Skip to content

Ignored people still show up when they /msg and /me emote #349

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions chat/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ func (m PublicMsg) String() string {
return fmt.Sprintf("%s: %s", m.from.Name(), m.body)
}

// EmoteMsg is a /me message sent to the room. It specifically does not
// extend PublicMsg because it doesn't implement MessageFrom to allow the
// sender to see the emote.
// EmoteMsg is a /me message sent to the room.
type EmoteMsg struct {
Msg
from *User
Expand All @@ -156,6 +154,10 @@ func NewEmoteMsg(body string, from *User) *EmoteMsg {
}
}

func (m EmoteMsg) From() *User {
return m.from
}

func (m EmoteMsg) Render(t *Theme) string {
return fmt.Sprintf("** %s %s", m.from.Name(), m.body)
}
Expand All @@ -181,6 +183,10 @@ func (m PrivateMsg) To() *User {
return m.to
}

func (m PrivateMsg) From() *User {
return m.from
}

func (m PrivateMsg) Render(t *Theme) string {
s := fmt.Sprintf("[PM from %s] %s", m.from.Name(), m.body)
if t == nil {
Expand Down
8 changes: 8 additions & 0 deletions chat/room.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ func (r *Room) HandleMsg(m message.Message) {
}
case message.MessageTo:
user := m.To()
if _, ok := m.(*message.PrivateMsg); ok {
fromMsg, _ := m.(message.MessageFrom)
if fromMsg != nil && user.Ignored.In(fromMsg.From().ID()) {
// Skip because ignored
return
}
}

user.Send(m)
default:
fromMsg, _ := m.(message.MessageFrom)
Expand Down
7 changes: 7 additions & 0 deletions chat/room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ func TestIgnore(t *testing.T) {
t.Fatalf("should have %d ignored users, has %d", 1, len(ignoredList))
}

// when an emote is sent by an ignored user, it should not be displayed
ch.Send(message.NewEmoteMsg("crying", ignored.user))

if ignorer.user.HasMessages() {
t.Fatal("should not have emote messages")
}

// when a message is sent from the ignored user, it is delivered to non-ignoring users
ch.Send(message.NewPublicMsg("hello", ignored.user))
other.user.HandleMsg(other.user.ConsumeOne())
Expand Down