aboutsummaryrefslogtreecommitdiff
path: root/connector/mattermost
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-29 10:01:42 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-29 10:01:42 +0100
commit38a3f1bdb18159cc4808fa86280da55f0599dcc8 (patch)
tree9976cd829d5fc3953d382dcc955a7b270f2ab728 /connector/mattermost
parent1c038995be9f869be1b69a604e42096807806676 (diff)
downloadeasybridge-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/mattermost')
-rw-r--r--connector/mattermost/mattermost.go24
1 files changed, 12 insertions, 12 deletions
diff --git a/connector/mattermost/mattermost.go b/connector/mattermost/mattermost.go
index 12ac604..52eb40f 100644
--- a/connector/mattermost/mattermost.go
+++ b/connector/mattermost/mattermost.go
@@ -243,7 +243,7 @@ func (mm *Mattermost) Leave(roomId RoomID) {
// Not supported? TODO
}
-func (mm *Mattermost) Send(event *Event) error {
+func (mm *Mattermost) Send(event *Event) (string, error) {
post := &model.Post{
Message: event.Text,
}
@@ -254,29 +254,29 @@ func (mm *Mattermost) Send(event *Event) error {
if event.Room != "" {
ch, err := mm.checkRoomId(event.Room)
if err != nil {
- return err
+ return "", err
}
post.ChannelId = ch
} else if event.Recipient != "" {
ui, err := mm.checkUserId(event.Recipient)
if err != nil {
- return err
+ return "", err
}
_, resp := mm.conn.Client.CreateDirectChannel(mm.conn.User.Id, ui)
if resp.Error != nil {
- return resp.Error
+ return "", resp.Error
}
channelName := model.GetDMNameFromIds(ui, mm.conn.User.Id)
err = mm.conn.UpdateChannels()
if err != nil {
- return err
+ return "", err
}
post.ChannelId = mm.conn.GetChannelId(channelName, "")
} else {
- return fmt.Errorf("Invalid target")
+ return "", fmt.Errorf("Invalid target")
}
if event.Attachments != nil {
@@ -284,28 +284,28 @@ func (mm *Mattermost) Send(event *Event) error {
for _, file := range event.Attachments {
rdr, err := file.Read()
if err != nil {
- return err
+ return "", err
}
defer rdr.Close()
data, err := ioutil.ReadAll(rdr)
if err != nil {
- return err
+ return "", err
}
up_file, err := mm.conn.UploadFile(data, post.ChannelId, file.Filename())
if err != nil {
log.Warnf("UploadFile error: %s", err)
- return err
+ return "", err
}
post.FileIds = append(post.FileIds, up_file)
}
}
- _, resp := mm.conn.Client.CreatePost(post)
+ created_post, resp := mm.conn.Client.CreatePost(post)
if resp.Error != nil {
log.Warnf("CreatePost error: %s", resp.Error)
- return resp.Error
+ return "", resp.Error
}
- return nil
+ return created_post.Id, nil
}
func (mm *Mattermost) Close() {