From 29c64c81002545b2d9252ffde4236413c09e5e00 Mon Sep 17 00:00:00 2001 From: harshil Sharma Date: Thu, 26 Oct 2023 11:23:32 +0530 Subject: [PATCH] Handled case of all members deactivated --- .../convert_gm_to_channel.tsx | 23 +++++++++++++++---- app/screens/convert_gm_to_channel/index.tsx | 17 +++++++++++++- assets/base/i18n/en.json | 1 + 3 files changed, 35 insertions(+), 6 deletions(-) diff --git a/app/screens/convert_gm_to_channel/convert_gm_to_channel.tsx b/app/screens/convert_gm_to_channel/convert_gm_to_channel.tsx index accff6cfa..3d8680051 100644 --- a/app/screens/convert_gm_to_channel/convert_gm_to_channel.tsx +++ b/app/screens/convert_gm_to_channel/convert_gm_to_channel.tsx @@ -6,19 +6,18 @@ import React, {useEffect, useRef, useState} from 'react'; import {fetchChannelMemberships, getGroupMessageMembersCommonTeams} from '@actions/remote/channel'; import {PER_PAGE_DEFAULT} from '@app/client/rest/constants'; import {useServerUrl} from '@app/context/server'; -import {logDebug} from '@app/utils/log'; import {ConvertGMToChannelForm} from './convert_gm_to_channel_form'; import {Loader} from './loader'; -import UserProfile from '../user_profile/user_profile'; type Props = { channelId: string; + currentUserId?: string; } const loadingIndicatorTimeout = 1200; -const ConvertGMToChannel = ({channelId}: Props) => { +const ConvertGMToChannel = ({channelId, currentUserId}: Props) => { const [loadingAnimationTimeout, setLoadingAnimationTimeout] = useState(false); const [commonTeamsFetched, setCommonTeamsFetched] = useState(false); const [channelMembersFetched, setChannelMembersFetched] = useState(false); @@ -42,8 +41,11 @@ const ConvertGMToChannel = ({channelId}: Props) => { } work(); + }, []); + useEffect(() => { mounted.current = true; + const options: GetUsersOptions = {sort: 'admin', active: true, per_page: PER_PAGE_DEFAULT}; fetchChannelMemberships(serverUrl, channelId, options, true).then(({users, members}) => { if (!mounted.current) { @@ -51,14 +53,25 @@ const ConvertGMToChannel = ({channelId}: Props) => { } if (users.length) { + // Gotta make sure we use profiles that are in members. + // See comment in fetchChannelMemberships for more details. + const usersById: {[id: string]: UserProfile} = {}; // eslint-disable-next-line max-nested-callbacks users.forEach((profile) => { - usersById[profile.id] = profile; + if (profile.id !== currentUserId) { + usersById[profile.id] = profile; + } }); // eslint-disable-next-line max-nested-callbacks - const filteredUsers = members.map((member) => usersById[member.user_id]); + const filteredUsers: UserProfile[] = []; + // eslint-disable-next-line max-nested-callbacks + members.forEach((member) => { + if (usersById[member.user_id]) { + filteredUsers.push(usersById[member.user_id]); + } + }); setProfiles(filteredUsers); } diff --git a/app/screens/convert_gm_to_channel/index.tsx b/app/screens/convert_gm_to_channel/index.tsx index be792d536..556fcf15b 100644 --- a/app/screens/convert_gm_to_channel/index.tsx +++ b/app/screens/convert_gm_to_channel/index.tsx @@ -1,6 +1,21 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider'; +import withObservables from '@nozbe/with-observables'; + +import {observeCurrentUserId} from '@app/queries/servers/system'; + import ConvertGMToChannel from './convert_gm_to_channel'; -export default ConvertGMToChannel; +import type {WithDatabaseArgs} from '@typings/database/database'; + +const enhance = withObservables([], ({database}: WithDatabaseArgs) => { + const currentUserId = observeCurrentUserId(database); + + return { + currentUserId, + }; +}); + +export default withDatabase(enhance(ConvertGMToChannel)); diff --git a/assets/base/i18n/en.json b/assets/base/i18n/en.json index c542d7284..6554aa057 100644 --- a/assets/base/i18n/en.json +++ b/assets/base/i18n/en.json @@ -1090,6 +1090,7 @@ "channel_info.convert_gm_to_channel": "Convert to a Private Channel", "channel_info.convert_gm_to_channel.warning.header": "Conversation history will be visible to any channel members", "channel_info.convert_gm_to_channel.warning.body": "You are about to convert the Group Message with {memberNames} to a Channel. This cannot be undone.", + "channel_info.convert_gm_to_channel.warning.body.yourself": "yourself", "channel_into.convert_gm_to_channel.team_selector.label": "Team", "channel_into.convert_gm_to_channel.team_selector.placeholder": "Select a Team", "channel_info.convert_gm_to_channel.button_text": "Convert to Private Channel",