/me works now, with test.

This commit is contained in:
Andrey Petrov 2014-12-26 12:26:53 -08:00
parent 999e1919e7
commit 325f8921da
3 changed files with 22 additions and 3 deletions

View File

@ -50,4 +50,12 @@ func TestChannelJoin(t *testing.T) {
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Got: `%s`; Expected: `%s`", actual, expected)
}
ch.Send(ParseInput("/me says hello.", u))
u.ConsumeOne(s)
expected = []byte("** foo says hello." + Newline)
s.Read(&actual)
if !reflect.DeepEqual(actual, expected) {
t.Errorf("Got: `%s`; Expected: `%s`", actual, expected)
}
}

View File

@ -40,6 +40,8 @@ func init() {
me := strings.TrimLeft(msg.body, "/me")
if me == "" {
me = " is at a loss for words."
} else {
me = me[1:]
}
channel.Send(NewEmoteMsg(me, msg.From()))

View File

@ -96,13 +96,22 @@ func (m *PublicMsg) String() string {
return m.Render(nil)
}
// EmoteMsg is a /me message sent to the channel.
// EmoteMsg is a /me message sent to the channel. It specifically does not
// extend PublicMsg because it doesn't implement MessageFrom to allow the
// sender to see the emote.
type EmoteMsg struct {
PublicMsg
Msg
from *User
}
func NewEmoteMsg(body string, from *User) *EmoteMsg {
return &EmoteMsg{*NewPublicMsg(body, from)}
return &EmoteMsg{
Msg: Msg{
body: body,
timestamp: time.Now(),
},
from: from,
}
}
func (m *EmoteMsg) Render(t *Theme) string {