diff options
author | Qais Patankar <qaisjp@gmail.com> | 2019-07-09 05:18:37 +0900 |
---|---|---|
committer | Wim <wim@42.be> | 2019-07-08 22:18:37 +0200 |
commit | e60949ff3f84e899d25103f85ed948d26a1b44c3 (patch) | |
tree | f008599b74b2c8d6de54af66c02c2886904c4987 /gateway/router.go | |
parent | 278a3c68905605da73435f4173cca655b46721e4 (diff) | |
download | matterbridge-msglm-e60949ff3f84e899d25103f85ed948d26a1b44c3.tar.gz matterbridge-msglm-e60949ff3f84e899d25103f85ed948d26a1b44c3.tar.bz2 matterbridge-msglm-e60949ff3f84e899d25103f85ed948d26a1b44c3.zip |
Support webhook message deletions (discord) (#853)
* Support webhook message deletions (discord)
Messages sent via webhook can now be deleted. It seems it can do this
without any special permissions.
This copies discordgo.WebhookExecute and makes it support the returning
of discordgo.Message.
A pull request has been sent upstream, so we should use that if
@bwmariin accepts the pull request:
https://github.com/bwmarrin/discordgo/pull/663
Changes in behaviour (webhook mode only):
- Previously messages *edited* on other platforms would just be
retransmitted as a brand new message to Discord.
- Message *edits* will now be ignored.
- Debug: message edits will now print out a "permission error".
In the future it may be good to send an "message edited" react to those
webhook messages, so at least people know that the message was edited on
other platforms. (Even though it can't actually show the new message.)
Alternatively, message edits could just send a brand new message with a
link back to the old one. This is a little ugly but it would ensure that
Discord users are able to see the edited message. These "message edit
notifications" would be sent from the bot user (not from a webhook), so
we could edit the "edit notification" if subsequent edits to the
original message are made.
Diffstat (limited to 'gateway/router.go')
-rw-r--r-- | gateway/router.go | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/gateway/router.go b/gateway/router.go index 613a2c48..3d531676 100644 --- a/gateway/router.go +++ b/gateway/router.go @@ -125,7 +125,8 @@ func (r *Router) handleReceive() { r.handleEventGetChannelMembers(&msg) r.handleEventFailure(&msg) r.handleEventRejoinChannels(&msg) - idx := 0 + + filesHandled := false for _, gw := range r.Gateways { // record all the message ID's of the different bridges var msgIDs []*BrMsgID @@ -134,17 +135,26 @@ func (r *Router) handleReceive() { } msg.Timestamp = time.Now() gw.modifyMessage(&msg) - if idx == 0 { + if !filesHandled { gw.handleFiles(&msg) + filesHandled = true } for _, br := range gw.Bridges { msgIDs = append(msgIDs, gw.handleMessage(&msg, br)...) } - // only add the message ID if it doesn't already exists - if _, ok := gw.Messages.Get(msg.Protocol + " " + msg.ID); !ok && msg.ID != "" { - gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs) + + if msg.ID != "" { + _, exists := gw.Messages.Get(msg.Protocol + " " + msg.ID) + + // Only add the message ID if it doesn't already exist + // + // For some bridges we always add/update the message ID. + // This is necessary as msgIDs will change if a bridge returns + // a different ID in response to edits. + if !exists || msg.Protocol == "discord" { + gw.Messages.Add(msg.Protocol+" "+msg.ID, msgIDs) + } } - idx++ } } } |