Skip to content

Commit

Permalink
Ignored people still show up when they send private /msg
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdelkader Bouadjadja committed Apr 30, 2020
1 parent fde0436 commit 6fe0b40
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions chat/message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,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
1 change: 1 addition & 0 deletions chat/room_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func TestIgnore(t *testing.T) {

// 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")
}
Expand Down

0 comments on commit 6fe0b40

Please sign in to comment.