From 6b528ffa4f1c8644f8d70a5d09d266a57303b4ca Mon Sep 17 00:00:00 2001 From: Neil Hanlon Date: Thu, 23 May 2024 17:58:58 -0400 Subject: [PATCH] Update post types and include system removals in skip logic (mattermost) (#2125) --- bridge/mattermost/helpers.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/bridge/mattermost/helpers.go b/bridge/mattermost/helpers.go index cca1c4e6..bc3eacb9 100644 --- a/bridge/mattermost/helpers.go +++ b/bridge/mattermost/helpers.go @@ -171,12 +171,24 @@ func (b *Bmattermost) sendWebhook(msg config.Message) (string, error) { } // skipMessages returns true if this message should not be handled +// //nolint:gocyclo,cyclop func (b *Bmattermost) skipMessage(message *matterclient.Message) bool { + // Handle join/leave - if message.Type == "system_join_leave" || - message.Type == "system_join_channel" || - message.Type == "system_leave_channel" { + skipJoinMessageTypes := map[string]struct{}{ + "system_join_leave": {}, //deprecated for system_add_to_channel + "system_leave_channel": {}, //deprecated for system_remove_from_channel + "system_join_channel": {}, + "system_add_to_channel": {}, + "system_remove_from_channel": {}, + "system_add_to_team": {}, + "system_remove_from_team": {}, + } + + // dirty hack to efficiently check if this element is in the map without writing a contains func + // can be replaced with native slice.contains with go 1.21 + if _, ok := skipJoinMessageTypes[message.Type]; ok { if b.GetBool("nosendjoinpart") { return true }