Skip to content

Commit

Permalink
Make getChannelIdTeam behave like GetChannelId for groups (mattermost) (
Browse files Browse the repository at this point in the history
#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.
  • Loading branch information
bucko909 authored and 42wim committed Sep 7, 2019
1 parent 3562d42 commit 1dc93ec
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions matterclient/channels.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
}
}
Expand All @@ -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
}
}
Expand All @@ -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)
}
}
}
Expand Down

0 comments on commit 1dc93ec

Please sign in to comment.