diff --git a/chat/message/message.go b/chat/message/message.go index 143096a..c07c8b2 100644 --- a/chat/message/message.go +++ b/chat/message/message.go @@ -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 @@ -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) } diff --git a/chat/room_test.go b/chat/room_test.go index 04785bd..171c1dd 100644 --- a/chat/room_test.go +++ b/chat/room_test.go @@ -105,6 +105,12 @@ func TestIgnore(t *testing.T) { t.Fatalf("should have %d ignored users, has %d", 1, len(ignoredList)) } + // ignoring the same user twice returns an error message and doesn't add the user twice + 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())