diff --git a/server/channels/app/slashcommands/command_invite.go b/server/channels/app/slashcommands/command_invite.go index 34613f4be60..e3ea1d82fa4 100644 --- a/server/channels/app/slashcommands/command_invite.go +++ b/server/channels/app/slashcommands/command_invite.go @@ -71,7 +71,7 @@ func (i *InviteProvider) doCommand(a *app.App, c request.CTX, args *model.Comman targetChannels = i.checkPermissions(a, c, args, resps, targetUsers[0], targetChannels) // track errors returned for various users. - differentChannels := make([]string, 0, 1) + differentChannels := make(map[string][]string) nonTeamUsers := make(map[string][]string) channelConstrained := make([]string, 0, 1) usersInChannel := make([]string, 0, 1) @@ -83,7 +83,7 @@ func (i *InviteProvider) doCommand(a *app.App, c request.CTX, args *model.Comman userError := i.addUserToChannel(a, c, args, targetUser, targetChannel) if userError == NoError { if args.ChannelId != targetChannel.Id { - differentChannels = append(differentChannels, targetUser.Username) + differentChannels[targetChannel.Name] = append(differentChannels[targetChannel.Name], targetUser.Username) } } else if userError == UserNotInTeam { if targetTeamDisplay == "" { @@ -124,22 +124,24 @@ func (i *InviteProvider) doCommand(a *app.App, c request.CTX, args *model.Comman } if len(differentChannels) > 0 { - if len(differentChannels) > 10 { - *resps = append(*resps, - args.T("api.command_invite.successOverflow", map[string]any{ - "FirstUser": "@" + differentChannels[0], - "Others": len(differentChannels) - 1, - "Channel": "", - }), - ) - } else { - usersString := map[string]any{ - "Users": "@" + strings.Join(differentChannels, ", @"), - "Channel": "test", + for k, v := range differentChannels { + if len(v) > 10 { + *resps = append(*resps, + args.T("api.command_invite.successOverflow", map[string]any{ + "FirstUser": "@" + v[0], + "Others": len(v) - 1, + "Channel": k, + }), + ) + } else { + usersString := map[string]any{ + "User": "@" + strings.Join(v, ", @"), + "Channel": k, + } + *resps = append(*resps, + args.T("api.command_invite.success", usersString), + ) } - *resps = append(*resps, - args.T("api.command_invite.success", usersString), - ) } } diff --git a/server/channels/app/slashcommands/command_invite_test.go b/server/channels/app/slashcommands/command_invite_test.go index c22c04f8833..5923ceb8ad7 100644 --- a/server/channels/app/slashcommands/command_invite_test.go +++ b/server/channels/app/slashcommands/command_invite_test.go @@ -74,7 +74,7 @@ func TestInviteProvider(t *testing.T) { channel2 := th.createChannel(th.BasicTeam, model.ChannelTypeOpen) msg := "@" + th.BasicUser2.Username + " @" + anotherUser.Username + " ~" + channel1.Name + " ~" + channel2.Name - expected := "api.command_invite.success" + expected := "api.command_invite.success\napi.command_invite.success" runCmd(msg, expected) checkIsMember(channel1.Id, th.BasicUser2.Id) checkIsMember(channel2.Id, th.BasicUser2.Id)