@@ -34,8 +34,8 @@ type Bxmpp struct {
3434 xc * xmpp.Client
3535 xmppMap map [string ]string
3636 connected bool
37- stanzaIDs * lru.Cache [string , string ]
38- replyHeaders * lru.Cache [string , xmpp.Reply ]
37+ stanzaIDs * lru.Cache [string , string ] // stanzaID -> ID
38+ replyHeaders * lru.Cache [string , xmpp.Reply ] // ID -> Reply{stanzaID, to}
3939 sync.RWMutex
4040
4141 avatarAvailability map [string ]bool
@@ -158,9 +158,27 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
158158
159159 // XEP-0461: populate reply fields if this message is a reply.
160160 var reply * xmpp.Reply
161+ var reactions * xmpp.Reactions
161162 if msg .ParentValid () {
162- if _reply , ok := b .replyHeaders .Get (msg .ParentID ); ok {
163- reply = & _reply
163+ // either a Reaction or a Reply
164+ //
165+ if msg .Event == config .EventReaction {
166+ b .Log .Debugf ("relaying a Reaction; the reactions are %#v" , msg .Reactions )
167+ if _reply , ok := b .replyHeaders .Get (msg .ParentID ); ok {
168+ reactions = & xmpp.Reactions {
169+ ID : _reply .ID ,
170+ Reactions : msg .Reactions ,
171+ }
172+ }
173+
174+ // XXX TODO: XEP-0444 says an update requires a *full* update for all reactions from a given user.
175+ // since the bridge is the source of ALL reactions for all users on the other side,
176+ // it needs to track what has been sent and *resend all of them*
177+ // also it's going to lose past reactions messages...
178+ } else {
179+ if _reply , ok := b .replyHeaders .Get (msg .ParentID ); ok {
180+ reply = & _reply
181+ }
164182 }
165183 }
166184
@@ -169,11 +187,12 @@ func (b *Bxmpp) Send(msg config.Message) (string, error) {
169187 // Generate a dummy ID because to avoid collision with other internal messages
170188 msgID := xid .New ().String ()
171189 if _ , err := b .xc .Send (xmpp.Chat {
172- Type : "groupchat" ,
173- Remote : msg .Channel + "@" + b .GetString ("Muc" ),
174- Text : msg .Username + msg .Text ,
175- OriginID : msgID ,
176- Reply : reply ,
190+ Type : "groupchat" ,
191+ Remote : msg .Channel + "@" + b .GetString ("Muc" ),
192+ Text : msg .Username + msg .Text ,
193+ OriginID : msgID ,
194+ Reply : reply ,
195+ Reactions : reactions ,
177196 }); err != nil {
178197 return "" , err
179198 }
@@ -362,6 +381,17 @@ func (b *Bxmpp) handleXMPP() error {
362381 parentText = v .Reply .Quote
363382 }
364383
384+ // If there was a <reactions> // ....
385+ var reactions []string
386+ if v .Reactions != nil {
387+ if _parentID , ok := b .stanzaIDs .Get (v .Reactions .ID ); ok {
388+ parentID = _parentID
389+ b .Log .Debugf ("Got reactions: %#v" , v .Reactions )
390+ reactions = append (reactions , v .Reactions .Reactions ... ) // XXX is the append() necessary?
391+ event = config .EventReaction
392+ }
393+ }
394+
365395 rmsg := config.Message {
366396 Username : b .parseNick (v .Remote ),
367397 Text : v .Text ,
@@ -373,6 +403,7 @@ func (b *Bxmpp) handleXMPP() error {
373403 Event : event ,
374404 ParentID : parentID ,
375405 ParentText : parentText ,
406+ Reactions : reactions ,
376407 }
377408
378409 // Check if we have an action event.
@@ -499,7 +530,7 @@ func (b *Bxmpp) skipMessage(message xmpp.Chat) bool {
499530 }
500531
501532 // skip empty messages
502- if message .Text == "" {
533+ if message .Text == "" && message . Reactions == nil {
503534 return true
504535 }
505536
0 commit comments