@@ -10,6 +10,11 @@ import (
10
10
"github.com/mattermost/mattermost-server/v6/model"
11
11
)
12
12
13
+ const (
14
+ defaultPerPage = 100
15
+ defaultPage = 0
16
+ )
17
+
13
18
func (p * Plugin ) constructMessageTemplate (userID , teamID string ) * MessageTemplate {
14
19
data := & MessageTemplate {}
15
20
var err * model.AppError
@@ -229,13 +234,12 @@ func (p *Plugin) processActionMessage(messageTemplate MessageTemplate, action *A
229
234
230
235
func (p * Plugin ) joinChannel (action * Action , channelName string ) {
231
236
if channelName == "*" {
232
- perPage := 100
233
- page := 0
237
+ page := defaultPage
234
238
for {
235
- // Adding user to all the public channels only in case of all i.e. *
236
- channels , appErr := p .API . GetPublicChannelsForTeam (action .Context .TeamID , page , perPage )
237
- if appErr != nil {
238
- p .API . LogError ("Failed to get all the public channels for the team" , "team_id" , action .Context .TeamID )
239
+ // Adding user to all the public channels when channel name in '*' ( i.e. all)
240
+ channels , err := p .client . Channel . ListPublicChannelsForTeam (action .Context .TeamID , page , defaultPerPage )
241
+ if err != nil {
242
+ p .client . Log . Error ("Failed to get all the public channels for the team" , "team_id" , action .Context .TeamID , "error" , err . Error () )
239
243
return
240
244
}
241
245
@@ -244,21 +248,21 @@ func (p *Plugin) joinChannel(action *Action, channelName string) {
244
248
}
245
249
246
250
for _ , channel := range channels {
247
- if _ , err := p .API . AddChannelMember (channel .Id , action .Context .UserID ); err != nil {
248
- p .API . LogError ("Couldn't add user to the channel" , "user_id" , action .Context .UserID , "channel_id" , channel .Id )
251
+ if _ , err := p .client . Channel . AddMember (channel .Id , action .Context .UserID ); err != nil {
252
+ p .client . Log . Error ("Couldn't add user to the channel" , "user_id" , action .Context .UserID , "channel_id" , channel .Id , "error" , err . Error () )
249
253
return
250
254
}
251
255
}
252
256
page ++
253
257
}
254
258
} else {
255
- if channel , err := p .API . GetChannelByName (action .Context .TeamID , channelName , false ); err == nil {
256
- if _ , err : = p .API . AddChannelMember (channel .Id , action .Context .UserID ); err != nil {
257
- p .API . LogError ("Couldn't add user to the channel, continuing to next channel" , "user_id" , action .Context .UserID , "channel_id" , channel .Id )
259
+ if channel , err := p .client . Channel . GetByName (action .Context .TeamID , channelName , false ); err == nil {
260
+ if _ , err = p .client . Channel . AddMember (channel .Id , action .Context .UserID ); err != nil {
261
+ p .client . Log . Error ("Couldn't add user to the channel, continuing to next channel" , "user_id" , action .Context .UserID , "channel_id" , channel .Id , "error" , err . Error () )
258
262
return
259
263
}
260
264
} else {
261
- p .API . LogError ("failed to get channel, continuing to the next channel" , "channel_name" , channelName , "user_id" , action .Context .UserID )
265
+ p .client . Log . Error ("failed to get channel, continuing to the next channel" , "channel_name" , channelName , "user_id" , action .Context .UserID , "error" , err . Error () )
262
266
}
263
267
}
264
268
}
0 commit comments