diff options
author | Wim <wim@42.be> | 2023-01-28 21:57:06 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 21:57:06 +0100 |
commit | eac2a8c8dc831f946970d327e2a80b26b0684255 (patch) | |
tree | 139baee0147d387da8f359e12ac4fc959008761c /bridge/mattermost/helpers.go | |
parent | 4cf313c4c6b25d19c4128f8e79d22d9a2a001cf0 (diff) | |
download | matterbridge-msglm-eac2a8c8dc831f946970d327e2a80b26b0684255.tar.gz matterbridge-msglm-eac2a8c8dc831f946970d327e2a80b26b0684255.tar.bz2 matterbridge-msglm-eac2a8c8dc831f946970d327e2a80b26b0684255.zip |
Remove mattermost 5 support (#1936)
Diffstat (limited to 'bridge/mattermost/helpers.go')
-rw-r--r-- | bridge/mattermost/helpers.go | 183 |
1 files changed, 24 insertions, 159 deletions
diff --git a/bridge/mattermost/helpers.go b/bridge/mattermost/helpers.go index c69d94fb..3e1262c7 100644 --- a/bridge/mattermost/helpers.go +++ b/bridge/mattermost/helpers.go @@ -6,11 +6,9 @@ import ( "github.com/42wim/matterbridge/bridge/config" "github.com/42wim/matterbridge/bridge/helper" - "github.com/42wim/matterbridge/matterclient" "github.com/42wim/matterbridge/matterhook" - matterclient6 "github.com/matterbridge/matterclient" - "github.com/mattermost/mattermost-server/v5/model" - model6 "github.com/mattermost/mattermost-server/v6/model" + "github.com/matterbridge/matterclient" + "github.com/mattermost/mattermost-server/v6/model" ) func (b *Bmattermost) doConnectWebhookBind() error { @@ -24,33 +22,15 @@ func (b *Bmattermost) doConnectWebhookBind() error { }) case b.GetString("Token") != "": b.Log.Info("Connecting using token (sending)") - b.Log.Infof("Using mattermost v6 methods: %t", b.v6) - - if b.v6 { - err := b.apiLogin6() - if err != nil { - return err - } - } else { - err := b.apiLogin() - if err != nil { - return err - } + err := b.apiLogin() + if err != nil { + return err } case b.GetString("Login") != "": b.Log.Info("Connecting using login/password (sending)") - b.Log.Infof("Using mattermost v6 methods: %t", b.v6) - - if b.v6 { - err := b.apiLogin6() - if err != nil { - return err - } - } else { - err := b.apiLogin() - if err != nil { - return err - } + err := b.apiLogin() + if err != nil { + return err } default: b.Log.Info("Connecting using webhookbindaddress (receiving)") @@ -72,45 +52,28 @@ func (b *Bmattermost) doConnectWebhookURL() error { }) if b.GetString("Token") != "" { b.Log.Info("Connecting using token (receiving)") - b.Log.Infof("Using mattermost v6 methods: %t", b.v6) - - if b.v6 { - err := b.apiLogin6() - if err != nil { - return err - } - } else { - err := b.apiLogin() - if err != nil { - return err - } + err := b.apiLogin() + if err != nil { + return err } } else if b.GetString("Login") != "" { b.Log.Info("Connecting using login/password (receiving)") - b.Log.Infof("Using mattermost v6 methods: %t", b.v6) - - if b.v6 { - err := b.apiLogin6() - if err != nil { - return err - } - } else { - err := b.apiLogin() - if err != nil { - return err - } + err := b.apiLogin() + if err != nil { + return err } } return nil } +// nolint:wrapcheck func (b *Bmattermost) apiLogin() error { password := b.GetString("Password") if b.GetString("Token") != "" { password = "token=" + b.GetString("Token") } - b.mc = matterclient.New(b.GetString("Login"), password, b.GetString("Team"), b.GetString("Server")) + b.mc = matterclient.New(b.GetString("Login"), password, b.GetString("Team"), b.GetString("Server"), "") if b.GetBool("debug") { b.mc.SetLogLevel("debug") } @@ -118,39 +81,13 @@ func (b *Bmattermost) apiLogin() error { b.mc.SkipVersionCheck = b.GetBool("SkipVersionCheck") b.mc.NoTLS = b.GetBool("NoTLS") b.Log.Infof("Connecting %s (team: %s) on %s", b.GetString("Login"), b.GetString("Team"), b.GetString("Server")) - err := b.mc.Login() - if err != nil { - return err - } - b.Log.Info("Connection succeeded") - b.TeamID = b.mc.GetTeamId() - go b.mc.WsReceiver() - go b.mc.StatusLoop() - return nil -} - -// nolint:wrapcheck -func (b *Bmattermost) apiLogin6() error { - password := b.GetString("Password") - if b.GetString("Token") != "" { - password = "token=" + b.GetString("Token") - } - - b.mc6 = matterclient6.New(b.GetString("Login"), password, b.GetString("Team"), b.GetString("Server"), "") - if b.GetBool("debug") { - b.mc6.SetLogLevel("debug") - } - b.mc6.SkipTLSVerify = b.GetBool("SkipTLSVerify") - b.mc6.SkipVersionCheck = b.GetBool("SkipVersionCheck") - b.mc6.NoTLS = b.GetBool("NoTLS") - b.Log.Infof("Connecting %s (team: %s) on %s", b.GetString("Login"), b.GetString("Team"), b.GetString("Server")) - if err := b.mc6.Login(); err != nil { + if err := b.mc.Login(); err != nil { return err } b.Log.Info("Connection succeeded") - b.TeamID = b.mc6.GetTeamID() + b.TeamID = b.mc.GetTeamID() return nil } @@ -234,76 +171,8 @@ func (b *Bmattermost) sendWebhook(msg config.Message) (string, error) { } // skipMessages returns true if this message should not be handled -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" { - if b.GetBool("nosendjoinpart") { - return true - } - - channelName := b.getChannelName(message.Post.ChannelId) - if channelName == "" { - channelName = message.Channel - } - - b.Log.Debugf("Sending JOIN_LEAVE event from %s to gateway", b.Account) - b.Remote <- config.Message{ - Username: "system", - Text: message.Text, - Channel: channelName, - Account: b.Account, - Event: config.EventJoinLeave, - } - return true - } - - // Handle edited messages - if (message.Raw.Event == model.WEBSOCKET_EVENT_POST_EDITED) && b.GetBool("EditDisable") { - return true - } - - // Ignore non-post messages - if message.Post == nil { - b.Log.Debugf("ignoring nil message.Post: %#v", message) - return true - } - - // Ignore messages sent from matterbridge - if message.Post.Props != nil { - if _, ok := message.Post.Props["matterbridge_"+b.uuid].(bool); ok { - b.Log.Debugf("sent by matterbridge, ignoring") - return true - } - } - - // Ignore messages sent from a user logged in as the bot - if b.mc.User.Username == message.Username { - return true - } - - // if the message has reactions don't repost it (for now, until we can correlate reaction with message) - if message.Post.HasReactions { - return true - } - - // ignore messages from other teams than ours - if message.Raw.Data["team_id"].(string) != b.TeamID { - return true - } - - // only handle posted, edited or deleted events - if !(message.Raw.Event == "posted" || message.Raw.Event == model.WEBSOCKET_EVENT_POST_EDITED || - message.Raw.Event == model.WEBSOCKET_EVENT_POST_DELETED) { - return true - } - return false -} - -// skipMessages returns true if this message should not be handled // nolint:gocyclo,cyclop -func (b *Bmattermost) skipMessage6(message *matterclient6.Message) bool { +func (b *Bmattermost) skipMessage(message *matterclient.Message) bool { // Handle join/leave if message.Type == "system_join_leave" || message.Type == "system_join_channel" || @@ -329,7 +198,7 @@ func (b *Bmattermost) skipMessage6(message *matterclient6.Message) bool { } // Handle edited messages - if (message.Raw.EventType() == model6.WebsocketEventPostEdited) && b.GetBool("EditDisable") { + if (message.Raw.EventType() == model.WebsocketEventPostEdited) && b.GetBool("EditDisable") { return true } @@ -348,7 +217,7 @@ func (b *Bmattermost) skipMessage6(message *matterclient6.Message) bool { } // Ignore messages sent from a user logged in as the bot - if b.mc6.User.Username == message.Username { + if b.mc.User.Username == message.Username { b.Log.Debug("message from same user as bot, ignoring") return true } @@ -365,8 +234,8 @@ func (b *Bmattermost) skipMessage6(message *matterclient6.Message) bool { } // only handle posted, edited or deleted events - if !(message.Raw.EventType() == "posted" || message.Raw.EventType() == model6.WebsocketEventPostEdited || - message.Raw.EventType() == model6.WebsocketEventPostDeleted) { + if !(message.Raw.EventType() == "posted" || message.Raw.EventType() == model.WebsocketEventPostEdited || + message.Raw.EventType() == model.WebsocketEventPostDeleted) { return true } return false @@ -396,11 +265,7 @@ func (b *Bmattermost) getChannelID(name string) string { return idcheck[1] } - if b.mc6 != nil { - return b.mc6.GetChannelID(name, b.TeamID) - } - - return b.mc.GetChannelId(name, b.TeamID) + return b.mc.GetChannelID(name, b.TeamID) } func (b *Bmattermost) getChannelName(id string) string { |