Somre review fixes
This commit is contained in:
parent
799e78c784
commit
7106c1807b
8 changed files with 35 additions and 24 deletions
|
|
@ -7,7 +7,7 @@ import {prepareCategoryChannels, queryCategoriesByTeamIds, getCategoryById, prep
|
|||
import {getCurrentUserId} from '@queries/servers/system';
|
||||
import {queryMyTeams} from '@queries/servers/team';
|
||||
import {isDMorGM} from '@utils/channel';
|
||||
import {logError} from '@utils/log';
|
||||
import {logDebug, logError} from '@utils/log';
|
||||
|
||||
import type {Database, Model} from '@nozbe/watermelondb';
|
||||
import type ChannelModel from '@typings/database/models/servers/channel';
|
||||
|
|
@ -106,6 +106,7 @@ export async function addChannelToDefaultCategory(serverUrl: string, channel: Ch
|
|||
|
||||
return {models};
|
||||
} catch (error) {
|
||||
logError('Failed to add channel to default category', error);
|
||||
return {error};
|
||||
}
|
||||
}
|
||||
|
|
@ -115,7 +116,7 @@ async function prepareAddNonGMDMChannelToDefaultCategory(database: Database, tea
|
|||
const channelCategory = categories.find((category) => category.type === CHANNELS_CATEGORY);
|
||||
if (channelCategory) {
|
||||
const cwc = await channelCategory.toCategoryWithChannels();
|
||||
if (!cwc.channel_ids.indexOf(channelId)) {
|
||||
if (cwc.channel_ids.indexOf(channelId) < 0) {
|
||||
cwc.channel_ids.unshift(channelId);
|
||||
return cwc;
|
||||
}
|
||||
|
|
@ -132,16 +133,25 @@ export async function handleConvertedGMCategories(serverUrl: string, channelId:
|
|||
const categories = await queryCategoriesByTeamIds(database, [targetTeamID]).fetch();
|
||||
const channelCategory = categories.find((category) => category.type === CHANNELS_CATEGORY);
|
||||
|
||||
categoryChannels.
|
||||
filter((categoryChannel) => categoryChannel.categoryId !== channelCategory?.id).
|
||||
forEach((categoryChannel) => categoryChannel.prepareDestroyPermanently());
|
||||
if (!channelCategory) {
|
||||
logError('Failed to find default category when handling category of converted GM');
|
||||
return {};
|
||||
}
|
||||
|
||||
const models: Model[] = categoryChannels;
|
||||
const models: Model[] = [];
|
||||
|
||||
categoryChannels.forEach((categoryChannel) => {
|
||||
if (categoryChannel.categoryId !== channelCategory.id) {
|
||||
models.push(categoryChannel.prepareDestroyPermanently());
|
||||
}
|
||||
});
|
||||
|
||||
const cwc = await prepareAddNonGMDMChannelToDefaultCategory(database, targetTeamID, channelId);
|
||||
if (cwc) {
|
||||
const model = await prepareCategoryChannels(operator, [cwc]);
|
||||
models.push(...model);
|
||||
} else {
|
||||
logDebug('handleConvertedGMCategories: could not find channel category of target team');
|
||||
}
|
||||
|
||||
if (models.length > 0 && !prepareRecordsOnly) {
|
||||
|
|
@ -150,6 +160,7 @@ export async function handleConvertedGMCategories(serverUrl: string, channelId:
|
|||
|
||||
return {models};
|
||||
} catch (error) {
|
||||
logError('Failed to handle category update for GM converted to channel', error);
|
||||
return {error};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1297,7 +1297,7 @@ export const convertGroupMessageToPrivateChannel = async (serverUrl: string, cha
|
|||
channel.teamId = targetTeamId;
|
||||
});
|
||||
|
||||
const models: any[] = [existingChannel];
|
||||
const models: Model[] = [existingChannel];
|
||||
|
||||
const {models: categoryUpdateModels} = await handleConvertedGMCategories(serverUrl, channelId, targetTeamId, true);
|
||||
if (categoryUpdateModels) {
|
||||
|
|
|
|||
|
|
@ -4,31 +4,29 @@
|
|||
import React from 'react';
|
||||
import {useIntl} from 'react-intl';
|
||||
|
||||
import OptionItem from '@app/components/option_item';
|
||||
import {Screens} from '@app/constants';
|
||||
import {dismissBottomSheet, goToScreen} from '@app/screens/navigation';
|
||||
import {preventDoubleTap} from '@app/utils/tap';
|
||||
import OptionItem from '@components/option_item';
|
||||
import {Screens} from '@constants';
|
||||
import {dismissBottomSheet, goToScreen} from '@screens/navigation';
|
||||
import {preventDoubleTap} from '@utils/tap';
|
||||
|
||||
type Props = {
|
||||
channelId: string;
|
||||
}
|
||||
|
||||
const ConvertToChannelLabel = (props: Props) => {
|
||||
const ConvertToChannelLabel = ({channelId}: Props) => {
|
||||
const {formatMessage} = useIntl();
|
||||
|
||||
const goToConvertToPrivateChannl = preventDoubleTap(async () => {
|
||||
await dismissBottomSheet();
|
||||
const title = formatMessage({id: 'channel_info.convert_gm_to_channel.screen_title', defaultMessage: 'Convert to Private Channel'});
|
||||
goToScreen(Screens.CONVERT_GM_TO_CHANNEL, title, {channelId: props.channelId});
|
||||
goToScreen(Screens.CONVERT_GM_TO_CHANNEL, title, {channelId});
|
||||
});
|
||||
|
||||
const label = formatMessage({id: 'channel_info.convert_gm_to_channel', defaultMessage: 'Convert to a Private Channel'});
|
||||
|
||||
return (
|
||||
<OptionItem
|
||||
action={goToConvertToPrivateChannl}
|
||||
icon='lock-outline'
|
||||
label={label}
|
||||
label={formatMessage({id: 'channel_info.convert_gm_to_channel', defaultMessage: 'Convert to a Private Channel'})}
|
||||
type='default'
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -65,7 +65,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => {
|
|||
marginTop: DESCRIPTION_MARGIN_TOP,
|
||||
},
|
||||
iconContainer: {marginRight: 16},
|
||||
infoContainer: {marginRight: 2},
|
||||
info: {
|
||||
flex: 1,
|
||||
textAlign: 'right',
|
||||
|
|
|
|||
|
|
@ -70,7 +70,6 @@ const launchAppFromNotification = async (notification: NotificationWithData, col
|
|||
|
||||
* @returns a redirection to a screen, either onboarding, add_server, login or home depending on the scenario
|
||||
*/
|
||||
|
||||
const launchApp = async (props: LaunchProps) => {
|
||||
let serverUrl: string | undefined;
|
||||
switch (props?.launchType) {
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ export async function prepareCategoriesAndCategoriesChannels(operator: ServerDat
|
|||
const teamIdToChannelIds = new Map<String, Set<String>>();
|
||||
categories.forEach((category) => {
|
||||
const value = teamIdToChannelIds.get(category.team_id) || new Set();
|
||||
category.channel_ids.forEach((channelId) => value.add(channelId));
|
||||
category.channel_ids.forEach(value.add, value);
|
||||
teamIdToChannelIds.set(category.team_id, value);
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import {Database, Q} from '@nozbe/watermelondb';
|
|||
import {of as of$, combineLatest} from 'rxjs';
|
||||
import {switchMap, distinctUntilChanged} from 'rxjs/operators';
|
||||
|
||||
import {logDebug} from '@app/utils/log';
|
||||
import {Database as DatabaseConstants, General, Permissions} from '@constants';
|
||||
import {isDMorGM} from '@utils/channel';
|
||||
import {hasPermission} from '@utils/role';
|
||||
|
|
@ -69,8 +70,11 @@ export function observePermissionForTeam(database: Database, team: TeamModel | u
|
|||
switchMap((myTeam) => {
|
||||
const rolesArray = [...user.roles.split(' ')];
|
||||
|
||||
logDebug(`user.roles: ${user.roles}`);
|
||||
|
||||
if (myTeam) {
|
||||
rolesArray.push(...myTeam.roles.split(' '));
|
||||
logDebug(`myTeam.roles: ${myTeam.roles}`);
|
||||
}
|
||||
|
||||
return queryRolesByNames(database, rolesArray).observeWithColumns(['permissions']).pipe(
|
||||
|
|
|
|||
|
|
@ -5,10 +5,10 @@ import React, {useCallback} from 'react';
|
|||
import {ScrollView, View} from 'react-native';
|
||||
import {type Edge, SafeAreaView} from 'react-native-safe-area-context';
|
||||
|
||||
import ConvertToChannelLabel from '@app/components/channel_actions/convert_to_channel/convert_to_channel_label';
|
||||
import {General} from '@app/constants';
|
||||
import ChannelInfoEnableCalls from '@calls/components/channel_info_enable_calls';
|
||||
import ChannelActions from '@components/channel_actions';
|
||||
import ConvertToChannelLabel from '@components/channel_actions/convert_to_channel/convert_to_channel_label';
|
||||
import {useServerUrl} from '@context/server';
|
||||
import {useTheme} from '@context/theme';
|
||||
import useAndroidHardwareBackHandler from '@hooks/android_back_handler';
|
||||
|
|
@ -80,6 +80,8 @@ const ChannelInfo = ({
|
|||
useNavButtonPressed(closeButtonId, componentId, onPressed, [onPressed]);
|
||||
useAndroidHardwareBackHandler(componentId, onPressed);
|
||||
|
||||
const convertGMOptionAvailable = type === General.GM_CHANNEL && !currentUser.isGuest;
|
||||
|
||||
return (
|
||||
<SafeAreaView
|
||||
edges={edges}
|
||||
|
|
@ -113,11 +115,9 @@ const ChannelInfo = ({
|
|||
canManageSettings={canManageSettings}
|
||||
/>
|
||||
<View style={styles.separator}/>
|
||||
{type === General.GM_CHANNEL && !currentUser.isGuest &&
|
||||
{convertGMOptionAvailable &&
|
||||
<>
|
||||
<ConvertToChannelLabel
|
||||
channelId={channelId}
|
||||
/>
|
||||
<ConvertToChannelLabel channelId={channelId}/>
|
||||
<View style={styles.separator}/>
|
||||
</>
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue