From 76c7b69e4e099dd80119f4ca1f2fac01aa2f31e6 Mon Sep 17 00:00:00 2001 From: Qais Patankar Date: Sun, 16 Jun 2019 00:15:18 +0100 Subject: Support bulk deletions (discord) --- bridge/discord/discord.go | 1 + bridge/discord/handlers.go | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) (limited to 'bridge/discord') diff --git a/bridge/discord/discord.go b/bridge/discord/discord.go index 49dfe4bc..ea43bd20 100644 --- a/bridge/discord/discord.go +++ b/bridge/discord/discord.go @@ -75,6 +75,7 @@ func (b *Bdiscord) Connect() error { b.c.AddHandler(b.memberUpdate) b.c.AddHandler(b.messageUpdate) b.c.AddHandler(b.messageDelete) + b.c.AddHandler(b.messageDeleteBulk) b.c.AddHandler(b.memberAdd) b.c.AddHandler(b.memberRemove) err = b.c.Open() diff --git a/bridge/discord/handlers.go b/bridge/discord/handlers.go index 85a36e1d..19e0ad6a 100644 --- a/bridge/discord/handlers.go +++ b/bridge/discord/handlers.go @@ -16,6 +16,27 @@ func (b *Bdiscord) messageDelete(s *discordgo.Session, m *discordgo.MessageDelet b.Remote <- rmsg } +// TODO(qaisjp): if other bridges support bulk deletions, it could be fanned out centrally +func (b *Bdiscord) messageDeleteBulk(s *discordgo.Session, m *discordgo.MessageDeleteBulk) { //nolint:unparam + for _, msgID := range m.Messages { + rmsg := config.Message{ + Account: b.Account, + ID: msgID, + Event: config.EventMsgDelete, + Text: config.EventMsgDelete, + Channel: "ID:" + m.ChannelID, + } + + if !b.useChannelID { + rmsg.Channel = b.getChannelName(m.ChannelID) + } + + b.Log.Debugf("<= Sending message from %s to gateway", b.Account) + b.Log.Debugf("<= Message is %#v", rmsg) + b.Remote <- rmsg + } +} + func (b *Bdiscord) messageUpdate(s *discordgo.Session, m *discordgo.MessageUpdate) { //nolint:unparam if b.GetBool("EditDisable") { return -- cgit v1.2.3