summaryrefslogtreecommitdiffstats
path: root/matterclient/channels.go
diff options
context:
space:
mode:
authorDavid Buckley <bucko909@users.noreply.github.com>2019-09-07 20:38:45 +0100
committerWim <wim@42.be>2019-09-07 21:39:44 +0200
commit1dc93ec4f001edd01daccbe408767d4878be25a3 (patch)
tree90c23f4b67b9ae2d8bc85c87258ade9667a2768a /matterclient/channels.go
parent3562d4220c7b2579990356085b0bec24c34392b2 (diff)
downloadmatterbridge-msglm-1dc93ec4f001edd01daccbe408767d4878be25a3.tar.gz
matterbridge-msglm-1dc93ec4f001edd01daccbe408767d4878be25a3.tar.bz2
matterbridge-msglm-1dc93ec4f001edd01daccbe408767d4878be25a3.zip
Make getChannelIdTeam behave like GetChannelId for groups (mattermost) (#873)
GetChannelId will support names generated from query groups when a team is not set, but not when a team is set since it falls through to getChannelIdTeam which has a different inner loop. i This pull makes the two implementations do the same thing.
Diffstat (limited to 'matterclient/channels.go')
-rw-r--r--matterclient/channels.go27
1 files changed, 13 insertions, 14 deletions
diff --git a/matterclient/channels.go b/matterclient/channels.go
index ae1bf384..e1ebf48d 100644
--- a/matterclient/channels.go
+++ b/matterclient/channels.go
@@ -36,6 +36,16 @@ func (m *MMClient) GetChannelHeader(channelId string) string { //nolint:golint
return ""
}
+func getNormalisedName(channel *model.Channel) string {
+ if channel.Type == model.CHANNEL_GROUP {
+ // (deprecated in favor of ReplaceAll in go 1.12)
+ res := strings.Replace(channel.DisplayName, ", ", "-", -1) //nolint: gocritic
+ res = strings.Replace(res, " ", "_", -1) //nolint: gocritic
+ return res
+ }
+ return channel.Name
+}
+
func (m *MMClient) GetChannelId(name string, teamId string) string { //nolint:golint
m.RLock()
defer m.RUnlock()
@@ -45,13 +55,7 @@ func (m *MMClient) GetChannelId(name string, teamId string) string { //nolint:go
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
- }
- } else if channel.Name == name {
+ if getNormalisedName(channel) == name {
return channel.Id
}
}
@@ -63,7 +67,7 @@ func (m *MMClient) getChannelIdTeam(name string, teamId string) string { //nolin
for _, t := range m.OtherTeams {
if t.Id == teamId {
for _, channel := range append(t.Channels, t.MoreChannels...) {
- if channel.Name == name {
+ if getNormalisedName(channel) == name {
return channel.Id
}
}
@@ -81,12 +85,7 @@ func (m *MMClient) GetChannelName(channelId string) string { //nolint:golint
}
for _, channel := range append(t.Channels, t.MoreChannels...) {
if channel.Id == channelId {
- if channel.Type == model.CHANNEL_GROUP {
- res := strings.Replace(channel.DisplayName, ", ", "-", -1)
- res = strings.Replace(res, " ", "_", -1)
- return res
- }
- return channel.Name
+ return getNormalisedName(channel)
}
}
}