diff --git a/server/channels/app/channel.go b/server/channels/app/channel.go index 2577e1a899..7593080cc1 100644 --- a/server/channels/app/channel.go +++ b/server/channels/app/channel.go @@ -2378,13 +2378,6 @@ func (a *App) LeaveChannel(c request.CTX, channelID string, userID string) *mode close(uc) }() - mcc := make(chan store.StoreResult[int64], 1) - go func() { - count, err := a.Srv().Store().Channel().GetMemberCount(channelID, false) - mcc <- store.StoreResult[int64]{Data: count, NErr: err} - close(mcc) - }() - cresult := <-sc if cresult.NErr != nil { errCtx := map[string]any{"channel_id": channelID} @@ -2406,25 +2399,15 @@ func (a *App) LeaveChannel(c request.CTX, channelID string, userID string) *mode return model.NewAppError("LeaveChannel", "app.user.get.app_error", nil, "", http.StatusInternalServerError).Wrap(uresult.NErr) } } - ccresult := <-mcc - if ccresult.NErr != nil { - return model.NewAppError("LeaveChannel", "app.channel.get_member_count.app_error", nil, "", http.StatusInternalServerError).Wrap(ccresult.NErr) - } channel := cresult.Data user := uresult.Data - membersCount := ccresult.Data if channel.IsGroupOrDirect() { err := model.NewAppError("LeaveChannel", "api.channel.leave.direct.app_error", nil, "", http.StatusBadRequest) return err } - if channel.Type == model.ChannelTypePrivate && membersCount == 1 { - err := model.NewAppError("LeaveChannel", "api.channel.leave.last_member.app_error", nil, "userId="+user.Id, http.StatusBadRequest) - return err - } - if err := a.removeUserFromChannel(c, userID, userID, channel); err != nil { return err } diff --git a/server/channels/app/channel_test.go b/server/channels/app/channel_test.go index 09d8a3ff5d..0d02a251a3 100644 --- a/server/channels/app/channel_test.go +++ b/server/channels/app/channel_test.go @@ -897,6 +897,17 @@ func TestLeaveChannel(t *testing.T) { require.Nil(t, appErr) require.Len(t, threads.Threads, 1) }) + + t.Run("can leave private channel as last member", func(t *testing.T) { + channel := th.createChannel(th.Context, th.BasicTeam, model.ChannelTypePrivate) + + count, appErr := th.App.GetChannelMemberCount(th.Context, th.BasicChannel.Id) + require.Nil(t, appErr, "It should remove channel membership") + require.Equal(t, int64(1), count) + + appErr = th.App.LeaveChannel(th.Context, channel.Id, th.BasicUser.Id) + require.Nil(t, appErr) + }) } func TestLeaveLastChannel(t *testing.T) { diff --git a/server/i18n/en.json b/server/i18n/en.json index 6ff75d4d57..e9c2d7992f 100644 --- a/server/i18n/en.json +++ b/server/i18n/en.json @@ -419,10 +419,6 @@ "id": "api.channel.leave.direct.app_error", "translation": "Unable to leave a direct message channel." }, - { - "id": "api.channel.leave.last_member.app_error", - "translation": "You're the only member left, try removing the Private Channel instead of leaving." - }, { "id": "api.channel.leave.left", "translation": "%v left the channel."