From 3650cdfc6d9649d9f5d5de56b01954a438b02628 Mon Sep 17 00:00:00 2001 From: Elias Nahum Date: Sat, 26 Mar 2022 20:40:17 -0300 Subject: [PATCH] fix Require cycle --- app/actions/local/post.ts | 5 ---- app/actions/local/timezone.ts | 26 ------------------ app/actions/remote/post.ts | 4 +++ app/actions/remote/session.ts | 3 ++- app/actions/remote/user.ts | 27 ++++++++++++++++++- .../message_attachments/action_menu/index.tsx | 2 +- app/screens/custom_status/index.tsx | 3 ++- .../custom_status_clear_after/index.tsx | 3 ++- app/screens/navigation.ts | 9 +++---- app/utils/navigation/index.ts | 12 +++++++++ app/utils/theme/index.ts | 2 +- index.ts | 1 - 12 files changed, 53 insertions(+), 44 deletions(-) create mode 100644 app/utils/navigation/index.ts diff --git a/app/actions/local/post.ts b/app/actions/local/post.ts index 6c0f71b81..60a2c7eb8 100644 --- a/app/actions/local/post.ts +++ b/app/actions/local/post.ts @@ -1,7 +1,6 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. -import {postActionWithCookie} from '@actions/remote/post'; import {ActionType, Post} from '@constants'; import DatabaseManager from '@database/manager'; import {getPostById, prepareDeletePost} from '@queries/servers/post'; @@ -133,10 +132,6 @@ export const removePost = async (serverUrl: string, post: PostModel | Post) => { return {post}; }; -export const selectAttachmentMenuAction = (serverUrl: string, postId: string, actionId: string, selectedOption: string) => { - return postActionWithCookie(serverUrl, postId, actionId, '', selectedOption); -}; - export const markPostAsDeleted = async (serverUrl: string, post: Post) => { const operator = DatabaseManager.serverDatabases[serverUrl]?.operator; if (!operator) { diff --git a/app/actions/local/timezone.ts b/app/actions/local/timezone.ts index f9d4cc58d..cfda4071e 100644 --- a/app/actions/local/timezone.ts +++ b/app/actions/local/timezone.ts @@ -3,10 +3,6 @@ import {getTimeZone} from 'react-native-localize'; -import {updateMe} from '@actions/remote/user'; -import DatabaseManager from '@database/manager'; -import {getUserById} from '@queries/servers/user'; - import type UserModel from '@typings/database/models/servers/user'; export const isTimezoneEnabled = (config: Partial) => { @@ -17,28 +13,6 @@ export function getDeviceTimezone() { return getTimeZone(); } -export const autoUpdateTimezone = async (serverUrl: string, {deviceTimezone, userId}: {deviceTimezone: string; userId: string}) => { - const database = DatabaseManager.serverDatabases[serverUrl].database; - if (!database) { - return {error: `No database present for ${serverUrl}`}; - } - - const currentUser = await getUserById(database, userId); - - if (!currentUser) { - return null; - } - - const currentTimezone = getUserTimezone(currentUser); - const newTimezoneExists = currentTimezone.automaticTimezone !== deviceTimezone; - - if (currentTimezone.useAutomaticTimezone && newTimezoneExists) { - const timezone = {useAutomaticTimezone: 'true', automaticTimezone: deviceTimezone, manualTimezone: currentTimezone.manualTimezone}; - await updateMe(serverUrl, {timezone}); - } - return null; -}; - export const getUserTimezone = (currentUser: UserModel) => { if (currentUser?.timezone) { return { diff --git a/app/actions/remote/post.ts b/app/actions/remote/post.ts index 8f80c543d..0e010ce26 100644 --- a/app/actions/remote/post.ts +++ b/app/actions/remote/post.ts @@ -854,3 +854,7 @@ export async function fetchSavedPosts(serverUrl: string, teamId?: string, channe return {error}; } } + +export const selectAttachmentMenuAction = (serverUrl: string, postId: string, actionId: string, selectedOption: string) => { + return postActionWithCookie(serverUrl, postId, actionId, '', selectedOption); +}; diff --git a/app/actions/remote/session.ts b/app/actions/remote/session.ts index 6e6d2124c..5d8116e88 100644 --- a/app/actions/remote/session.ts +++ b/app/actions/remote/session.ts @@ -3,7 +3,7 @@ import {DeviceEventEmitter} from 'react-native'; -import {autoUpdateTimezone, getDeviceTimezone, isTimezoneEnabled} from '@actions/local/timezone'; +import {getDeviceTimezone, isTimezoneEnabled} from '@actions/local/timezone'; import {Database, Events} from '@constants'; import {SYSTEM_IDENTIFIERS} from '@constants/database'; import DatabaseManager from '@database/manager'; @@ -17,6 +17,7 @@ import {getCSRFFromCookie} from '@utils/security'; import {loginEntry} from './entry'; import {logError} from './error'; import {fetchDataRetentionPolicy} from './systems'; +import {autoUpdateTimezone} from './user'; import type ClientError from '@client/rest/error'; import type {LoginArgs} from '@typings/database/database'; diff --git a/app/actions/remote/user.ts b/app/actions/remote/user.ts index 31a2ddb35..56f0feadd 100644 --- a/app/actions/remote/user.ts +++ b/app/actions/remote/user.ts @@ -1,10 +1,13 @@ // Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. // See LICENSE.txt for license information. +/* eslint-disable max-lines */ + import {Model} from '@nozbe/watermelondb'; import {chunk} from 'lodash'; import {updateChannelsDisplayName} from '@actions/local/channel'; +import {getUserTimezone} from '@actions/local/timezone'; import {updateRecentCustomStatuses, updateLocalUser} from '@actions/local/user'; import {fetchRolesIfNeeded} from '@actions/remote/role'; import {General} from '@constants'; @@ -13,7 +16,7 @@ import {debounce} from '@helpers/api/general'; import NetworkManager from '@init/network_manager'; import {queryChannelsByTypes} from '@queries/servers/channel'; import {getCurrentTeamId, getCurrentUserId} from '@queries/servers/system'; -import {getCurrentUser, prepareUsers, queryAllUsers, queryUsersById, queryUsersByUsername} from '@queries/servers/user'; +import {getCurrentUser, getUserById, prepareUsers, queryAllUsers, queryUsersById, queryUsersByUsername} from '@queries/servers/user'; import {removeUserFromList} from '@utils/user'; import {forceLogoutIfNecessary} from './session'; @@ -693,3 +696,25 @@ export const buildProfileImageUrl = (serverUrl: string, userId: string, timestam return client.getProfilePictureUrl(userId, timestamp); }; + +export const autoUpdateTimezone = async (serverUrl: string, {deviceTimezone, userId}: {deviceTimezone: string; userId: string}) => { + const database = DatabaseManager.serverDatabases[serverUrl].database; + if (!database) { + return {error: `No database present for ${serverUrl}`}; + } + + const currentUser = await getUserById(database, userId); + + if (!currentUser) { + return null; + } + + const currentTimezone = getUserTimezone(currentUser); + const newTimezoneExists = currentTimezone.automaticTimezone !== deviceTimezone; + + if (currentTimezone.useAutomaticTimezone && newTimezoneExists) { + const timezone = {useAutomaticTimezone: 'true', automaticTimezone: deviceTimezone, manualTimezone: currentTimezone.manualTimezone}; + await updateMe(serverUrl, {timezone}); + } + return null; +}; diff --git a/app/components/post_list/post/body/content/message_attachments/action_menu/index.tsx b/app/components/post_list/post/body/content/message_attachments/action_menu/index.tsx index 7e395757c..2b1d01f2b 100644 --- a/app/components/post_list/post/body/content/message_attachments/action_menu/index.tsx +++ b/app/components/post_list/post/body/content/message_attachments/action_menu/index.tsx @@ -3,7 +3,7 @@ import React, {useCallback, useState} from 'react'; -import {selectAttachmentMenuAction} from '@actions/local/post'; +import {selectAttachmentMenuAction} from '@actions/remote/post'; import AutocompleteSelector from '@components/autocomplete_selector'; import {useServerUrl} from '@context/server'; diff --git a/app/screens/custom_status/index.tsx b/app/screens/custom_status/index.tsx index ff78cc5f5..93a8e6f91 100644 --- a/app/screens/custom_status/index.tsx +++ b/app/screens/custom_status/index.tsx @@ -22,8 +22,9 @@ import {withServerUrl} from '@context/server'; import {withTheme} from '@context/theme'; import {observeConfig, observeRecentCustomStatus} from '@queries/servers/system'; import {observeCurrentUser} from '@queries/servers/user'; -import {dismissModal, goToScreen, mergeNavigationOptions, showModal} from '@screens/navigation'; +import {dismissModal, goToScreen, showModal} from '@screens/navigation'; import {getCurrentMomentForTimezone, getRoundedTime, isCustomStatusExpirySupported} from '@utils/helpers'; +import {mergeNavigationOptions} from '@utils/navigation'; import {preventDoubleTap} from '@utils/tap'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import { diff --git a/app/screens/custom_status_clear_after/index.tsx b/app/screens/custom_status_clear_after/index.tsx index 954b381ef..7c7b7ff47 100644 --- a/app/screens/custom_status_clear_after/index.tsx +++ b/app/screens/custom_status_clear_after/index.tsx @@ -17,7 +17,8 @@ import { import {CustomStatusDuration} from '@constants/custom_status'; import {observeCurrentUser} from '@queries/servers/user'; -import {dismissModal, mergeNavigationOptions, popTopScreen} from '@screens/navigation'; +import {dismissModal, popTopScreen} from '@screens/navigation'; +import {mergeNavigationOptions} from '@utils/navigation'; import {changeOpacity, makeStyleSheetFromTheme} from '@utils/theme'; import ClearAfterMenuItem from './components/clear_after_menu_item'; diff --git a/app/screens/navigation.ts b/app/screens/navigation.ts index 400157436..1cefcc196 100644 --- a/app/screens/navigation.ts +++ b/app/screens/navigation.ts @@ -14,12 +14,13 @@ import NavigationConstants from '@constants/navigation'; import {getDefaultThemeByAppearance} from '@context/theme'; import EphemeralStore from '@store/ephemeral_store'; import {LaunchProps, LaunchType} from '@typings/launch'; -import {NavButtons} from '@typings/screens/navigation'; +import {appearanceControlledScreens, mergeNavigationOptions} from '@utils/navigation'; import {changeOpacity, setNavigatorStyles} from '@utils/theme'; +import type {NavButtons} from '@typings/screens/navigation'; + const {MattermostManaged} = NativeModules; const isRunningInSplitView = MattermostManaged.isRunningInSplitView; -export const appearanceControlledScreens = [Screens.SERVER, Screens.LOGIN, Screens.FORGOT_PASSWORD, Screens.MFA, Screens.SSO]; const alpha = { from: 0, @@ -592,10 +593,6 @@ export function setButtons(componentId: string, buttons: NavButtons = {leftButto mergeNavigationOptions(componentId, options); } -export function mergeNavigationOptions(componentId: string, options: Options) { - Navigation.mergeOptions(componentId, options); -} - export function showOverlay(name: string, passProps = {}, options = {}) { if (!isScreenRegistered(name)) { return; diff --git a/app/utils/navigation/index.ts b/app/utils/navigation/index.ts new file mode 100644 index 000000000..02f23f780 --- /dev/null +++ b/app/utils/navigation/index.ts @@ -0,0 +1,12 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import {Navigation, Options} from 'react-native-navigation'; + +import {Screens} from '@constants'; + +export const appearanceControlledScreens = [Screens.SERVER, Screens.LOGIN, Screens.FORGOT_PASSWORD, Screens.MFA, Screens.SSO]; + +export function mergeNavigationOptions(componentId: string, options: Options) { + Navigation.mergeOptions(componentId, options); +} diff --git a/app/utils/theme/index.ts b/app/utils/theme/index.ts index 9e68a782c..7768f5a60 100644 --- a/app/utils/theme/index.ts +++ b/app/utils/theme/index.ts @@ -7,8 +7,8 @@ import tinyColor from 'tinycolor2'; import {Preferences} from '@constants'; import {MODAL_SCREENS_WITHOUT_BACK} from '@constants/screens'; -import {appearanceControlledScreens, mergeNavigationOptions} from '@screens/navigation'; import EphemeralStore from '@store/ephemeral_store'; +import {appearanceControlledScreens, mergeNavigationOptions} from '@utils/navigation'; import type {Options} from 'react-native-navigation'; diff --git a/index.ts b/index.ts index 38b266886..e7783fb30 100644 --- a/index.ts +++ b/index.ts @@ -25,7 +25,6 @@ if (__DEV__) { LogBox.ignoreLogs([ '`-[RCTRootView cancelTouches]`', 'scaleY', - 'Require cycle: node_modules/zod/lib/src/index.js', "[react-native-gesture-handler] Seems like you're using an old API with gesture components, check out new Gestures system!", 'new NativeEventEmitter', ]);