summaryrefslogtreecommitdiffstats
path: root/matterclient/matterclient.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-10-27 22:02:25 +0200
committerWim <wim@42.be>2018-10-27 22:02:25 +0200
commite2b50d6194ab825de8c6443d46b642ecd3a0313c (patch)
treeb8307a3e96f8ebcf380ae470776aada24156f131 /matterclient/matterclient.go
parent74e33b0a51f6d8b5cebd355ac3dd0e825e2c83a7 (diff)
downloadmatterbridge-msglm-e2b50d6194ab825de8c6443d46b642ecd3a0313c.tar.gz
matterbridge-msglm-e2b50d6194ab825de8c6443d46b642ecd3a0313c.tar.bz2
matterbridge-msglm-e2b50d6194ab825de8c6443d46b642ecd3a0313c.zip
Add better support for multiperson DM (mattermost)
Diffstat (limited to 'matterclient/matterclient.go')
-rw-r--r--matterclient/matterclient.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/matterclient/matterclient.go b/matterclient/matterclient.go
index 86eb1bea..8b3c07d1 100644
--- a/matterclient/matterclient.go
+++ b/matterclient/matterclient.go
@@ -434,8 +434,9 @@ 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
}
@@ -445,8 +446,9 @@ 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
}
@@ -460,8 +462,20 @@ 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...) {
@@ -689,7 +703,7 @@ 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)
}
@@ -743,9 +757,13 @@ 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 ""
}