summaryrefslogtreecommitdiffstats
path: root/bridge/discord/helpers.go
diff options
context:
space:
mode:
authorSimon THOBY <simonthoby@live.fr>2020-11-14 05:08:09 +0100
committerGitHub <noreply@github.com>2020-11-14 04:08:09 +0000
commitcbb46293ab670c1989bfcd9aae5d853223074038 (patch)
tree3376530d6ac2816c49140d7bef365ad05dff846d /bridge/discord/helpers.go
parent765e00c949344b958d4681c91db8502d150f0353 (diff)
downloadmatterbridge-msglm-cbb46293ab670c1989bfcd9aae5d853223074038.tar.gz
matterbridge-msglm-cbb46293ab670c1989bfcd9aae5d853223074038.tar.bz2
matterbridge-msglm-cbb46293ab670c1989bfcd9aae5d853223074038.zip
Update webhook messages via new endpoint (discord)
When using the webhook, the previous method to edit a message was to delete the old one via the classical API, and to create a new message via the webhook. While this works, this means that editing "old" messages lead to a mess where the chronological order is no longer respected. This uses an hidden API explained in https://support.discord.com/hc/en-us/community/posts/360034557771 to achieve a proper edition using the webhook API. The obvious downside of this approach is that since it is an undocumented API for now, so there is no stability guarantee :/
Diffstat (limited to 'bridge/discord/helpers.go')
-rw-r--r--bridge/discord/helpers.go34
1 files changed, 0 insertions, 34 deletions
diff --git a/bridge/discord/helpers.go b/bridge/discord/helpers.go
index e183165c..73536cf4 100644
--- a/bridge/discord/helpers.go
+++ b/bridge/discord/helpers.go
@@ -209,40 +209,6 @@ func (b *Bdiscord) splitURL(url string) (string, string) {
return webhookURLSplit[webhookIdxID], webhookURLSplit[webhookIdxToken]
}
-// getcacheID tries to find a corresponding msgID in the webhook cache.
-// if not found returns the original request.
-func (b *Bdiscord) getCacheID(msgID string) string {
- b.webhookMutex.RLock()
- defer b.webhookMutex.RUnlock()
- for k, v := range b.webhookCache {
- if msgID == k {
- return v
- }
- }
- return msgID
-}
-
-// updateCacheID updates the cache so that the newID takes the place of
-// the original ID. This is used for edit/deletes in combination with webhooks
-// as editing a message via webhook means deleting the message and creating a
-// new message (with a new ID). This ID needs to be set instead of the original ID
-func (b *Bdiscord) updateCacheID(origID, newID string) {
- b.webhookMutex.Lock()
- match := false
- for k, v := range b.webhookCache {
- if v == origID {
- delete(b.webhookCache, k)
- b.webhookCache[origID] = newID
- match = true
- continue
- }
- }
- if !match && origID != "" {
- b.webhookCache[origID] = newID
- }
- b.webhookMutex.Unlock()
-}
-
func enumerateUsernames(s string) []string {
onlySpace := true
for _, r := range s {