Making conversion API call
This commit is contained in:
parent
978a13adc5
commit
67f6740be4
7 changed files with 106 additions and 18 deletions
|
|
@ -1274,3 +1274,33 @@ export const getGroupMessageMembersCommonTeams = async (serverUrl: string, chann
|
|||
return {error};
|
||||
}
|
||||
};
|
||||
|
||||
export const convertGroupMessageToPrivateChannel = async (serverUrl: string, channelId: string, teamId: string, displayName: string) => {
|
||||
try {
|
||||
const client = NetworkManager.getClient(serverUrl);
|
||||
const name = generateChannelNameFromDisplayName(displayName);
|
||||
|
||||
const {database, operator} = DatabaseManager.getServerDatabaseAndOperator(serverUrl);
|
||||
const existingChannel = await getChannelById(database, channelId);
|
||||
|
||||
// addConvertingChannel ??? do we need to do this?
|
||||
|
||||
const updatedChannel = await client.convertGroupMessageToPrivateChannel(channelId, teamId, displayName, name);
|
||||
|
||||
if (existingChannel) {
|
||||
existingChannel.prepareUpdate((channel) => {
|
||||
channel.type = General.PRIVATE_CHANNEL;
|
||||
channel.displayName = displayName;
|
||||
channel.name = name;
|
||||
});
|
||||
|
||||
await operator.batchRecords([existingChannel], 'convertGroupMessageToPrivateChannel');
|
||||
}
|
||||
|
||||
return {updatedChannel};
|
||||
} catch (error) {
|
||||
logDebug('error on convertGroupMessageToPrivateChannel', getFullErrorMessage(error));
|
||||
forceLogoutIfNecessary(serverUrl, error);
|
||||
return {error};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ export interface ClientChannelsMix {
|
|||
updateChannelMemberSchemeRoles: (channelId: string, userId: string, isSchemeUser: boolean, isSchemeAdmin: boolean) => Promise<any>;
|
||||
getMemberInChannel: (channelId: string, userId: string) => Promise<ChannelMembership>;
|
||||
getGroupMessageMembersCommonTeams: (channelId: string) => Promise<Team[]>;
|
||||
convertGroupMessageToPrivateChannel: (channelId: string, teamId: string, displayName: string, name: string) => Promise<Channel>;
|
||||
}
|
||||
|
||||
const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase) => class extends superclass {
|
||||
|
|
@ -358,6 +359,20 @@ const ClientChannels = <TBase extends Constructor<ClientBase>>(superclass: TBase
|
|||
{method: 'get'},
|
||||
);
|
||||
};
|
||||
|
||||
convertGroupMessageToPrivateChannel = (channelId: string, teamId: string, displayName: string, name: string) => {
|
||||
const body = {
|
||||
channel_id: channelId,
|
||||
team_id: teamId,
|
||||
display_name: displayName,
|
||||
name,
|
||||
};
|
||||
|
||||
return this.doFetch(
|
||||
`${this.getChannelRoute(channelId)}/convert_to_channel?team-id=${teamId}`,
|
||||
{method: 'post', body},
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
export default ClientChannels;
|
||||
|
|
|
|||
|
|
@ -42,6 +42,7 @@ const ConvertPrivate = ({canConvert, channelId, displayName}: Props) => {
|
|||
);
|
||||
};
|
||||
|
||||
// LOL LOL
|
||||
const convertToPrivate = preventDoubleTap(async () => {
|
||||
const result = await convertChannelToPrivate(serverUrl, channelId);
|
||||
const {formatMessage} = intl;
|
||||
|
|
|
|||
|
|
@ -12,9 +12,10 @@ import {getKeyboardAppearanceFromTheme} from '@app/utils/theme';
|
|||
|
||||
type Props = {
|
||||
error?: string;
|
||||
onChange: (text: string) => void;
|
||||
}
|
||||
|
||||
export const ChannelNameInput = ({error}: Props) => {
|
||||
export const ChannelNameInput = ({error, onChange}: Props) => {
|
||||
const {formatMessage} = useIntl();
|
||||
const theme = useTheme();
|
||||
|
||||
|
|
@ -38,6 +39,7 @@ export const ChannelNameInput = ({error}: Props) => {
|
|||
testID='gonvert_gm_to_channel.channel_display_name.input'
|
||||
theme={theme}
|
||||
error={error}
|
||||
onChangeText={onChange}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import {useServerUrl} from '@app/context/server';
|
|||
|
||||
import {ConvertGMToChannelForm} from './convert_gm_to_channel_form/convert_gm_to_channel_form';
|
||||
import {Loader} from './loader';
|
||||
import channel from '@app/constants/channel';
|
||||
|
||||
type Props = {
|
||||
channelId: string;
|
||||
|
|
@ -98,6 +99,7 @@ const ConvertGMToChannel = ({
|
|||
commonTeams={commonTeams}
|
||||
profiles={profiles}
|
||||
teammateNameDisplay={teammateNameDisplay}
|
||||
channelId={channelId}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,12 +1,14 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React, {useCallback, useEffect, useRef} from 'react';
|
||||
import React, {useCallback, useEffect, useRef, useState} from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
import {View} from 'react-native';
|
||||
|
||||
import {convertGroupMessageToPrivateChannel, switchToChannelById} from '@actions/remote/channel';
|
||||
import {useServerUrl} from '@app/context/server';
|
||||
import {useTheme} from '@app/context/theme';
|
||||
import {logDebug} from '@app/utils/log';
|
||||
import {logDebug, logError} from '@app/utils/log';
|
||||
import {makeStyleSheetFromTheme} from '@app/utils/theme';
|
||||
import {displayUsername} from '@app/utils/user';
|
||||
import Button from '@components/button';
|
||||
|
|
@ -16,6 +18,9 @@ import MessageBox from '../message_box/message_box';
|
|||
import {TeamSelector} from '../team_selector';
|
||||
|
||||
import {NoCommonTeamForm} from './no_common_teams_form';
|
||||
import { dismissAllModalsAndPopToRoot, popToRoot, popTopScreen } from '@app/screens/navigation';
|
||||
import { switchToChannel } from '@actions/local/channel';
|
||||
import { update } from 'lodash';
|
||||
|
||||
const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
|
||||
return {
|
||||
|
|
@ -30,6 +35,7 @@ const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
|
|||
});
|
||||
|
||||
type Props = {
|
||||
channelId: string;
|
||||
commonTeams: Team[];
|
||||
profiles: UserProfile[];
|
||||
locale?: string;
|
||||
|
|
@ -37,6 +43,7 @@ type Props = {
|
|||
}
|
||||
|
||||
export const ConvertGMToChannelForm = ({
|
||||
channelId,
|
||||
commonTeams,
|
||||
profiles,
|
||||
locale,
|
||||
|
|
@ -44,8 +51,11 @@ export const ConvertGMToChannelForm = ({
|
|||
}: Props) => {
|
||||
const theme = useTheme();
|
||||
const styles = getStyleFromTheme(theme);
|
||||
const serverUrl = useServerUrl();
|
||||
const intl = useIntl();
|
||||
|
||||
const team = useRef<Team>();
|
||||
const [selectedTeam, setSelectedTeam] = useState<Team>();
|
||||
const newChannelName = useRef<string>();
|
||||
|
||||
const {formatMessage} = useIntl();
|
||||
const confirmButtonText = formatMessage({
|
||||
|
|
@ -54,20 +64,38 @@ export const ConvertGMToChannelForm = ({
|
|||
});
|
||||
|
||||
useEffect(() => {
|
||||
logDebug(`BBB commonTeams.length: ${commonTeams.length}`);
|
||||
if (commonTeams.length > 0) {
|
||||
team.current = commonTeams[0];
|
||||
logDebug(`BBB commonTeams[0]: ${commonTeams[0].display_name}`);
|
||||
setSelectedTeam(commonTeams[0]);
|
||||
}
|
||||
}, [commonTeams]);
|
||||
|
||||
const handleOnSelectTeam = useCallback((selectedTeam: Team) => {
|
||||
team.current = selectedTeam;
|
||||
const handleOnPress = useCallback(async () => {
|
||||
if (!selectedTeam || !newChannelName.current) {
|
||||
logDebug(`!selectedTeam: ${selectedTeam} || !newChannelName.current: ${newChannelName.current}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const {updatedChannel, error} = await convertGroupMessageToPrivateChannel(serverUrl, channelId, selectedTeam.id, newChannelName.current);
|
||||
logDebug(updatedChannel);
|
||||
|
||||
if (error) {
|
||||
logError(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!updatedChannel) {
|
||||
return;
|
||||
}
|
||||
|
||||
switchToChannelById(serverUrl, updatedChannel.id, selectedTeam.id);
|
||||
}, [selectedTeam]);
|
||||
|
||||
const handleOnChannelNameChange = useCallback((newName: string) => {
|
||||
newChannelName.current = newName;
|
||||
}, []);
|
||||
|
||||
const handleOnPress = useCallback(() => {
|
||||
logDebug(1);
|
||||
}, []);
|
||||
|
||||
const intl = useIntl();
|
||||
const messageBoxHeader = intl.formatMessage({
|
||||
id: 'channel_info.convert_gm_to_channel.warning.header',
|
||||
defaultMessage: 'Conversation history will be visible to any channel members',
|
||||
|
|
@ -75,9 +103,7 @@ export const ConvertGMToChannelForm = ({
|
|||
|
||||
const userDisplayNames = profiles.map((profile) => displayUsername(profile, locale, teammateNameDisplay));
|
||||
const defaultUserDisplayNames = intl.formatMessage({id: 'channel_info.convert_gm_to_channel.warning.body.yourself', defaultMessage: 'yourself'});
|
||||
|
||||
const memberNames = profiles.length > 0 ? intl.formatList(userDisplayNames) : defaultUserDisplayNames;
|
||||
|
||||
const messageBoxBody = intl.formatMessage({
|
||||
id: 'channel_info.convert_gm_to_channel.warning.bodyXXXX',
|
||||
defaultMessage: 'You are about to convert the Group Message with {memberNames} to a Channel. This cannot be undone.',
|
||||
|
|
@ -101,11 +127,13 @@ export const ConvertGMToChannelForm = ({
|
|||
commonTeams.length > 1 &&
|
||||
<TeamSelector
|
||||
commonTeams={commonTeams}
|
||||
onSelectTeam={handleOnSelectTeam}
|
||||
selectedTeamId={team.current?.id}
|
||||
onSelectTeam={setSelectedTeam}
|
||||
selectedTeamId={selectedTeam?.id}
|
||||
/>
|
||||
}
|
||||
<ChannelNameInput/>
|
||||
<ChannelNameInput
|
||||
onChange={handleOnChannelNameChange}
|
||||
/>
|
||||
<Button
|
||||
onPress={handleOnPress}
|
||||
text={confirmButtonText}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React, { useCallback, useState } from 'react';
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
import {Platform} from 'react-native';
|
||||
|
||||
|
|
@ -11,6 +11,7 @@ import {useTheme} from '@app/context/theme';
|
|||
import {dismissBottomSheet, goToScreen} from '@app/screens/navigation';
|
||||
import {preventDoubleTap} from '@app/utils/tap';
|
||||
import {changeOpacity, makeStyleSheetFromTheme} from '@app/utils/theme';
|
||||
import { logDebug } from '@app/utils/log';
|
||||
|
||||
const getStyleFromTheme = makeStyleSheetFromTheme((theme: Theme) => {
|
||||
return {
|
||||
|
|
@ -38,6 +39,15 @@ export const TeamSelector = ({commonTeams, onSelectTeam, selectedTeamId}: Props)
|
|||
const label = formatMessage({id: 'channel_into.convert_gm_to_channel.team_selector.label', defaultMessage: 'Team'});
|
||||
const placeholder = formatMessage({id: 'channel_into.convert_gm_to_channel.team_selector.placeholder', defaultMessage: 'Select a Team'});
|
||||
|
||||
useEffect(() => {
|
||||
logDebug(`AAA selectedTeamId: ${selectedTeamId}`);
|
||||
if (selectedTeamId) {
|
||||
const team = commonTeams.find((t) => t.id === selectedTeamId);
|
||||
logDebug(`AAA team: ${team?.display_name}`);
|
||||
setSelectedTeam(team);
|
||||
}
|
||||
}, [selectedTeamId]);
|
||||
|
||||
const selectTeam = useCallback((teamId: string) => {
|
||||
const team = commonTeams.find((t) => t.id === teamId);
|
||||
if (team) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue