Handled case of all members deactivated
This commit is contained in:
parent
bac0136dae
commit
29c64c8100
3 changed files with 35 additions and 6 deletions
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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",
|
||||
|
|
|
|||
Loading…
Reference in a new issue