This commit is contained in:
harshil Sharma 2023-10-20 15:57:00 +05:30
parent c70b50fefc
commit a717ea520f
11 changed files with 75 additions and 12 deletions

View file

@ -1262,3 +1262,15 @@ export const handleKickFromChannel = async (serverUrl: string, channelId: string
logDebug('cannot kick user from channel', error);
}
};
export const getGroupMessageMembersCommonTeams = async (serverUrl: string, channelId: string) => {
try {
const client = NetworkManager.getClient(serverUrl);
const teams = await client.getGroupMessageMembersCommonTeams(channelId);
return {teams};
} catch (error) {
logDebug('error on getGroupMessageMembersCommonTeams', getFullErrorMessage(error));
forceLogoutIfNecessary(serverUrl, error);
return {error};
}
};

View file

@ -44,6 +44,7 @@ export interface ClientChannelsMix {
searchAllChannels: (term: string, teamIds: string[], archivedOnly?: boolean) => Promise<Channel[]>;
updateChannelMemberSchemeRoles: (channelId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => Promise<any>;
getMemberInChannel: (channelId: string, userId: string) => Promise<ChannelMembership>;
getGroupMessageMembersCommonTeams: (channelId: string) => Promise<Team[]>;
}
const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase) => class extends superclass {
@ -350,6 +351,13 @@ const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase
{method: 'get'},
);
};
getGroupMessageMembersCommonTeams = (channelId: string) => {
return this.doFetch(
`${this.getChannelRoute(channelId)}/common_teams`,
{method: 'get'},
);
};
};
export default ClientChannels;

View file

@ -2,6 +2,7 @@
// See LICENSE.txt for license information.
import {toMilliseconds} from '@utils/datetime';
import {logDebug} from '@utils/log';
import type ClientBase from './base';
import type {ClientResponse, ClientResponseError, ProgressPromise, UploadRequestOptions} from '@mattermost/react-native-network-client';
@ -89,6 +90,7 @@ const ClientFiles = <TBase extends Constructor<ClientBase>>(superclass: TBase) =
searchFilesWithParams = async (teamId: string, params: FileSearchParams) => {
this.analytics?.trackAPI('api_files_search');
const endpoint = teamId ? `${this.getTeamRoute(teamId)}/files/search` : `${this.getFilesRoute()}/search`;
logDebug(endpoint);
return this.doFetch(endpoint, {method: 'post', body: params});
};

View file

@ -9,12 +9,16 @@ import {Screens} from '@app/constants';
import {dismissBottomSheet, goToScreen} from '@app/screens/navigation';
import {preventDoubleTap} from '@app/utils/tap';
const ConvertToChannelLabel = () => {
type Props = {
channelId: string;
}
const ConvertToChannelLabel = (props: Props) => {
const goToConvertToPrivateChannl = preventDoubleTap(async () => {
await dismissBottomSheet();
const title = 'Convert to Private Channel';
goToScreen(Screens.CONVERT_GM_TO_CHANNEL, title, {});
goToScreen(Screens.CONVERT_GM_TO_CHANNEL, title, {channelId: props.channelId});
});
const {formatMessage} = useIntl();

View file

@ -11,7 +11,7 @@ import {queryUsersById} from '@queries/servers/user';
import ManageMembersLabel from './manage_members_label';
import type {WithDatabaseArgs} from '@typings/database/database';
type OwnProps = WithDatabaseArgs & {
isDefaultChannel: boolean;
userId: string;

View file

@ -49,7 +49,7 @@ const messages = defineMessages({
type Props = {
canRemoveUser: boolean;
channelId: string;
channelId: string;
manageOption: ManageOptionsTypes;
testID?: string;
userId: string;

View file

@ -94,6 +94,7 @@ function ChannelFiles({
useAndroidHardwareBackHandler(componentId, close);
// LOL
const handleSearch = useCallback(async (searchTerm: string, ftr: FileFilter) => {
const t = Date.now();
lastSearchRequest.current = t;

View file

@ -77,6 +77,7 @@ const ChannelInfo = ({
useNavButtonPressed(closeButtonId, componentId, onPressed, [onPressed]);
useAndroidHardwareBackHandler(componentId, onPressed);
// LOL
return (
<SafeAreaView
edges={edges}
@ -112,7 +113,9 @@ const ChannelInfo = ({
<View style={styles.separator}/>
{type === General.GM_CHANNEL &&
<>
<ConvertToChannelLabel/>
<ConvertToChannelLabel
channelId={channelId}
/>
<View style={styles.separator}/>
</>
}

View file

@ -3,29 +3,51 @@
import React, {useEffect, useState} from 'react';
import {getGroupMessageMembersCommonTeams} from '@actions/remote/channel';
import {useServerUrl} from '@app/context/server';
import {ConvertGMToChannelForm} from './convert_gm_to_channel_form';
import {Loader} from './loader';
type Props = {
channelId: string;
}
const loadingIndicatorTimeout = 1200;
const ConvertGMToChannel = (props: Props) => {
const [loadingAnimationTimeout, setLoadingAnimationTimeout] = useState(false);
const [commonTeamsFetched, setCommonTeamsFetched] = useState(false);
const [commonTeams, setCommonTeams] = useState<Team[]>([]);
const serverUrl = useServerUrl();
useEffect(() => {
setTimeout(() => setLoadingAnimationTimeout(true), loadingIndicatorTimeout);
async function work() {
const {teams} = await getGroupMessageMembersCommonTeams(serverUrl, props.channelId);
if (!teams) {
return;
}
setCommonTeams(teams);
setCommonTeamsFetched(true);
}
work();
}, []);
const showLoader = !loadingAnimationTimeout;
const showLoader = !loadingAnimationTimeout && !commonTeamsFetched;
if (showLoader) {
return (<Loader/>);
}
return (
<ConvertGMToChannelForm/>
<ConvertGMToChannelForm
commonTeams={commonTeams}
/>
);
};

View file

@ -25,7 +25,11 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
};
});
export const ConvertGMToChannelForm = () => {
type Props = {
commonTeams: Team[];
}
export const ConvertGMToChannelForm = ({commonTeams}: Props) => {
const theme = useTheme();
const styles = getStyleFromTheme(theme);
@ -38,7 +42,9 @@ export const ConvertGMToChannelForm = () => {
return (
<View style={styles.container}>
<MessageBox/>
<TeamSelector/>
<TeamSelector
commonTeams={commonTeams}
/>
<ChannelNameInput/>
<Button
onPress={() => true}

View file

@ -22,7 +22,12 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
};
});
export const TeamSelector = () => {
type Props = {
commonTeams: Team[];
}
export const TeamSelector = ({commonTeams}: Props) => {
const theme = useTheme();
const styles = getStyleFromTheme(theme);
@ -35,7 +40,7 @@ export const TeamSelector = () => {
await dismissBottomSheet();
const title = formatMessage({id: 'channel_info.convert_gm_to_channel.team_selector_list.title', defaultMessage: 'Select Team'});
goToScreen(Screens.TEAM_SELECTOR_LIST, title);
goToScreen(Screens.TEAM_SELECTOR_LIST, title, {teans: commonTeams});
});
return (