diff options
author | Wim <wim@42.be> | 2020-04-21 23:35:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-21 23:35:46 +0200 |
commit | eaf92fca4ddf6bf78d2092618a4dc93b78af7140 (patch) | |
tree | 7c3c2f90b027117492aef33bcabeb744d51aef99 /bridge/discord/discord.go | |
parent | 06b7bad7146607f46652c9bd766de3f95028c370 (diff) | |
download | matterbridge-msglm-eaf92fca4ddf6bf78d2092618a4dc93b78af7140.tar.gz matterbridge-msglm-eaf92fca4ddf6bf78d2092618a4dc93b78af7140.tar.bz2 matterbridge-msglm-eaf92fca4ddf6bf78d2092618a4dc93b78af7140.zip |
Add an ID cache (discord). Fixes #1106 (#1111)
When a webhook "edits" a message, it does this by deleting the message
and creating a new one with the new content.
On creation of this new message, we'll get another ID then already is
know by the gateway in its id cache. So we add it in our own cache and
replace it whenever we want to edit/delete it again.
Diffstat (limited to 'bridge/discord/discord.go')
-rw-r--r-- | bridge/discord/discord.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index a59735ad..614512f3 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -34,6 +34,8 @@ type Bdiscord struct { membersMutex sync.RWMutex userMemberMap map[string]*discordgo.Member nickMemberMap map[string]*discordgo.Member + webhookCache map[string]string + webhookMutex sync.RWMutex } func New(cfg *bridge.Config) bridge.Bridger { @@ -41,6 +43,7 @@ func New(cfg *bridge.Config) bridge.Bridger { b.userMemberMap = make(map[string]*discordgo.Member) b.nickMemberMap = make(map[string]*discordgo.Member) b.channelInfoMap = make(map[string]*config.ChannelInfo) + b.webhookCache = make(map[string]string) if b.GetString("WebhookURL") != "" { b.Log.Debug("Configuring Discord Incoming Webhook") b.webhookID, b.webhookToken = b.splitURL(b.GetString("WebhookURL")) @@ -188,6 +191,8 @@ func (b *Bdiscord) JoinChannel(channel config.ChannelInfo) error { func (b *Bdiscord) Send(msg config.Message) (string, error) { b.Log.Debugf("=> Receiving %#v", msg) + origMsgID := msg.ID + channelID := b.getChannelID(msg.Channel) if channelID == "" { return "", fmt.Errorf("Could not find channelID for %v", msg.Channel) @@ -230,6 +235,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { // If we are editing a message, delete the old message if msg.ID != "" { + msg.ID = b.getCacheID(msg.ID) b.Log.Debugf("Deleting edited webhook message") err := b.c.ChannelMessageDelete(channelID, msg.ID) if err != nil { @@ -273,6 +279,8 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { if msg == nil { return "", nil } + + b.updateCacheID(origMsgID, msg.ID) return msg.ID, nil } @@ -283,6 +291,7 @@ func (b *Bdiscord) Send(msg config.Message) (string, error) { if msg.ID == "" { return "", nil } + msg.ID = b.getCacheID(msg.ID) err := b.c.ChannelMessageDelete(channelID, msg.ID) return "", err } |