Thumbnail

rani/matterbridge.git

Clone URL: https://git.buni.party/rani/matterbridge.git

commit eb3946ff29145aa325ae0b0f0cec8bb86ebdce6f Author: Wim <wim@42.be> Date: Sat Oct 27 22:02:25 2018 +0000 Add better support for multiperson DM (mattermost) diff --git a/bridge/mattermost/mattermost.go b/bridge/mattermost/mattermost.go index 2fed284..c9a7c66 100644 --- a/bridge/mattermost/mattermost.go +++ b/bridge/mattermost/mattermost.go @@ -1097 +1097 @@ func (b *Bmattermost) Disconnect() error {  func (b *Bmattermost) JoinChannel(channel config.ChannelInfo) error {   // we can only join channels using the API   if b.GetString("WebhookURL") == "" && b.GetString("WebhookBindAddress") == "" { - id := b.mc.GetChannelId(channel.Name, "") + id := b.mc.GetChannelId(channel.Name, b.TeamID)   if id == "" {   return fmt.Errorf("Could not find channel ID for channel %s", channel.Name)   } @@ -1477 +1477 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {   // Upload a file if it exists   if msg.Extra != nil {   for _, rmsg := range helper.HandleExtra(&msg, b.General) { - b.mc.PostMessage(b.mc.GetChannelId(rmsg.Channel, ""), rmsg.Username+rmsg.Text) + b.mc.PostMessage(b.mc.GetChannelId(rmsg.Channel, b.TeamID), rmsg.Username+rmsg.Text)   }   if len(msg.Extra["file"]) > 0 {   return b.handleUploadFile(&msg) @@ -1657 +1657 @@ func (b *Bmattermost) Send(msg config.Message) (string, error) {   }     // Post normal message - return b.mc.PostMessage(b.mc.GetChannelId(msg.Channel, ""), msg.Text) + return b.mc.PostMessage(b.mc.GetChannelId(msg.Channel, b.TeamID), msg.Text)  }    func (b *Bmattermost) handleMatter() { @@ -3577 +3577 @@ func (b *Bmattermost) handleDownloadFile(rmsg *config.Message, id string) error  func (b *Bmattermost) handleUploadFile(msg *config.Message) (string, error) {   var err error   var res, id string - channelID := b.mc.GetChannelId(msg.Channel, "") + channelID := b.mc.GetChannelId(msg.Channel, b.TeamID)   for _, f := range msg.Extra["file"] {   fi := f.(config.FileInfo)   id, err = b.mc.UploadFile(*fi.Data, channelID, fi.Name) diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go index 86eb1be..8b3c07d 100644 --- a/matterclient/matterclient.go +++ b/matterclient/matterclient.go @@ -4348 +4349 @@ func (m *MMClient) GetChannelName(channelId string) string {   for _, channel := range t.Channels {   if channel.Id == channelId {   if channel.Type == model.CHANNEL_GROUP { - res := strings.Replace(channel.DisplayName, ",", "_", -1) - return strings.Replace(res, " ", "", -1) + res := strings.Replace(channel.DisplayName, ", ", "-", -1) + res = strings.Replace(res, " ", "_", -1) + return res   }   return channel.Name   } @@ -4458 +4469 @@ func (m *MMClient) GetChannelName(channelId string) string {   for _, channel := range t.MoreChannels {   if channel.Id == channelId {   if channel.Type == model.CHANNEL_GROUP { - res := strings.Replace(channel.DisplayName, ",", "_", -1) - return strings.Replace(res, " ", "", -1) + res := strings.Replace(channel.DisplayName, ", ", "-", -1) + res = strings.Replace(res, " ", "_", -1) + return res   }   return channel.Name   } @@ -4608 +46220 @@ func (m *MMClient) GetChannelId(name string, teamId string) string {   m.RLock()   defer m.RUnlock()   if teamId == "" { - teamId = m.Team.Id + for _, t := range m.OtherTeams { + for _, channel := range append(t.Channels, t.MoreChannels...) { + if channel.Type == model.CHANNEL_GROUP { + res := strings.Replace(channel.DisplayName, ", ", "-", -1) + res = strings.Replace(res, " ", "_", -1) + if res == name { + return channel.Id + } + } + + } + }   } +   for _, t := range m.OtherTeams {   if t.Id == teamId {   for _, channel := range append(t.Channels, t.MoreChannels...) { @@ -6897 +7037 @@ func (m *MMClient) SendDirectMessage(toUserId string, msg string) {     // build & send the message   msg = strings.Replace(msg, "\r", "", -1) - post := &model.Post{ChannelId: m.GetChannelId(channelName, ""), Message: msg} + post := &model.Post{ChannelId: m.GetChannelId(channelName, m.Team.Id), Message: msg}   m.Client.CreatePost(post)  }   @@ -7439 +75713 @@ func (m *MMClient) GetTeamFromChannel(channelId string) string {   }   for _, c := range channels {   if c.Id == channelId { + if c.Type == model.CHANNEL_GROUP { + return "G" + }   return t.Id   }   } + channels = nil   }   return ""  }