From ed018207226912ee57ecaae06c539aea37e7bb96 Mon Sep 17 00:00:00 2001 From: Wim Date: Mon, 11 Sep 2017 22:45:15 +0200 Subject: Add support for deleting messages across bridges. Currently fully support mattermost,slack and discord. Message deleted on the bridge or received from other bridges will be deleted. Partially support for Gitter. Gitter bridge will delete messages received from other bridges. But if you delete a message on gitter, this deletion will not be sent to other bridges (this is a gitter API limitation, it doesn't propogate edits or deletes via the API) --- bridge/slack/slack.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'bridge/slack') diff --git a/bridge/slack/slack.go b/bridge/slack/slack.go index c7205464..fa847db9 100644 --- a/bridge/slack/slack.go +++ b/bridge/slack/slack.go @@ -166,6 +166,16 @@ func (b *Bslack) Send(msg config.Message) (string, error) { // replace mentions np.LinkNames = 1 + if msg.Event == config.EVENT_MSG_DELETE { + // some protocols echo deletes, but with empty ID + if msg.ID == "" { + return "", nil + } + // we get a "slack ", split it + ts := strings.Fields(msg.ID) + b.sc.DeleteMessage(schannel.ID, ts[1]) + return "", nil + } // if we have no ID it means we're creating a new message, not updating an existing one if msg.ID != "" { ts := strings.Fields(msg.ID) @@ -231,7 +241,7 @@ func (b *Bslack) handleSlack() { if b.Config.WebhookURL == "" && b.Config.WebhookBindAddress == "" && message.Username == b.si.User.Name { continue } - if message.Text == "" || message.Username == "" { + if (message.Text == "" || message.Username == "") && message.Raw.SubType != "message_deleted" { continue } text := message.Text @@ -250,6 +260,12 @@ func (b *Bslack) handleSlack() { if message.Raw.SubMessage != nil { msg.ID = "slack " + message.Raw.SubMessage.Timestamp } + if message.Raw.SubType == "message_deleted" { + msg.Text = config.EVENT_MSG_DELETE + msg.Event = config.EVENT_MSG_DELETE + msg.ID = "slack " + message.Raw.DeletedTimestamp + } + flog.Debugf("Message is %#v", msg) b.Remote <- msg } } @@ -276,7 +292,7 @@ func (b *Bslack) handleSlackClient(mchan chan *MMMessage) { continue } m := &MMMessage{} - if ev.BotID == "" { + if ev.BotID == "" && ev.SubType != "message_deleted" { user, err := b.rtm.GetUserInfo(ev.User) if err != nil { continue -- cgit v1.2.3