From 7106c1807b7b8284b4a443bfd2c20322d19804f6 Mon Sep 17 00:00:00 2001 From: harshil Sharma Date: Fri, 10 Nov 2023 16:14:11 +0530 Subject: [PATCH] Somre review fixes --- app/actions/local/category.ts | 23 ++++++++++++++----- app/actions/remote/channel.ts | 2 +- .../convert_to_channel_label.tsx | 16 ++++++------- app/components/option_item/index.tsx | 1 - app/init/launch.ts | 1 - app/queries/servers/categories.ts | 2 +- app/queries/servers/role.ts | 4 ++++ app/screens/channel_info/channel_info.tsx | 10 ++++---- 8 files changed, 35 insertions(+), 24 deletions(-) diff --git a/app/actions/local/category.ts b/app/actions/local/category.ts index d0834b10b..9d853daf4 100644 --- a/app/actions/local/category.ts +++ b/app/actions/local/category.ts @@ -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}; } } diff --git a/app/actions/remote/channel.ts b/app/actions/remote/channel.ts index dae8e0ed6..e9297b915 100644 --- a/app/actions/remote/channel.ts +++ b/app/actions/remote/channel.ts @@ -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) { diff --git a/app/components/channel_actions/convert_to_channel/convert_to_channel_label.tsx b/app/components/channel_actions/convert_to_channel/convert_to_channel_label.tsx index 456e93631..701f02419 100644 --- a/app/components/channel_actions/convert_to_channel/convert_to_channel_label.tsx +++ b/app/components/channel_actions/convert_to_channel/convert_to_channel_label.tsx @@ -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 ( ); diff --git a/app/components/option_item/index.tsx b/app/components/option_item/index.tsx index b5d69c59e..fc67dbdd2 100644 --- a/app/components/option_item/index.tsx +++ b/app/components/option_item/index.tsx @@ -65,7 +65,6 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => { marginTop: DESCRIPTION_MARGIN_TOP, }, iconContainer: {marginRight: 16}, - infoContainer: {marginRight: 2}, info: { flex: 1, textAlign: 'right', diff --git a/app/init/launch.ts b/app/init/launch.ts index fc9e99c00..f03c6426c 100644 --- a/app/init/launch.ts +++ b/app/init/launch.ts @@ -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) { diff --git a/app/queries/servers/categories.ts b/app/queries/servers/categories.ts index 20d4ac369..5d7a1deec 100644 --- a/app/queries/servers/categories.ts +++ b/app/queries/servers/categories.ts @@ -52,7 +52,7 @@ export async function prepareCategoriesAndCategoriesChannels(operator: ServerDat const teamIdToChannelIds = new Map>(); 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); }); diff --git a/app/queries/servers/role.ts b/app/queries/servers/role.ts index ae1c05d81..900b1b1dd 100644 --- a/app/queries/servers/role.ts +++ b/app/queries/servers/role.ts @@ -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( diff --git a/app/screens/channel_info/channel_info.tsx b/app/screens/channel_info/channel_info.tsx index 7a505e87b..cf9e5f20f 100644 --- a/app/screens/channel_info/channel_info.tsx +++ b/app/screens/channel_info/channel_info.tsx @@ -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 ( - {type === General.GM_CHANNEL && !currentUser.isGuest && + {convertGMOptionAvailable && <> - + }