From e5253927131c116d1e21d476b7b0dc3a51d646c0 Mon Sep 17 00:00:00 2001 From: Gleidson Daniel Silva Date: Thu, 7 Apr 2022 13:53:07 -0300 Subject: [PATCH] Chore: Move services and methods away from rocketchat folder (#4033) * move services to lib * move methods to lib * fix imports --- app/ee/omnichannel/lib/index.ts | 2 +- .../omnichannel/lib/subscriptions/inquiry.ts | 2 +- app/lib/methods/actions.ts | 2 +- app/lib/{rocketchat => }/methods/callJitsi.ts | 8 ++-- app/lib/methods/canOpenRoom.ts | 2 +- .../methods/enterpriseModules.ts | 10 ++--- .../methods/getCustomEmojis.ts | 14 +++---- .../{rocketchat => }/methods/getPermalinks.ts | 8 ++-- .../methods/getPermissions.ts | 14 +++---- app/lib/{rocketchat => }/methods/getRoles.ts | 14 +++---- app/lib/methods/getRooms.ts | 2 +- .../{rocketchat => }/methods/getSettings.ts | 26 ++++++------- app/lib/methods/getSlashCommands.ts | 2 +- .../methods/getUsersPresence.ts | 14 +++---- app/lib/{rocketchat => }/methods/helpers.ts | 10 ++--- app/lib/methods/loadMessagesForRoom.ts | 2 +- app/lib/methods/loadMissedMessages.ts | 2 +- app/lib/methods/loadNextMessages.ts | 2 +- app/lib/methods/loadSurroundingMessages.ts | 2 +- app/lib/methods/loadThreadMessages.ts | 2 +- app/lib/{rocketchat => }/methods/logout.ts | 20 +++++----- app/lib/methods/readMessages.ts | 2 +- app/lib/{rocketchat => }/methods/search.ts | 6 +-- .../methods/sendFileMessage.ts | 10 ++--- app/lib/methods/sendMessage.ts | 2 +- app/lib/{rocketchat => }/methods/setUser.ts | 8 ++-- app/lib/methods/subscriptions/room.ts | 2 +- app/lib/methods/subscriptions/rooms.ts | 2 +- .../methods/triggerActions.ts | 8 ++-- .../methods/userPreferencesMethods.ts | 4 +- .../{rocketchat/index.ts => rocketchat.ts} | 26 ++++++------- app/lib/{rocketchat => }/services/connect.ts | 38 +++++++++---------- .../services/getServerTimeSync.ts | 0 app/lib/{rocketchat => }/services/restApi.ts | 22 +++++------ app/lib/{rocketchat => }/services/sdk.ts | 8 ++-- .../services/shareExtension.ts | 18 ++++----- app/reducers/permissions.ts | 2 +- app/sagas/login.js | 2 +- app/share.tsx | 2 +- app/utils/localAuthentication.ts | 2 +- app/views/SelectServerView.tsx | 2 +- 41 files changed, 163 insertions(+), 163 deletions(-) rename app/lib/{rocketchat => }/methods/callJitsi.ts (87%) rename app/lib/{rocketchat => }/methods/enterpriseModules.ts (87%) rename app/lib/{rocketchat => }/methods/getCustomEmojis.ts (91%) rename app/lib/{rocketchat => }/methods/getPermalinks.ts (81%) rename app/lib/{rocketchat => }/methods/getPermissions.ts (91%) rename app/lib/{rocketchat => }/methods/getRoles.ts (90%) rename app/lib/{rocketchat => }/methods/getSettings.ts (87%) rename app/lib/{rocketchat => }/methods/getUsersPresence.ts (88%) rename app/lib/{rocketchat => }/methods/helpers.ts (95%) rename app/lib/{rocketchat => }/methods/logout.ts (87%) rename app/lib/{rocketchat => }/methods/search.ts (93%) rename app/lib/{rocketchat => }/methods/sendFileMessage.ts (93%) rename app/lib/{rocketchat => }/methods/setUser.ts (81%) rename app/lib/{rocketchat => }/methods/triggerActions.ts (77%) rename app/lib/{rocketchat => }/methods/userPreferencesMethods.ts (74%) rename app/lib/{rocketchat/index.ts => rocketchat.ts} (70%) rename app/lib/{rocketchat => }/services/connect.ts (93%) rename app/lib/{rocketchat => }/services/getServerTimeSync.ts (100%) rename app/lib/{rocketchat => }/services/restApi.ts (97%) rename app/lib/{rocketchat => }/services/sdk.ts (95%) rename app/lib/{rocketchat => }/services/shareExtension.ts (84%) diff --git a/app/ee/omnichannel/lib/index.ts b/app/ee/omnichannel/lib/index.ts index c7c45dc65..efe6d5083 100644 --- a/app/ee/omnichannel/lib/index.ts +++ b/app/ee/omnichannel/lib/index.ts @@ -1,4 +1,4 @@ -import sdk from '../../../lib/rocketchat/services/sdk'; +import sdk from '../../../lib/services/sdk'; import { IUser } from '../../../definitions'; import EventEmitter from '../../../utils/events'; import subscribeInquiry from './subscriptions/inquiry'; diff --git a/app/ee/omnichannel/lib/subscriptions/inquiry.ts b/app/ee/omnichannel/lib/subscriptions/inquiry.ts index 480677f2e..e9358133e 100644 --- a/app/ee/omnichannel/lib/subscriptions/inquiry.ts +++ b/app/ee/omnichannel/lib/subscriptions/inquiry.ts @@ -2,7 +2,7 @@ import log from '../../../../utils/log'; import { store } from '../../../../lib/store/auxStore'; import RocketChat from '../../../../lib/rocketchat'; import { inquiryQueueAdd, inquiryQueueRemove, inquiryQueueUpdate, inquiryRequest } from '../../actions/inquiry'; -import sdk from '../../../../lib/rocketchat/services/sdk'; +import sdk from '../../../../lib/services/sdk'; import { IOmnichannelRoom } from '../../../../definitions'; interface IArgsQueueOmnichannel extends IOmnichannelRoom { diff --git a/app/lib/methods/actions.ts b/app/lib/methods/actions.ts index da4c55db7..5425f49c8 100644 --- a/app/lib/methods/actions.ts +++ b/app/lib/methods/actions.ts @@ -4,7 +4,7 @@ import EventEmitter from '../../utils/events'; import fetch from '../../utils/fetch'; import random from '../../utils/random'; import Navigation from '../navigation/appNavigation'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; const triggersId = new Map(); diff --git a/app/lib/rocketchat/methods/callJitsi.ts b/app/lib/methods/callJitsi.ts similarity index 87% rename from app/lib/rocketchat/methods/callJitsi.ts rename to app/lib/methods/callJitsi.ts index 1668802f1..fcfd450ed 100644 --- a/app/lib/rocketchat/methods/callJitsi.ts +++ b/app/lib/methods/callJitsi.ts @@ -1,7 +1,7 @@ -import { ISubscription } from '../../../definitions'; -import { events, logEvent } from '../../../utils/log'; -import { store } from '../../store/auxStore'; -import Navigation from '../../navigation/appNavigation'; +import { ISubscription } from '../../definitions'; +import { events, logEvent } from '../../utils/log'; +import { store } from '../store/auxStore'; +import Navigation from '../navigation/appNavigation'; import sdk from '../services/sdk'; async function jitsiURL({ room }: { room: ISubscription }) { diff --git a/app/lib/methods/canOpenRoom.ts b/app/lib/methods/canOpenRoom.ts index 404afa8a2..46c041537 100644 --- a/app/lib/methods/canOpenRoom.ts +++ b/app/lib/methods/canOpenRoom.ts @@ -2,7 +2,7 @@ import { ERoomTypes } from '../../definitions'; import { store } from '../store/auxStore'; import database from '../database'; import RocketChat from '../rocketchat'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; const restTypes = { channel: 'channels', diff --git a/app/lib/rocketchat/methods/enterpriseModules.ts b/app/lib/methods/enterpriseModules.ts similarity index 87% rename from app/lib/rocketchat/methods/enterpriseModules.ts rename to app/lib/methods/enterpriseModules.ts index a38b99f81..e33cd7dcf 100644 --- a/app/lib/rocketchat/methods/enterpriseModules.ts +++ b/app/lib/methods/enterpriseModules.ts @@ -1,9 +1,9 @@ import sdk from '../services/sdk'; -import { store as reduxStore } from '../../store/auxStore'; -import database from '../../database'; -import log from '../../../utils/log'; -import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../../actions/enterpriseModules'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import { store as reduxStore } from '../store/auxStore'; +import database from '../database'; +import log from '../../utils/log'; +import { clearEnterpriseModules, setEnterpriseModules as setEnterpriseModulesAction } from '../../actions/enterpriseModules'; +import { compareServerVersion } from './helpers/compareServerVersion'; const LICENSE_OMNICHANNEL_MOBILE_ENTERPRISE = 'omnichannel-mobile-enterprise'; const LICENSE_LIVECHAT_ENTERPRISE = 'livechat-enterprise'; diff --git a/app/lib/rocketchat/methods/getCustomEmojis.ts b/app/lib/methods/getCustomEmojis.ts similarity index 91% rename from app/lib/rocketchat/methods/getCustomEmojis.ts rename to app/lib/methods/getCustomEmojis.ts index 278693d47..4f664efaa 100644 --- a/app/lib/rocketchat/methods/getCustomEmojis.ts +++ b/app/lib/methods/getCustomEmojis.ts @@ -1,14 +1,14 @@ import orderBy from 'lodash/orderBy'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; -import { ICustomEmojis } from '../../../reducers/customEmojis'; -import { store as reduxStore } from '../../store/auxStore'; -import database from '../../database'; -import log from '../../../utils/log'; -import { setCustomEmojis as setCustomEmojisAction } from '../../../actions/customEmojis'; -import { ICustomEmoji, TCustomEmojiModel } from '../../../definitions'; +import { ICustomEmojis } from '../../reducers/customEmojis'; +import { store as reduxStore } from '../store/auxStore'; +import database from '../database'; +import log from '../../utils/log'; +import { setCustomEmojis as setCustomEmojisAction } from '../../actions/customEmojis'; +import { ICustomEmoji, TCustomEmojiModel } from '../../definitions'; import sdk from '../services/sdk'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import { compareServerVersion } from './helpers/compareServerVersion'; interface IUpdateEmojis { update: TCustomEmojiModel[]; diff --git a/app/lib/rocketchat/methods/getPermalinks.ts b/app/lib/methods/getPermalinks.ts similarity index 81% rename from app/lib/rocketchat/methods/getPermalinks.ts rename to app/lib/methods/getPermalinks.ts index 8e66517c1..29ec4d2bd 100644 --- a/app/lib/rocketchat/methods/getPermalinks.ts +++ b/app/lib/methods/getPermalinks.ts @@ -1,8 +1,8 @@ -import log from '../../../utils/log'; -import { TMessageModel, TSubscriptionModel } from '../../../definitions'; -import { store } from '../../store/auxStore'; -import getRoom from '../../methods/getRoom'; +import log from '../../utils/log'; +import { TMessageModel, TSubscriptionModel } from '../../definitions'; +import { store } from '../store/auxStore'; import { isGroupChat } from './helpers'; +import getRoom from './getRoom'; type TRoomType = 'p' | 'c' | 'd'; diff --git a/app/lib/rocketchat/methods/getPermissions.ts b/app/lib/methods/getPermissions.ts similarity index 91% rename from app/lib/rocketchat/methods/getPermissions.ts rename to app/lib/methods/getPermissions.ts index 36199a5c8..58aeba0da 100644 --- a/app/lib/rocketchat/methods/getPermissions.ts +++ b/app/lib/methods/getPermissions.ts @@ -2,14 +2,14 @@ import { Q } from '@nozbe/watermelondb'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import orderBy from 'lodash/orderBy'; -import { setPermissions as setPermissionsAction } from '../../../actions/permissions'; -import { IPermission, TPermissionModel } from '../../../definitions'; -import log from '../../../utils/log'; -import { store as reduxStore } from '../../store/auxStore'; -import database from '../../database'; +import { setPermissions as setPermissionsAction } from '../../actions/permissions'; +import { IPermission, TPermissionModel } from '../../definitions'; +import log from '../../utils/log'; +import { store as reduxStore } from '../store/auxStore'; +import database from '../database'; import sdk from '../services/sdk'; -import protectedFunction from '../../methods/helpers/protectedFunction'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import protectedFunction from './helpers/protectedFunction'; +import { compareServerVersion } from './helpers/compareServerVersion'; export const SUPPORTED_PERMISSIONS = [ 'add-user-to-any-c-room', diff --git a/app/lib/rocketchat/methods/getRoles.ts b/app/lib/methods/getRoles.ts similarity index 90% rename from app/lib/rocketchat/methods/getRoles.ts rename to app/lib/methods/getRoles.ts index 0382a7bb3..93f7596d2 100644 --- a/app/lib/rocketchat/methods/getRoles.ts +++ b/app/lib/methods/getRoles.ts @@ -1,14 +1,14 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import Model from '@nozbe/watermelondb/Model'; -import database from '../../database'; -import { getRoleById } from '../../database/services/Role'; -import log from '../../../utils/log'; -import { store as reduxStore } from '../../store/auxStore'; -import { removeRoles, setRoles as setRolesAction, updateRoles } from '../../../actions/roles'; -import protectedFunction from '../../methods/helpers/protectedFunction'; -import { TRoleModel } from '../../../definitions'; +import database from '../database'; +import { getRoleById } from '../database/services/Role'; +import log from '../../utils/log'; +import { store as reduxStore } from '../store/auxStore'; +import { removeRoles, setRoles as setRolesAction, updateRoles } from '../../actions/roles'; +import { TRoleModel } from '../../definitions'; import sdk from '../services/sdk'; +import protectedFunction from './helpers/protectedFunction'; export async function setRoles(): Promise { const db = database.active; diff --git a/app/lib/methods/getRooms.ts b/app/lib/methods/getRooms.ts index 8d7f89397..cc7a37d77 100644 --- a/app/lib/methods/getRooms.ts +++ b/app/lib/methods/getRooms.ts @@ -1,4 +1,4 @@ -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; export default function (updatedSince: Date) { // subscriptions.get: Since RC 0.60.0 diff --git a/app/lib/rocketchat/methods/getSettings.ts b/app/lib/methods/getSettings.ts similarity index 87% rename from app/lib/rocketchat/methods/getSettings.ts rename to app/lib/methods/getSettings.ts index f0659c06a..8c53f6faa 100644 --- a/app/lib/rocketchat/methods/getSettings.ts +++ b/app/lib/methods/getSettings.ts @@ -1,16 +1,16 @@ import { Q } from '@nozbe/watermelondb'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; -import { addSettings, clearSettings } from '../../../actions/settings'; -import { DEFAULT_AUTO_LOCK, defaultSettings } from '../../constants'; -import { IPreparedSettings, ISettingsIcon } from '../../../definitions'; -import fetch from '../../../utils/fetch'; -import log from '../../../utils/log'; -import { store as reduxStore } from '../../store/auxStore'; -import database from '../../database'; -import RocketChat from '..'; +import { addSettings, clearSettings } from '../../actions/settings'; +import { DEFAULT_AUTO_LOCK, defaultSettings } from '../constants'; +import { IPreparedSettings, ISettingsIcon } from '../../definitions'; +import fetch from '../../utils/fetch'; +import log from '../../utils/log'; +import { store as reduxStore } from '../store/auxStore'; +import database from '../database'; import sdk from '../services/sdk'; -import protectedFunction from '../../methods/helpers/protectedFunction'; +import { parseSettings, _prepareSettings } from './helpers'; +import protectedFunction from './helpers/protectedFunction'; const serverInfoKeys = [ 'Site_Name', @@ -112,7 +112,7 @@ export async function getLoginSettings({ server }: { server: string }): Promise< if (result.success && result.settings.length) { reduxStore.dispatch(clearSettings()); - reduxStore.dispatch(addSettings(RocketChat.parseSettings(RocketChat._prepareSettings(result.settings)))); + reduxStore.dispatch(addSettings(parseSettings(_prepareSettings(result.settings)))); } } catch (e) { log(e); @@ -131,7 +131,7 @@ export async function setSettings(): Promise { valueAsArray: item.valueAsArray, _updatedAt: item._updatedAt })); - reduxStore.dispatch(addSettings(RocketChat.parseSettings(parsed.slice(0, parsed.length)))); + reduxStore.dispatch(addSettings(parseSettings(parsed.slice(0, parsed.length)))); } export function subscribeSettings(): void { @@ -155,10 +155,10 @@ export async function getSettings(): Promise { return; } const data: IData[] = result.settings || []; - const filteredSettings: IPreparedSettings[] = RocketChat._prepareSettings(data); + const filteredSettings: IPreparedSettings[] = _prepareSettings(data); const filteredSettingsIds = filteredSettings.map(s => s._id); - reduxStore.dispatch(addSettings(RocketChat.parseSettings(filteredSettings))); + reduxStore.dispatch(addSettings(parseSettings(filteredSettings))); // filter server info const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id)); diff --git a/app/lib/methods/getSlashCommands.ts b/app/lib/methods/getSlashCommands.ts index ed9f37783..d2fbe2a7b 100644 --- a/app/lib/methods/getSlashCommands.ts +++ b/app/lib/methods/getSlashCommands.ts @@ -4,7 +4,7 @@ import database from '../database'; import log from '../../utils/log'; import protectedFunction from './helpers/protectedFunction'; import { ISlashCommandResult, TSlashCommandModel } from '../../definitions'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; export default function getSlashCommands() { const db = database.active; diff --git a/app/lib/rocketchat/methods/getUsersPresence.ts b/app/lib/methods/getUsersPresence.ts similarity index 88% rename from app/lib/rocketchat/methods/getUsersPresence.ts rename to app/lib/methods/getUsersPresence.ts index e7c24f663..b8587e43a 100644 --- a/app/lib/rocketchat/methods/getUsersPresence.ts +++ b/app/lib/methods/getUsersPresence.ts @@ -1,14 +1,14 @@ import { InteractionManager } from 'react-native'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; -import { IActiveUsers } from '../../../reducers/activeUsers'; -import { store as reduxStore } from '../../store/auxStore'; -import { setActiveUsers } from '../../../actions/activeUsers'; -import { setUser } from '../../../actions/login'; -import database from '../../database'; -import { IRocketChat, IUser } from '../../../definitions'; +import { IActiveUsers } from '../../reducers/activeUsers'; +import { store as reduxStore } from '../store/auxStore'; +import { setActiveUsers } from '../../actions/activeUsers'; +import { setUser } from '../../actions/login'; +import database from '../database'; +import { IRocketChat, IUser } from '../../definitions'; import sdk from '../services/sdk'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import { compareServerVersion } from './helpers/compareServerVersion'; export function subscribeUsersPresence(this: IRocketChat) { const serverVersion = reduxStore.getState().server.version as string; diff --git a/app/lib/rocketchat/methods/helpers.ts b/app/lib/methods/helpers.ts similarity index 95% rename from app/lib/rocketchat/methods/helpers.ts rename to app/lib/methods/helpers.ts index d62df0062..c4c360234 100644 --- a/app/lib/rocketchat/methods/helpers.ts +++ b/app/lib/methods/helpers.ts @@ -1,11 +1,11 @@ // @ts-nocheck - TEMP import AsyncStorage from '@react-native-community/async-storage'; -import log from '../../../utils/log'; -import { store as reduxStore } from '../../store/auxStore'; -import database from '../../database'; -import subscribeRoomsTmp from '../../methods/subscriptions/rooms'; -import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, defaultSettings } from '../../constants'; +import log from '../../utils/log'; +import { store as reduxStore } from '../store/auxStore'; +import database from '../database'; +import subscribeRoomsTmp from './subscriptions/rooms'; +import { ANALYTICS_EVENTS_KEY, CRASH_REPORT_KEY, defaultSettings } from '../constants'; export function isGroupChat(room): boolean { return ((room.uids && room.uids.length > 2) || (room.usernames && room.usernames.length > 2)) ?? false; diff --git a/app/lib/methods/loadMessagesForRoom.ts b/app/lib/methods/loadMessagesForRoom.ts index 234434b77..87ec9919b 100644 --- a/app/lib/methods/loadMessagesForRoom.ts +++ b/app/lib/methods/loadMessagesForRoom.ts @@ -5,7 +5,7 @@ import { IMessage, TMessageModel } from '../../definitions'; import log from '../../utils/log'; import { getMessageById } from '../database/services/Message'; import roomTypeToApiType, { RoomTypes } from './roomTypeToApiType'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; import updateMessages from './updateMessages'; import { generateLoadMoreId } from './helpers/generateLoadMoreId'; diff --git a/app/lib/methods/loadMissedMessages.ts b/app/lib/methods/loadMissedMessages.ts index 5a114269c..cb5e0712d 100644 --- a/app/lib/methods/loadMissedMessages.ts +++ b/app/lib/methods/loadMissedMessages.ts @@ -1,7 +1,7 @@ import { ILastMessage } from '../../definitions'; import log from '../../utils/log'; import database from '../database'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; import updateMessages from './updateMessages'; const getLastUpdate = async (rid: string) => { diff --git a/app/lib/methods/loadNextMessages.ts b/app/lib/methods/loadNextMessages.ts index a7a729ad3..533059cdb 100644 --- a/app/lib/methods/loadNextMessages.ts +++ b/app/lib/methods/loadNextMessages.ts @@ -7,7 +7,7 @@ import { getMessageById } from '../database/services/Message'; import { MessageTypeLoad } from '../constants'; import updateMessages from './updateMessages'; import { TMessageModel } from '../../definitions'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; import { generateLoadMoreId } from './helpers/generateLoadMoreId'; const COUNT = 50; diff --git a/app/lib/methods/loadSurroundingMessages.ts b/app/lib/methods/loadSurroundingMessages.ts index 81ea1523d..35abf4083 100644 --- a/app/lib/methods/loadSurroundingMessages.ts +++ b/app/lib/methods/loadSurroundingMessages.ts @@ -5,7 +5,7 @@ import orderBy from 'lodash/orderBy'; import log from '../../utils/log'; import { getMessageById } from '../database/services/Message'; import { MessageTypeLoad } from '../constants'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; import { IMessage } from '../../definitions'; import updateMessages from './updateMessages'; import { generateLoadMoreId } from './helpers/generateLoadMoreId'; diff --git a/app/lib/methods/loadThreadMessages.ts b/app/lib/methods/loadThreadMessages.ts index e9390668e..82beeeeac 100644 --- a/app/lib/methods/loadThreadMessages.ts +++ b/app/lib/methods/loadThreadMessages.ts @@ -8,7 +8,7 @@ import { Encryption } from '../encryption'; import protectedFunction from './helpers/protectedFunction'; import buildMessage from './helpers/buildMessage'; import { TThreadMessageModel } from '../../definitions'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; async function load({ tmid }: { tmid: string }) { try { diff --git a/app/lib/rocketchat/methods/logout.ts b/app/lib/methods/logout.ts similarity index 87% rename from app/lib/rocketchat/methods/logout.ts rename to app/lib/methods/logout.ts index d070002a3..eac5b8ac9 100644 --- a/app/lib/rocketchat/methods/logout.ts +++ b/app/lib/methods/logout.ts @@ -2,17 +2,17 @@ import * as FileSystem from 'expo-file-system'; import { Rocketchat as RocketchatClient } from '@rocket.chat/sdk'; import Model from '@nozbe/watermelondb/Model'; -import { getDeviceToken } from '../../../notifications/push'; -import { extractHostname } from '../../../utils/server'; -import { BASIC_AUTH_KEY } from '../../../utils/fetch'; -import database, { getDatabase } from '../../database'; -import RocketChat from '..'; -import { useSsl } from '../../../utils/url'; -import log from '../../../utils/log'; -import UserPreferences from '../../methods/userPreferences'; -import { ICertificate, IRocketChat } from '../../../definitions'; +import { getDeviceToken } from '../../notifications/push'; +import { extractHostname } from '../../utils/server'; +import { BASIC_AUTH_KEY } from '../../utils/fetch'; +import database, { getDatabase } from '../database'; +import { useSsl } from '../../utils/url'; +import log from '../../utils/log'; +import { ICertificate, IRocketChat } from '../../definitions'; import sdk from '../services/sdk'; -import { E2E_PRIVATE_KEY, E2E_PUBLIC_KEY, E2E_RANDOM_PASSWORD_KEY } from '../../constants'; +import { E2E_PRIVATE_KEY, E2E_PUBLIC_KEY, E2E_RANDOM_PASSWORD_KEY } from '../constants'; +import UserPreferences from './userPreferences'; +import RocketChat from '../rocketchat'; function removeServerKeys({ server, userId }: { server: string; userId?: string | null }) { UserPreferences.removeItem(`${RocketChat.TOKEN_KEY}-${server}`); diff --git a/app/lib/methods/readMessages.ts b/app/lib/methods/readMessages.ts index 339000a3a..27f4808bb 100644 --- a/app/lib/methods/readMessages.ts +++ b/app/lib/methods/readMessages.ts @@ -1,7 +1,7 @@ import database from '../database'; import log from '../../utils/log'; import { TSubscriptionModel } from '../../definitions'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; export default async function readMessages(rid: string, ls: Date, updateLastOpen = false): Promise { try { diff --git a/app/lib/rocketchat/methods/search.ts b/app/lib/methods/search.ts similarity index 93% rename from app/lib/rocketchat/methods/search.ts rename to app/lib/methods/search.ts index f094077dd..d8f0f7d1a 100644 --- a/app/lib/rocketchat/methods/search.ts +++ b/app/lib/methods/search.ts @@ -1,9 +1,9 @@ import { Q } from '@nozbe/watermelondb'; -import { sanitizeLikeString } from '../../database/utils'; -import database from '../../database/index'; +import { sanitizeLikeString } from '../database/utils'; +import database from '../database/index'; import { spotlight } from '../services/restApi'; -import { ISearch, ISearchLocal, SubscriptionType } from '../../../definitions'; +import { ISearch, ISearchLocal, SubscriptionType } from '../../definitions'; import { isGroupChat } from './helpers'; let debounce: null | ((reason: string) => void) = null; diff --git a/app/lib/rocketchat/methods/sendFileMessage.ts b/app/lib/methods/sendFileMessage.ts similarity index 93% rename from app/lib/rocketchat/methods/sendFileMessage.ts rename to app/lib/methods/sendFileMessage.ts index 2d5a012e2..e282f5555 100644 --- a/app/lib/rocketchat/methods/sendFileMessage.ts +++ b/app/lib/methods/sendFileMessage.ts @@ -3,11 +3,11 @@ import { settings as RocketChatSettings } from '@rocket.chat/sdk'; import { FetchBlobResponse, StatefulPromise } from 'rn-fetch-blob'; import isEmpty from 'lodash/isEmpty'; -import FileUpload from '../../../utils/fileUpload'; -import database from '../../database'; -import log from '../../../utils/log'; -import { IUpload, IUser, TUploadModel } from '../../../definitions'; -import { IFileUpload } from '../../../utils/fileUpload/interfaces'; +import FileUpload from '../../utils/fileUpload'; +import database from '../database'; +import log from '../../utils/log'; +import { IUpload, IUser, TUploadModel } from '../../definitions'; +import { IFileUpload } from '../../utils/fileUpload/interfaces'; const uploadQueue: { [index: string]: StatefulPromise } = {}; diff --git a/app/lib/methods/sendMessage.ts b/app/lib/methods/sendMessage.ts index 95a3537d0..06738a470 100644 --- a/app/lib/methods/sendMessage.ts +++ b/app/lib/methods/sendMessage.ts @@ -6,7 +6,7 @@ import log from '../../utils/log'; import random from '../../utils/random'; import { Encryption } from '../encryption'; import { E2EType, IMessage, IUser, TMessageModel } from '../../definitions'; -import sdk from '../rocketchat/services/sdk'; +import sdk from '../services/sdk'; import { E2E_MESSAGE_TYPE, E2E_STATUS, messagesStatus } from '../constants'; const changeMessageStatus = async (id: string, status: number, tmid?: string, message?: IMessage) => { diff --git a/app/lib/rocketchat/methods/setUser.ts b/app/lib/methods/setUser.ts similarity index 81% rename from app/lib/rocketchat/methods/setUser.ts rename to app/lib/methods/setUser.ts index 6cc31e5de..5d7f16752 100644 --- a/app/lib/rocketchat/methods/setUser.ts +++ b/app/lib/methods/setUser.ts @@ -1,9 +1,9 @@ import { InteractionManager } from 'react-native'; -import { setActiveUsers } from '../../../actions/activeUsers'; -import { setUser } from '../../../actions/login'; -import { store as reduxStore } from '../../store/auxStore'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import { setActiveUsers } from '../../actions/activeUsers'; +import { setUser } from '../../actions/login'; +import { store as reduxStore } from '../store/auxStore'; +import { compareServerVersion } from './helpers/compareServerVersion'; // TODO export function _setUser(this: any, ddpMessage: { fields: any; id: any; cleared: any }) { diff --git a/app/lib/methods/subscriptions/room.ts b/app/lib/methods/subscriptions/room.ts index 296180686..8685fc3aa 100644 --- a/app/lib/methods/subscriptions/room.ts +++ b/app/lib/methods/subscriptions/room.ts @@ -17,7 +17,7 @@ import { subscribeRoom, unsubscribeRoom } from '../../../actions/room'; import { Encryption } from '../../encryption'; import { IMessage, TMessageModel, TSubscriptionModel, TThreadMessageModel, TThreadModel } from '../../../definitions'; import { IDDPMessage } from '../../../definitions/IDDPMessage'; -import sdk from '../../rocketchat/services/sdk'; +import sdk from '../../services/sdk'; const WINDOW_TIME = 1000; diff --git a/app/lib/methods/subscriptions/rooms.ts b/app/lib/methods/subscriptions/rooms.ts index e03ec4805..17ab329fe 100644 --- a/app/lib/methods/subscriptions/rooms.ts +++ b/app/lib/methods/subscriptions/rooms.ts @@ -28,7 +28,7 @@ import { TThreadMessageModel, TThreadModel } from '../../../definitions'; -import sdk from '../../rocketchat/services/sdk'; +import sdk from '../../services/sdk'; import { IDDPMessage } from '../../../definitions/IDDPMessage'; import { getSubscriptionByRoomId } from '../../database/services/Subscription'; import { getMessageById } from '../../database/services/Message'; diff --git a/app/lib/rocketchat/methods/triggerActions.ts b/app/lib/methods/triggerActions.ts similarity index 77% rename from app/lib/rocketchat/methods/triggerActions.ts rename to app/lib/methods/triggerActions.ts index 65a14528e..8815ac6db 100644 --- a/app/lib/rocketchat/methods/triggerActions.ts +++ b/app/lib/methods/triggerActions.ts @@ -4,10 +4,10 @@ import { ITriggerCancel, ITriggerSubmitView, ModalActions -} from '../../../containers/UIKit/interfaces'; -import { TRocketChat } from '../../../definitions'; -import { triggerAction } from '../../methods/actions'; -import Navigation from '../../navigation/appNavigation'; +} from '../../containers/UIKit/interfaces'; +import { TRocketChat } from '../../definitions'; +import Navigation from '../navigation/appNavigation'; +import { triggerAction } from './actions'; export function triggerBlockAction(this: TRocketChat, options: ITriggerBlockAction) { return triggerAction.call(this, { type: ActionTypes.ACTION, ...options }); diff --git a/app/lib/rocketchat/methods/userPreferencesMethods.ts b/app/lib/methods/userPreferencesMethods.ts similarity index 74% rename from app/lib/rocketchat/methods/userPreferencesMethods.ts rename to app/lib/methods/userPreferencesMethods.ts index 7ab5db523..a4a625d29 100644 --- a/app/lib/rocketchat/methods/userPreferencesMethods.ts +++ b/app/lib/methods/userPreferencesMethods.ts @@ -1,5 +1,5 @@ -import { IPreferences } from '../../../definitions'; -import userPreferences from '../../methods/userPreferences'; +import { IPreferences } from '../../definitions'; +import userPreferences from './userPreferences'; const SORT_PREFS_KEY = 'RC_SORT_PREFS_KEY'; diff --git a/app/lib/rocketchat/index.ts b/app/lib/rocketchat.ts similarity index 70% rename from app/lib/rocketchat/index.ts rename to app/lib/rocketchat.ts index 43695952e..15daa9663 100644 --- a/app/lib/rocketchat/index.ts +++ b/app/lib/rocketchat.ts @@ -1,18 +1,18 @@ // Methods -import canOpenRoom from '../methods/canOpenRoom'; -import clearCache from '../methods/clearCache'; -import getRoom from '../methods/getRoom'; -import getRooms from '../methods/getRooms'; -import getSlashCommands from '../methods/getSlashCommands'; -import loadMessagesForRoom from '../methods/loadMessagesForRoom'; -import loadMissedMessages from '../methods/loadMissedMessages'; -import loadNextMessages from '../methods/loadNextMessages'; -import loadSurroundingMessages from '../methods/loadSurroundingMessages'; -import loadThreadMessages from '../methods/loadThreadMessages'; -import readMessages from '../methods/readMessages'; -import roomTypeToApiType from '../methods/roomTypeToApiType'; +import canOpenRoom from './methods/canOpenRoom'; +import clearCache from './methods/clearCache'; +import getRoom from './methods/getRoom'; +import getRooms from './methods/getRooms'; +import getSlashCommands from './methods/getSlashCommands'; +import loadMessagesForRoom from './methods/loadMessagesForRoom'; +import loadMissedMessages from './methods/loadMissedMessages'; +import loadNextMessages from './methods/loadNextMessages'; +import loadSurroundingMessages from './methods/loadSurroundingMessages'; +import loadThreadMessages from './methods/loadThreadMessages'; +import readMessages from './methods/readMessages'; +import roomTypeToApiType from './methods/roomTypeToApiType'; // Spread Methods -import * as sendMessage from '../methods/sendMessage'; +import * as sendMessage from './methods/sendMessage'; import * as callJitsi from './methods/callJitsi'; import * as enterpriseModules from './methods/enterpriseModules'; import * as getCustomEmojis from './methods/getCustomEmojis'; diff --git a/app/lib/rocketchat/services/connect.ts b/app/lib/services/connect.ts similarity index 93% rename from app/lib/rocketchat/services/connect.ts rename to app/lib/services/connect.ts index ad9e00f9a..6575a5bcd 100644 --- a/app/lib/rocketchat/services/connect.ts +++ b/app/lib/services/connect.ts @@ -4,26 +4,26 @@ import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { InteractionManager } from 'react-native'; import { Q } from '@nozbe/watermelondb'; -import log from '../../../utils/log'; -import { onRolesChanged } from '../methods/getRoles'; -import { setActiveUsers } from '../../../actions/activeUsers'; -import protectedFunction from '../../methods/helpers/protectedFunction'; -import database from '../../database'; -import { selectServerFailure } from '../../../actions/server'; -import { twoFactor } from '../../../utils/twoFactor'; -import { store } from '../../store/auxStore'; -import { loginRequest, setLoginServices, setUser } from '../../../actions/login'; +import log from '../../utils/log'; +import { setActiveUsers } from '../../actions/activeUsers'; +import protectedFunction from '../methods/helpers/protectedFunction'; +import database from '../database'; +import { selectServerFailure } from '../../actions/server'; +import { twoFactor } from '../../utils/twoFactor'; +import { store } from '../store/auxStore'; +import { loginRequest, setLoginServices, setUser } from '../../actions/login'; import sdk from './sdk'; -import I18n from '../../../i18n'; -import RocketChat from '..'; -import { ICredentials, ILoggedUser, IRocketChat, STATUSES } from '../../../definitions'; -import { isIOS } from '../../../utils/deviceInfo'; -import { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../../actions/connect'; -import { updatePermission } from '../../../actions/permissions'; -import EventEmitter from '../../../utils/events'; -import { updateSettings } from '../../../actions/settings'; -import { defaultSettings, MIN_ROCKETCHAT_VERSION } from '../../constants'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import I18n from '../../i18n'; +import RocketChat from '../rocketchat'; +import { ICredentials, ILoggedUser, IRocketChat, STATUSES } from '../../definitions'; +import { isIOS } from '../../utils/deviceInfo'; +import { connectRequest, connectSuccess, disconnect as disconnectAction } from '../../actions/connect'; +import { updatePermission } from '../../actions/permissions'; +import EventEmitter from '../../utils/events'; +import { updateSettings } from '../../actions/settings'; +import { defaultSettings, MIN_ROCKETCHAT_VERSION } from '../constants'; +import { compareServerVersion } from '../methods/helpers/compareServerVersion'; +import { onRolesChanged } from '../methods/getRoles'; interface IServices { [index: string]: string | boolean; diff --git a/app/lib/rocketchat/services/getServerTimeSync.ts b/app/lib/services/getServerTimeSync.ts similarity index 100% rename from app/lib/rocketchat/services/getServerTimeSync.ts rename to app/lib/services/getServerTimeSync.ts diff --git a/app/lib/rocketchat/services/restApi.ts b/app/lib/services/restApi.ts similarity index 97% rename from app/lib/rocketchat/services/restApi.ts rename to app/lib/services/restApi.ts index f82aad305..5f48b459a 100644 --- a/app/lib/rocketchat/services/restApi.ts +++ b/app/lib/services/restApi.ts @@ -7,18 +7,18 @@ import { SubscriptionType, IUser, TRocketChat -} from '../../../definitions'; -import { IAvatarSuggestion, IParams } from '../../../definitions/IProfileViewInterfaces'; -import { ISpotlight } from '../../../definitions/ISpotlight'; -import { TEAM_TYPE } from '../../../definitions/ITeam'; -import { Encryption } from '../../encryption'; -import { TParams } from '../../../definitions/ILivechatEditView'; -import { store as reduxStore } from '../../store/auxStore'; -import { getDeviceToken } from '../../../notifications/push'; -import { getBundleId, isIOS } from '../../../utils/deviceInfo'; -import roomTypeToApiType, { RoomTypes } from '../../methods/roomTypeToApiType'; +} from '../../definitions'; +import { IAvatarSuggestion, IParams } from '../../definitions/IProfileViewInterfaces'; +import { ISpotlight } from '../../definitions/ISpotlight'; +import { TEAM_TYPE } from '../../definitions/ITeam'; +import { Encryption } from '../encryption'; +import { TParams } from '../../definitions/ILivechatEditView'; +import { store as reduxStore } from '../store/auxStore'; +import { getDeviceToken } from '../../notifications/push'; +import { getBundleId, isIOS } from '../../utils/deviceInfo'; +import roomTypeToApiType, { RoomTypes } from '../methods/roomTypeToApiType'; import sdk from './sdk'; -import { compareServerVersion } from '../../methods/helpers/compareServerVersion'; +import { compareServerVersion } from '../methods/helpers/compareServerVersion'; export const createChannel = ({ name, diff --git a/app/lib/rocketchat/services/sdk.ts b/app/lib/services/sdk.ts similarity index 95% rename from app/lib/rocketchat/services/sdk.ts rename to app/lib/services/sdk.ts index fa8ec7de0..eb2c56b25 100644 --- a/app/lib/rocketchat/services/sdk.ts +++ b/app/lib/services/sdk.ts @@ -2,10 +2,10 @@ import { Rocketchat } from '@rocket.chat/sdk'; import EJSON from 'ejson'; import isEmpty from 'lodash/isEmpty'; -import { twoFactor } from '../../../utils/twoFactor'; -import { useSsl } from '../../../utils/url'; -import { store as reduxStore } from '../../store/auxStore'; -import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../../definitions/rest/helpers'; +import { twoFactor } from '../../utils/twoFactor'; +import { useSsl } from '../../utils/url'; +import { store as reduxStore } from '../store/auxStore'; +import { Serialized, MatchPathPattern, OperationParams, PathFor, ResultFor } from '../../definitions/rest/helpers'; class Sdk { private sdk: typeof Rocketchat; diff --git a/app/lib/rocketchat/services/shareExtension.ts b/app/lib/services/shareExtension.ts similarity index 84% rename from app/lib/rocketchat/services/shareExtension.ts rename to app/lib/services/shareExtension.ts index 4a35c0629..4970ab105 100644 --- a/app/lib/rocketchat/services/shareExtension.ts +++ b/app/lib/services/shareExtension.ts @@ -1,14 +1,14 @@ import { Q } from '@nozbe/watermelondb'; -import { shareSetSettings, shareSelectServer, shareSetUser } from '../../../actions/share'; -import SSLPinning from '../../../utils/sslPinning'; -import log from '../../../utils/log'; -import { IShareServer, IShareUser } from '../../../reducers/share'; -import UserPreferences from '../../methods/userPreferences'; -import database from '../../database'; -import RocketChat from '..'; -import { encryptionInit } from '../../../actions/encryption'; -import { store } from '../../store/auxStore'; +import { shareSetSettings, shareSelectServer, shareSetUser } from '../../actions/share'; +import SSLPinning from '../../utils/sslPinning'; +import log from '../../utils/log'; +import { IShareServer, IShareUser } from '../../reducers/share'; +import UserPreferences from '../methods/userPreferences'; +import database from '../database'; +import RocketChat from '../rocketchat'; +import { encryptionInit } from '../../actions/encryption'; +import { store } from '../store/auxStore'; import sdk from './sdk'; export async function shareExtensionInit(server: string) { diff --git a/app/reducers/permissions.ts b/app/reducers/permissions.ts index be97f7936..d2887a555 100644 --- a/app/reducers/permissions.ts +++ b/app/reducers/permissions.ts @@ -1,6 +1,6 @@ import { PERMISSIONS } from '../actions/actionsTypes'; import { TActionPermissions } from '../actions/permissions'; -import { SUPPORTED_PERMISSIONS } from '../lib/rocketchat/methods/getPermissions'; +import { SUPPORTED_PERMISSIONS } from '../lib/methods/getPermissions'; export type TSupportedPermissions = typeof SUPPORTED_PERMISSIONS[number]; diff --git a/app/sagas/login.js b/app/sagas/login.js index fa1c05515..d7cb94c54 100644 --- a/app/sagas/login.js +++ b/app/sagas/login.js @@ -20,7 +20,7 @@ import UserPreferences from '../lib/methods/userPreferences'; import { inquiryRequest, inquiryReset } from '../ee/omnichannel/actions/inquiry'; import { isOmnichannelStatusAvailable } from '../ee/omnichannel/lib'; import { RootEnum } from '../definitions'; -import sdk from '../lib/rocketchat/services/sdk'; +import sdk from '../lib/services/sdk'; const getServer = state => state.server.server; const loginWithPasswordCall = args => RocketChat.loginWithPassword(args); diff --git a/app/share.tsx b/app/share.tsx index fff29dea2..53988c7eb 100644 --- a/app/share.tsx +++ b/app/share.tsx @@ -10,7 +10,7 @@ import UserPreferences from './lib/methods/userPreferences'; import Navigation from './lib/navigation/shareNavigation'; import store from './lib/store'; import { initStore } from './lib/store/auxStore'; -import { closeShareExtension, shareExtensionInit } from './lib/rocketchat/services/shareExtension'; +import { closeShareExtension, shareExtensionInit } from './lib/services/shareExtension'; import { defaultHeader, getActiveRouteName, navigationTheme, themedHeader } from './utils/navigation'; import RocketChat from './lib/rocketchat'; import { ThemeContext, TSupportedThemes } from './theme'; diff --git a/app/utils/localAuthentication.ts b/app/utils/localAuthentication.ts index 343878f1f..f094eee8c 100644 --- a/app/utils/localAuthentication.ts +++ b/app/utils/localAuthentication.ts @@ -7,7 +7,7 @@ import moment from 'moment'; import UserPreferences from '../lib/methods/userPreferences'; import { store } from '../lib/store/auxStore'; import database from '../lib/database'; -import { getServerTimeSync } from '../lib/rocketchat/services/getServerTimeSync'; +import { getServerTimeSync } from '../lib/services/getServerTimeSync'; import { ATTEMPTS_KEY, BIOMETRY_ENABLED_KEY, diff --git a/app/views/SelectServerView.tsx b/app/views/SelectServerView.tsx index fcc4307ed..e94170c1f 100644 --- a/app/views/SelectServerView.tsx +++ b/app/views/SelectServerView.tsx @@ -7,7 +7,7 @@ import { Q, Model } from '@nozbe/watermelondb'; import I18n from '../i18n'; import StatusBar from '../containers/StatusBar'; import ServerItem, { ROW_HEIGHT } from '../presentation/ServerItem'; -import { shareExtensionInit } from '../lib/rocketchat/services/shareExtension'; +import { shareExtensionInit } from '../lib/services/shareExtension'; import database from '../lib/database'; import SafeAreaView from '../containers/SafeAreaView'; import * as List from '../containers/List';