diff options
author | Wim <wim@42.be> | 2017-04-15 20:21:57 +0200 |
---|---|---|
committer | Wim <wim@42.be> | 2017-04-15 20:21:57 +0200 |
commit | fdb57230a363d1326f597253bb230f0e7e325aee (patch) | |
tree | 58af49c8d900f1b43a61528d6360188ef296007b | |
parent | 7469732bbc84dbb60b6eafc29fb8d0771a48ba27 (diff) | |
download | matterbridge-msglm-fdb57230a363d1326f597253bb230f0e7e325aee.tar.gz matterbridge-msglm-fdb57230a363d1326f597253bb230f0e7e325aee.tar.bz2 matterbridge-msglm-fdb57230a363d1326f597253bb230f0e7e325aee.zip |
Add support for edited messages (mattermost)
-rw-r--r-- | bridge/mattermost/mattermost.go | 6 | ||||
-rw-r--r-- | matterbridge.toml.sample | 8 | ||||
-rw-r--r-- | matterclient/matterclient.go | 14 |
3 files changed, 25 insertions, 3 deletions
diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index b9d082e3..31c8b603 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -143,12 +143,16 @@ func (b *Bmattermost) handleMatterClient(mchan chan *MMMessage) { } // do not post our own messages back to irc // only listen to message from our team - if message.Raw.Event == "posted" && b.mc.User.Username != message.Username && message.Raw.Data["team_id"].(string) == b.TeamId { + if (message.Raw.Event == "posted" || message.Raw.Event == "post_edited") && + b.mc.User.Username != message.Username && message.Raw.Data["team_id"].(string) == b.TeamId { flog.Debugf("Receiving from matterclient %#v", message) m := &MMMessage{} m.Username = message.Username m.Channel = message.Channel m.Text = message.Text + if message.Raw.Event == "post_edited" && !b.Config.EditDisable { + m.Text = message.Text + b.Config.EditSuffix + } if len(message.Post.FileIds) > 0 { for _, link := range b.mc.GetPublicLinks(message.Post.FileIds) { m.Text = m.Text + "\n" + link diff --git a/matterbridge.toml.sample b/matterbridge.toml.sample index 69c18164..33a01fc5 100644 --- a/matterbridge.toml.sample +++ b/matterbridge.toml.sample @@ -241,6 +241,14 @@ NicksPerRow=4 #OPTIONAL (default false) PrefixMessagesWithNick=false +#Disable sending of edits to other bridges +#OPTIONAL (default false) +EditDisable=false + +#Message to be appended to every edited message +#OPTIONAL (default empty) +EditSuffix=" (edited)" + #Nicks you want to ignore. #Messages from those users will not be sent to other bridges. #OPTIONAL diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index a066d654..d234fb34 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -251,7 +251,7 @@ func (m *MMClient) WsReceiver() { func (m *MMClient) parseMessage(rmsg *Message) { switch rmsg.Raw.Event { - case model.WEBSOCKET_EVENT_POSTED: + case model.WEBSOCKET_EVENT_POSTED, model.WEBSOCKET_EVENT_POST_EDITED: m.parseActionPost(rmsg) /* case model.ACTION_USER_REMOVED: @@ -280,7 +280,17 @@ func (m *MMClient) parseActionPost(rmsg *Message) { rmsg.Username = m.GetUser(data.UserId).Username rmsg.Channel = m.GetChannelName(data.ChannelId) rmsg.Type = data.Type - rmsg.Team = m.GetTeamName(rmsg.Raw.Data["team_id"].(string)) + teamid, _ := rmsg.Raw.Data["team_id"].(string) + // edit messsages have no team_id for some reason + if teamid == "" { + // we can find the team_id from the channelid + result, _ := m.Client.GetChannel(data.ChannelId, "") + teamid = result.Data.(*model.ChannelData).Channel.TeamId + rmsg.Raw.Data["team_id"] = teamid + } + if teamid != "" { + rmsg.Team = m.GetTeamName(teamid) + } // direct message if rmsg.Raw.Data["channel_type"] == "D" { rmsg.Channel = m.GetUser(data.UserId).Username |