diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-29 10:01:42 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-29 10:01:42 +0100 |
commit | 38a3f1bdb18159cc4808fa86280da55f0599dcc8 (patch) | |
tree | 9976cd829d5fc3953d382dcc955a7b270f2ab728 /connector/xmpp | |
parent | 1c038995be9f869be1b69a604e42096807806676 (diff) | |
download | easybridge-38a3f1bdb18159cc4808fa86280da55f0599dcc8.tar.gz easybridge-38a3f1bdb18159cc4808fa86280da55f0599dcc8.zip |
Fix Mattermost event deduplication
Mattermost assigns its own IDs to messages, thus when sending a message
to Mattermost the event_seen key that has to be written must take into
account that ID and not the one that we put in the event (which was the
Matrix event ID)
Note that for XMPP anything can be used as an ID, so using the Matrix
event ID there worked, but it's actually not so good.
Diffstat (limited to 'connector/xmpp')
-rw-r--r-- | connector/xmpp/xmpp.go | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/connector/xmpp/xmpp.go b/connector/xmpp/xmpp.go index dcf1db6..efaaf64 100644 --- a/connector/xmpp/xmpp.go +++ b/connector/xmpp/xmpp.go @@ -306,13 +306,13 @@ func (xm *XMPP) Leave(roomId RoomID) { xm.conn.LeaveMUC(string(roomId)) } -func (xm *XMPP) Send(event *Event) error { +func (xm *XMPP) Send(event *Event) (string, error) { if event.Attachments != nil && len(event.Attachments) > 0 { for _, at := range event.Attachments { url := at.URL() if url == "" { // TODO find a way to send them using some hosing of some kind - return fmt.Errorf("Attachment without URL sent to XMPP") + return "", fmt.Errorf("Attachment without URL sent to XMPP") } else { event.Text += fmt.Sprintf("\n%s (%s, %dkb)", url, at.Mimetype(), at.Size()/1024) @@ -320,6 +320,10 @@ func (xm *XMPP) Send(event *Event) error { } } + if event.Id == "" { + event.Id = xid.New().String() + } + log.Tracef("xm *XMPP Send %#v\n", event) if len(event.Recipient) > 0 { _, err := xm.conn.Send(gxmpp.Chat{ @@ -327,20 +331,17 @@ func (xm *XMPP) Send(event *Event) error { Remote: string(event.Recipient), Text: event.Text, }) - return err + return event.Id, err } else if len(event.Room) > 0 { - if event.Id == "" { - event.Id = xid.New().String() - } _, err := xm.conn.Send(gxmpp.Chat{ Type: "groupchat", Remote: string(event.Room), Text: event.Text, ID: event.Id, }) - return err + return event.Id, err } else { - return fmt.Errorf("Invalid event") + return "", fmt.Errorf("Invalid event") } } |