From ee0eb7723a9e24d16d5cbd395a9740ebbcb1a2f6 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 01:15:20 -0300 Subject: [PATCH 01/51] Chore: Migrate Model's folder to Typescript --- app/definitions/ICustomEmoji.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/definitions/ICustomEmoji.ts diff --git a/app/definitions/ICustomEmoji.ts b/app/definitions/ICustomEmoji.ts new file mode 100644 index 00000000000..03da85b3ff8 --- /dev/null +++ b/app/definitions/ICustomEmoji.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface ICustomEmoji { + name: string; + aliases: string; + extension: string; + _updatedAt: Date; +} + +export type TCustomEmojiModel = ICustomEmoji & Model; From b46f1e83b995353be67a499524166161a54c38b4 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 01:23:53 -0300 Subject: [PATCH 02/51] minor tweak --- app/definitions/ICustomEmoji.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/definitions/ICustomEmoji.ts b/app/definitions/ICustomEmoji.ts index 03da85b3ff8..6a6c131a73f 100644 --- a/app/definitions/ICustomEmoji.ts +++ b/app/definitions/ICustomEmoji.ts @@ -1,8 +1,8 @@ import Model from '@nozbe/watermelondb/Model'; export interface ICustomEmoji { - name: string; - aliases: string; + name?: string; + aliases?: string; extension: string; _updatedAt: Date; } From 196b2a52dec05a1f5ccfb8c117fb4e902cacddb9 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 01:25:40 -0300 Subject: [PATCH 03/51] IFrequentlyUsedEmoji --- app/definitions/IFrequentlyUsedEmoji.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/definitions/IFrequentlyUsedEmoji.ts diff --git a/app/definitions/IFrequentlyUsedEmoji.ts b/app/definitions/IFrequentlyUsedEmoji.ts new file mode 100644 index 00000000000..a659e2abdc5 --- /dev/null +++ b/app/definitions/IFrequentlyUsedEmoji.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IFrequentlyUsedEmoji { + content?: string; + extension?: string; + isCustom: boolean; + count: number; +} + +export type TFrequentlyUsedEmoji = IFrequentlyUsedEmoji & Model; From 6e2f18f6166591ff7c7aba8fd6d2e0415e3e562b Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 01:54:11 -0300 Subject: [PATCH 04/51] refactor IAttachments --- app/containers/message/Reply.tsx | 28 ++++++---------------------- app/containers/message/Video.tsx | 10 ++-------- app/definitions/IAttachment.ts | 15 +++++++++++++++ 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/app/containers/message/Reply.tsx b/app/containers/message/Reply.tsx index fbc8984fcb9..8d81260509a 100644 --- a/app/containers/message/Reply.tsx +++ b/app/containers/message/Reply.tsx @@ -13,6 +13,7 @@ import { themes } from '../../constants/colors'; import MessageContext from './Context'; import { fileDownloadAndPreview } from '../../utils/fileDownload'; import { formatAttachmentUrl } from '../../lib/utils'; +import { IAttachment } from '../../definitions/IAttachment'; import RCActivityIndicator from '../ActivityIndicator'; const styles = StyleSheet.create({ @@ -90,43 +91,26 @@ const styles = StyleSheet.create({ } }); -interface IMessageReplyAttachment { - author_name: string; - message_link: string; - ts: string; - text: string; - title: string; - short: boolean; - value: string; - title_link: string; - author_link: string; - type: string; - color: string; - description: string; - fields: IMessageReplyAttachment[]; - thumb_url: string; -} - interface IMessageTitle { - attachment: Partial; + attachment: IAttachment; timeFormat: string; theme: string; } interface IMessageDescription { - attachment: Partial; + attachment: IAttachment; getCustomEmoji: Function; theme: string; } interface IMessageFields { - attachment: Partial; + attachment: IAttachment; theme: string; getCustomEmoji: Function; } interface IMessageReply { - attachment: IMessageReplyAttachment; + attachment: IAttachment; timeFormat: string; index: number; theme: string; @@ -198,7 +182,7 @@ const Fields = React.memo( {field.title} {/* @ts-ignore*/} Date: Tue, 21 Dec 2021 02:01:17 -0300 Subject: [PATCH 05/51] IReactions --- app/definitions/IReactions.ts | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/definitions/IReactions.ts diff --git a/app/definitions/IReactions.ts b/app/definitions/IReactions.ts new file mode 100644 index 00000000000..a28f5d06e7c --- /dev/null +++ b/app/definitions/IReactions.ts @@ -0,0 +1,5 @@ +export interface IReaction { + _id: string; + emoji: string; + usernames: string[]; +} From f43116332ffdab758495b99a820aa89622908d99 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 02:16:44 -0300 Subject: [PATCH 06/51] IMessage created, missing mix with Markdown --- app/definitions/IMessage.ts | 65 +++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index aca651c1018..7e68b31c370 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -1,3 +1,68 @@ +import { MarkdownAST } from '@rocket.chat/message-parser'; + +import { IAttachment } from './IAttachment'; +import { IReaction } from './IReactions'; +import { RoomType } from './IRoom'; + +interface IUserMessage { + _id: string; + username?: string; + name?: string; +} + +export interface IUserMention extends IUserMessage { + type: string; +} + +export interface IUserChannel { + [index: number]: string | number; + name: string; + _id: string; +} + +export type TOnLinkPress = (link: string) => void; + +export interface ITranslations { + _id: string; + language: string; + value: string; +} + export interface IMessage { msg: string; + t?: RoomType; + ts: Date; + u: IUserMessage; + subscription: { id: string }; + alias: string; + parseUrls: boolean; + groupable: boolean; + avatar: string; + emoji: string; + attachments: IAttachment[]; + urls: string[]; + _updatedAt: Date; + status: number; + pinned: boolean; + starred: boolean; + editedBy?: { _id: string; username: string }; + reactions: IReaction[]; + role: string; + drid: string; + dcount: number; + dlm: Date; + tmid: string; + tcount: number; + tlm: Date; + replies: string[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + unread: boolean; + autoTranslate: boolean; + translations: ITranslations[]; + tmsg: string; + blocks: any; + e2e: string; + tshow: boolean; + md: MarkdownAST; } From d613be105a051b3e11759003bdd1e13569a376bc Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:19:29 -0300 Subject: [PATCH 07/51] Chore: Migrate CustomEmoji to Typescript --- app/definitions/ICustomEmoji.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/definitions/ICustomEmoji.ts diff --git a/app/definitions/ICustomEmoji.ts b/app/definitions/ICustomEmoji.ts new file mode 100644 index 00000000000..6a6c131a73f --- /dev/null +++ b/app/definitions/ICustomEmoji.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface ICustomEmoji { + name?: string; + aliases?: string; + extension: string; + _updatedAt: Date; +} + +export type TCustomEmojiModel = ICustomEmoji & Model; From 80faa1860fe42bcee5800a0a115a0af8afcc03a0 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:23:07 -0300 Subject: [PATCH 08/51] Chore: Migrate FrequentlyUsedEmoji to Typescript --- app/definitions/IFrequentlyUsedEmoji.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/definitions/IFrequentlyUsedEmoji.ts diff --git a/app/definitions/IFrequentlyUsedEmoji.ts b/app/definitions/IFrequentlyUsedEmoji.ts new file mode 100644 index 00000000000..a659e2abdc5 --- /dev/null +++ b/app/definitions/IFrequentlyUsedEmoji.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IFrequentlyUsedEmoji { + content?: string; + extension?: string; + isCustom: boolean; + count: number; +} + +export type TFrequentlyUsedEmoji = IFrequentlyUsedEmoji & Model; From 51d95e1587d6b671cbb16b0dbd52ef85c7987870 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:31:27 -0300 Subject: [PATCH 09/51] Chore: Migrate Message definition to Typescript --- app/containers/message/Reply.tsx | 28 +++---------- app/containers/message/Video.tsx | 10 +---- app/definitions/IAttachment.ts | 15 +++++++ app/definitions/IMessage.ts | 68 ++++++++++++++++++++++++++++++++ app/definitions/IReactions.ts | 5 +++ 5 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 app/definitions/IReactions.ts diff --git a/app/containers/message/Reply.tsx b/app/containers/message/Reply.tsx index fbc8984fcb9..8d81260509a 100644 --- a/app/containers/message/Reply.tsx +++ b/app/containers/message/Reply.tsx @@ -13,6 +13,7 @@ import { themes } from '../../constants/colors'; import MessageContext from './Context'; import { fileDownloadAndPreview } from '../../utils/fileDownload'; import { formatAttachmentUrl } from '../../lib/utils'; +import { IAttachment } from '../../definitions/IAttachment'; import RCActivityIndicator from '../ActivityIndicator'; const styles = StyleSheet.create({ @@ -90,43 +91,26 @@ const styles = StyleSheet.create({ } }); -interface IMessageReplyAttachment { - author_name: string; - message_link: string; - ts: string; - text: string; - title: string; - short: boolean; - value: string; - title_link: string; - author_link: string; - type: string; - color: string; - description: string; - fields: IMessageReplyAttachment[]; - thumb_url: string; -} - interface IMessageTitle { - attachment: Partial; + attachment: IAttachment; timeFormat: string; theme: string; } interface IMessageDescription { - attachment: Partial; + attachment: IAttachment; getCustomEmoji: Function; theme: string; } interface IMessageFields { - attachment: Partial; + attachment: IAttachment; theme: string; getCustomEmoji: Function; } interface IMessageReply { - attachment: IMessageReplyAttachment; + attachment: IAttachment; timeFormat: string; index: number; theme: string; @@ -198,7 +182,7 @@ const Fields = React.memo( {field.title} {/* @ts-ignore*/} void; + +export interface ITranslations { + _id: string; + language: string; + value: string; +} + export interface IMessage { msg: string; + t?: RoomType; + ts: Date; + u: IUserMessage; + subscription: { id: string }; + alias: string; + parseUrls: boolean; + groupable: boolean; + avatar: string; + emoji: string; + attachments: IAttachment[]; + urls: string[]; + _updatedAt: Date; + status: number; + pinned: boolean; + starred: boolean; + editedBy?: { _id: string; username: string }; + reactions: IReaction[]; + role: string; + drid: string; + dcount: number; + dlm: Date; + tmid: string; + tcount: number; + tlm: Date; + replies: string[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + unread: boolean; + autoTranslate: boolean; + translations: ITranslations[]; + tmsg: string; + blocks: any; + e2e: string; + tshow: boolean; + md: MarkdownAST; } + +export type TMessageModel = IMessage & Model; diff --git a/app/definitions/IReactions.ts b/app/definitions/IReactions.ts new file mode 100644 index 00000000000..a28f5d06e7c --- /dev/null +++ b/app/definitions/IReactions.ts @@ -0,0 +1,5 @@ +export interface IReaction { + _id: string; + emoji: string; + usernames: string[]; +} From 3c1d4f701dc4a3d55c5fe5257bd60dbffec0e5cc Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:49:23 -0300 Subject: [PATCH 10/51] Chore: Migrate Permission definition to Typescript --- app/definitions/IPermission.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/definitions/IPermission.ts diff --git a/app/definitions/IPermission.ts b/app/definitions/IPermission.ts new file mode 100644 index 00000000000..14e1a500c9b --- /dev/null +++ b/app/definitions/IPermission.ts @@ -0,0 +1,8 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IPermission { + roles: string[]; + _updatedAt: Date; +} + +export type TPermissionModel = IPermission & Model; From 1068d119647259e020050d6a478b62a0b18a81bd Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:54:41 -0300 Subject: [PATCH 11/51] Chore: Migrate Role definition to Typescript --- app/definitions/IRole.ts | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/definitions/IRole.ts diff --git a/app/definitions/IRole.ts b/app/definitions/IRole.ts new file mode 100644 index 00000000000..82dbef3bb8b --- /dev/null +++ b/app/definitions/IRole.ts @@ -0,0 +1,8 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IRole { + id: string; + description: string; +} + +export type TRoleModel = IRole & Model; From 9168159044b5f8d09304639765c0c9ad737e11de Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 15:56:27 -0300 Subject: [PATCH 12/51] minor tweak --- app/definitions/IPermission.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/app/definitions/IPermission.ts b/app/definitions/IPermission.ts index 14e1a500c9b..0ccc134652f 100644 --- a/app/definitions/IPermission.ts +++ b/app/definitions/IPermission.ts @@ -1,6 +1,7 @@ import Model from '@nozbe/watermelondb/Model'; export interface IPermission { + id: string; roles: string[]; _updatedAt: Date; } From 027104a90f8bc9c23d938e8c5c311eef66c6cb28 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 23:04:12 -0300 Subject: [PATCH 13/51] Chore: Migrate Room and Subscription model to Typescript --- app/definitions/IRocketChatRecord.ts | 4 --- app/definitions/IRoom.ts | 39 +++++++++----------------- app/definitions/IServedBy.ts | 5 ++++ app/definitions/ISubscription.ts | 27 ++++++++++++++++++ app/navigationTypes.ts | 4 +-- app/stacks/MasterDetailStack/types.ts | 34 +++++++++++----------- app/stacks/types.ts | 32 ++++++++++----------- app/views/AutoTranslateView/index.tsx | 4 +-- app/views/MessagesView/index.tsx | 14 ++++----- app/views/SearchMessagesView/index.tsx | 6 ++-- app/views/ShareView/index.tsx | 4 +-- 11 files changed, 95 insertions(+), 78 deletions(-) delete mode 100644 app/definitions/IRocketChatRecord.ts create mode 100644 app/definitions/IServedBy.ts create mode 100644 app/definitions/ISubscription.ts diff --git a/app/definitions/IRocketChatRecord.ts b/app/definitions/IRocketChatRecord.ts deleted file mode 100644 index 48d91fa84e6..00000000000 --- a/app/definitions/IRocketChatRecord.ts +++ /dev/null @@ -1,4 +0,0 @@ -export interface IRocketChatRecord { - id: string; - updatedAt: Date; -} diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index 786c1d7c85b..e8341661246 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -1,27 +1,16 @@ -import { IRocketChatRecord } from './IRocketChatRecord'; +import { IServedBy } from './IServedBy'; -export enum RoomType { - GROUP = 'p', - DIRECT = 'd', - CHANNEL = 'c', - OMNICHANNEL = 'l', - THREAD = 'thread' -} - -export interface IRoom extends IRocketChatRecord { - rid: string; - t: RoomType; - name: string; - fname: string; - prid?: string; - tmid?: string; - topic?: string; - teamMain?: boolean; - teamId?: string; - encrypted?: boolean; - visitor?: boolean; - autoTranslateLanguage?: boolean; - autoTranslate?: boolean; - observe?: Function; - usedCannedResponse: string; +export interface IRoom { + id: string; + customFields: string[]; + broadcast: boolean; + encrypted: boolean; + e2eKeyId?: string; + ro: boolean; + v: string[]; + servedBy: IServedBy; + departmentId: string; + livechatData?: any; + tags?: string[]; + avatarETag?: string; } diff --git a/app/definitions/IServedBy.ts b/app/definitions/IServedBy.ts new file mode 100644 index 00000000000..4bf31aad23b --- /dev/null +++ b/app/definitions/IServedBy.ts @@ -0,0 +1,5 @@ +export interface IServedBy { + _id: string; + username: string; + ts: Date; +} diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts new file mode 100644 index 00000000000..ec5cd9ade82 --- /dev/null +++ b/app/definitions/ISubscription.ts @@ -0,0 +1,27 @@ +export enum SubscriptionType { + GROUP = 'p', + DIRECT = 'd', + CHANNEL = 'c', + OMNICHANNEL = 'l', + THREAD = 'thread' +} + +export interface ISubscription { + id: string; + updatedAt: Date; + rid: string; + t: SubscriptionType; + name: string; + fname: string; + prid?: string; + tmid?: string; + topic?: string; + teamMain?: boolean; + teamId?: string; + encrypted?: boolean; + visitor?: boolean; + autoTranslateLanguage?: boolean; + autoTranslate?: boolean; + observe?: Function; + usedCannedResponse: string; +} diff --git a/app/navigationTypes.ts b/app/navigationTypes.ts index 568b75d0fa5..cbf17f42e80 100644 --- a/app/navigationTypes.ts +++ b/app/navigationTypes.ts @@ -1,6 +1,6 @@ import { NavigatorScreenParams } from '@react-navigation/core'; -import { IRoom } from './definitions/IRoom'; +import { ISubscription } from './definitions/ISubscription'; import { IServer } from './definitions/IServer'; import { IAttachment } from './definitions/IAttachment'; import { MasterDetailInsideStackParamList } from './stacks/MasterDetailStack/types'; @@ -28,7 +28,7 @@ export type ShareInsideStackParamList = { isShareExtension: boolean; serverInfo: IServer; text: string; - room: IRoom; + room: ISubscription; thread: any; // TODO: Change }; SelectServerView: undefined; diff --git a/app/stacks/MasterDetailStack/types.ts b/app/stacks/MasterDetailStack/types.ts index 202ad601491..242c13bab42 100644 --- a/app/stacks/MasterDetailStack/types.ts +++ b/app/stacks/MasterDetailStack/types.ts @@ -3,18 +3,18 @@ import { NavigatorScreenParams } from '@react-navigation/core'; import { IAttachment } from '../../definitions/IAttachment'; import { IMessage } from '../../definitions/IMessage'; -import { IRoom, RoomType } from '../../definitions/IRoom'; +import { ISubscription, SubscriptionType } from '../../definitions/ISubscription'; export type MasterDetailChatsStackParamList = { RoomView: { rid: string; - t: RoomType; + t: SubscriptionType; tmid?: string; message?: string; name?: string; fname?: string; prid?: string; - room: IRoom; + room: ISubscription; jumpToMessageId?: string; jumpToThreadId?: string; roomUserId?: string; @@ -27,17 +27,17 @@ export type MasterDetailDrawerParamList = { export type ModalStackParamList = { RoomActionsView: { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; joined: boolean; }; RoomInfoView: { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; }; SelectListView: { data: any; @@ -54,11 +54,11 @@ export type ModalStackParamList = { }; RoomMembersView: { rid: string; - room: IRoom; + room: ISubscription; }; SearchMessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; encrypted?: boolean; showCloseModal?: boolean; }; @@ -84,18 +84,18 @@ export type ModalStackParamList = { }; MessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; name: string; }; AutoTranslateView: { rid: string; - room: IRoom; + room: ISubscription; }; DirectoryView: undefined; QueueListView: undefined; NotificationPrefView: { rid: string; - room: IRoom; + room: ISubscription; }; ForwardLivechatView: { rid: string; @@ -110,10 +110,10 @@ export type ModalStackParamList = { scopeName: string; tags: string[]; }; - room: IRoom; + room: ISubscription; }; LivechatEditView: { - room: IRoom; + room: ISubscription; roomUser: any; // TODO: Change }; PickerView: { @@ -126,7 +126,7 @@ export type ModalStackParamList = { }; ThreadMessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; }; TeamChannelsView: { teamId: string; @@ -160,7 +160,7 @@ export type ModalStackParamList = { teamId?: string; }; CreateDiscussionView: { - channel: IRoom; + channel: ISubscription; message: IMessage; showCloseModal: boolean; }; @@ -194,7 +194,7 @@ export type MasterDetailInsideStackParamList = { isShareView?: boolean; serverInfo: {}; text: string; - room: IRoom; + room: ISubscription; thread: any; // TODO: Change }; }; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index 3107c69ce70..5a26caabfa2 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -6,28 +6,28 @@ import { IOptionsField } from '../views/NotificationPreferencesView/options'; import { IServer } from '../definitions/IServer'; import { IAttachment } from '../definitions/IAttachment'; import { IMessage } from '../definitions/IMessage'; -import { IRoom, RoomType } from '../definitions/IRoom'; +import { ISubscription, SubscriptionType } from '../definitions/ISubscription'; export type ChatsStackParamList = { RoomsListView: undefined; RoomView: { rid: string; - t: RoomType; + t: SubscriptionType; tmid?: string; message?: string; name?: string; fname?: string; prid?: string; - room: IRoom; + room: ISubscription; jumpToMessageId?: string; jumpToThreadId?: string; roomUserId?: string; }; RoomActionsView: { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; joined: boolean; }; SelectListView: { @@ -41,21 +41,21 @@ export type ChatsStackParamList = { isRadio?: boolean; }; RoomInfoView: { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; }; RoomInfoEditView: { rid: string; }; RoomMembersView: { rid: string; - room: IRoom; + room: ISubscription; }; SearchMessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; encrypted?: boolean; showCloseModal?: boolean; }; @@ -74,12 +74,12 @@ export type ChatsStackParamList = { }; MessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; name: string; }; AutoTranslateView: { rid: string; - room: IRoom; + room: ISubscription; }; DirectoryView: undefined; NotificationPrefView: { @@ -90,7 +90,7 @@ export type ChatsStackParamList = { rid: string; }; LivechatEditView: { - room: IRoom; + room: ISubscription; roomUser: any; // TODO: Change }; PickerView: { @@ -103,7 +103,7 @@ export type ChatsStackParamList = { }; ThreadMessagesView: { rid: string; - t: RoomType; + t: SubscriptionType; }; TeamChannelsView: { teamId: string; @@ -138,7 +138,7 @@ export type ChatsStackParamList = { scopeName: string; tags: string[]; }; - room: IRoom; + room: ISubscription; }; }; @@ -198,7 +198,7 @@ export type NewMessageStackParamList = { teamId?: string; }; CreateDiscussionView: { - channel: IRoom; + channel: ISubscription; message: IMessage; showCloseModal: boolean; }; @@ -230,7 +230,7 @@ export type InsideStackParamList = { isShareExtension: boolean; serverInfo: IServer; text: string; - room: IRoom; + room: ISubscription; thread: any; // TODO: Change }; ModalBlockView: { diff --git a/app/views/AutoTranslateView/index.tsx b/app/views/AutoTranslateView/index.tsx index f840ca12a5e..954426891d7 100644 --- a/app/views/AutoTranslateView/index.tsx +++ b/app/views/AutoTranslateView/index.tsx @@ -11,7 +11,7 @@ import { SWITCH_TRACK_COLOR, themes } from '../../constants/colors'; import { withTheme } from '../../theme'; import SafeAreaView from '../../containers/SafeAreaView'; import { events, logEvent } from '../../utils/log'; -import { IRoom } from '../../definitions/IRoom'; +import { ISubscription } from '../../definitions/ISubscription'; const styles = StyleSheet.create({ list: { @@ -42,7 +42,7 @@ class AutoTranslateView extends React.Component { if (room && room.observe) { this.roomObservable = room.observe(); - this.subscription = this.roomObservable.subscribe((changes: IRoom) => { + this.subscription = this.roomObservable.subscribe((changes: ISubscription) => { if (this.mounted) { const { selectedLanguage, enableAutoTranslate } = this.state; if (selectedLanguage !== changes.autoTranslateLanguage) { diff --git a/app/views/MessagesView/index.tsx b/app/views/MessagesView/index.tsx index 14532051b35..c9e3d601d15 100644 --- a/app/views/MessagesView/index.tsx +++ b/app/views/MessagesView/index.tsx @@ -20,7 +20,7 @@ import SafeAreaView from '../../containers/SafeAreaView'; import getThreadName from '../../lib/methods/getThreadName'; import styles from './styles'; import { ChatsStackParamList } from '../../stacks/types'; -import { IRoom, RoomType } from '../../definitions/IRoom'; +import { ISubscription, SubscriptionType } from '../../definitions/ISubscription'; interface IMessagesViewProps { user: { @@ -40,10 +40,10 @@ interface IMessagesViewProps { } interface IRoomInfoParam { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; joined: boolean; } @@ -72,13 +72,13 @@ interface IMessageItem { interface IParams { rid: string; - t: RoomType; + t: SubscriptionType; tmid?: string; message?: string; name?: string; fname?: string; prid?: string; - room: IRoom; + room: ISubscription; jumpToMessageId?: string; jumpToThreadId?: string; roomUserId?: string; @@ -86,7 +86,7 @@ interface IParams { class MessagesView extends React.Component { private rid: string; - private t: RoomType; + private t: SubscriptionType; private content: any; private room: any; @@ -158,7 +158,7 @@ class MessagesView extends React.Component { ...params, tmid: item.tmid, name: await getThreadName(this.rid, item.tmid, item._id), - t: RoomType.THREAD + t: SubscriptionType.THREAD }; navigation.push('RoomView', params); } else { diff --git a/app/views/SearchMessagesView/index.tsx b/app/views/SearchMessagesView/index.tsx index a85df674590..7bc3c17383d 100644 --- a/app/views/SearchMessagesView/index.tsx +++ b/app/views/SearchMessagesView/index.tsx @@ -6,7 +6,7 @@ import { Q } from '@nozbe/watermelondb'; import { connect } from 'react-redux'; import { dequal } from 'dequal'; -import { IRoom, RoomType } from '../../definitions/IRoom'; +import { ISubscription, SubscriptionType } from '../../definitions/ISubscription'; import { IAttachment } from '../../definitions/IAttachment'; import RCTextInput from '../../containers/TextInput'; import ActivityIndicator from '../../containers/ActivityIndicator'; @@ -42,10 +42,10 @@ interface ISearchMessagesViewState { } interface IRoomInfoParam { - room: IRoom; + room: ISubscription; member: any; rid: string; - t: RoomType; + t: SubscriptionType; joined: boolean; } diff --git a/app/views/ShareView/index.tsx b/app/views/ShareView/index.tsx index a3ad287aa2f..d77ba022b8f 100644 --- a/app/views/ShareView/index.tsx +++ b/app/views/ShareView/index.tsx @@ -28,7 +28,7 @@ import Preview from './Preview'; import Header from './Header'; import styles from './styles'; import { IAttachment } from './interfaces'; -import { IRoom } from '../../definitions/IRoom'; +import { ISubscription } from '../../definitions/ISubscription'; interface IShareViewState { selected: IAttachment; @@ -36,7 +36,7 @@ interface IShareViewState { readOnly: boolean; attachments: IAttachment[]; text: string; - room: IRoom; + room: ISubscription; thread: any; // change maxFileSize: number; mediaAllowList: number; From 36e2aa759ae449f19ccf7ae77ac66d5acbaeafbd Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Tue, 21 Dec 2021 23:11:56 -0300 Subject: [PATCH 14/51] TRoomModel --- app/definitions/IRoom.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index e8341661246..3aea342485e 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -1,3 +1,5 @@ +import Model from '@nozbe/watermelondb/Model'; + import { IServedBy } from './IServedBy'; export interface IRoom { @@ -14,3 +16,5 @@ export interface IRoom { tags?: string[]; avatarETag?: string; } + +export type TRoomModel = IRoom & Model; From 58ab3b0327df59dcd83b99ba1031b025321db63c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 10:43:39 -0300 Subject: [PATCH 15/51] refactoring isubscription --- app/definitions/ISubscription.ts | 92 +++++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 13 deletions(-) diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index ec5cd9ade82..5fae07c7290 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -6,22 +6,88 @@ export enum SubscriptionType { THREAD = 'thread' } +export interface IUserMessage { + _id: string; + username: string; + name: string; +} + +// export interface ILastMessage {"_id":string,"rid":string,"tshow":boolean,"tmid":string,"msg":string,"ts":Date,"u":IUserMessage,"_updatedAt":Date,"urls":string[],"mentions":[],"channels":[],"md":[{"type":"PARAGRAPH","value":[{"type":"PLAIN_TEXT","value":"olaaa"}]}],"attachments":[],"reactions":[],"unread":false,"status":0} + export interface ISubscription { - id: string; - updatedAt: Date; - rid: string; + _id: string; // _id belongs watermelonDB + id: string; // id from server + f: boolean; t: SubscriptionType; + ts: Date; + ls: Date; name: string; - fname: string; - prid?: string; - tmid?: string; + fname?: string; + rid: string; // the same as id + open: boolean; + alert: boolean; + roles: string[]; + unread: number; + userMentions: number; + groupMentions: number; + tunread: string[]; + tunreadUser: string[]; + tunreadGroup: string[]; + roomUpdatedAt: Date; + ro: boolean; + lastOpen: Date; + description?: string; + announcement?: string; + bannerClosed?: boolean; topic?: string; - teamMain?: boolean; - teamId?: string; - encrypted?: boolean; - visitor?: boolean; - autoTranslateLanguage?: boolean; + blocked: boolean; + blocker: boolean; + reactWhenReadOnly: boolean; + archived: boolean; + joinCodeRequired: boolean; + notifications: any; + muted: string[]; + ignored: string[]; + broadcast?: boolean; + prid: string; + draftMessage: string; + lastThreadSync: Date; + jitsiTimeout: number; autoTranslate?: boolean; - observe?: Function; - usedCannedResponse: string; + autoTranslateLanguage?: boolean; + // lastMessage: + // messages + // threads + // threadMessages + // hideUnreadStatus + // sysMes + // uids + // usernames + // visitor + // departmentId + // servedBy + // livechatData + // tags + // E2EKey + // encrypted + // e2eKeyId + // avatarETag + // teamId + // teamMain } +// updatedAt: Date; +// rid: string; +// t: SubscriptionType; +// name: string; +// fname: string; +// prid?: string; +// tmid?: string; +// topic?: string; +// teamMain?: boolean; +// teamId?: string; +// encrypted?: boolean; +// visitor?: boolean; +// autoTranslateLanguage?: boolean; +// autoTranslate?: boolean; +// observe?: Function; +// usedCannedResponse: string; From d2a894d2696381e8be6bf7fb3f2659df00b46c7c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 11:47:21 -0300 Subject: [PATCH 16/51] ISubcription almost there, missing the Threads, ThreadsMessages and Uploads models --- app/definitions/IMessage.ts | 23 ++++++++++- app/definitions/ISubscription.ts | 68 ++++++++++++++------------------ 2 files changed, 50 insertions(+), 41 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index f7b6bf64a52..0850229f436 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -3,7 +3,7 @@ import { MarkdownAST } from '@rocket.chat/message-parser'; import { IAttachment } from './IAttachment'; import { IReaction } from './IReactions'; -import { RoomType } from './IRoom'; +import { SubscriptionType } from './ISubscription'; interface IUserMessage { _id: string; @@ -29,9 +29,28 @@ export interface ITranslations { value: string; } +export interface ILastMessage { + _id: string; + rid: string; + tshow: boolean; + tmid: string; + msg: string; + ts: Date; + u: IUserMessage; + _updatedAt: Date; + urls: string[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + md: MarkdownAST; + attachments: IAttachment[]; + reactions: IReaction[]; + unread: boolean; + status: boolean; +} + export interface IMessage { msg: string; - t?: RoomType; + t?: SubscriptionType; ts: Date; u: IUserMessage; subscription: { id: string }; diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index 5fae07c7290..3333ae5f7ac 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -1,3 +1,8 @@ +import Collection from '@nozbe/watermelondb/Collection'; + +import { ILastMessage, TMessageModel } from './IMessage'; +import { IServedBy } from './IServedBy'; + export enum SubscriptionType { GROUP = 'p', DIRECT = 'd', @@ -6,14 +11,14 @@ export enum SubscriptionType { THREAD = 'thread' } -export interface IUserMessage { +export interface IVisitor { _id: string; username: string; - name: string; + token: string; + status: string; + lastMessageTs: Date; } -// export interface ILastMessage {"_id":string,"rid":string,"tshow":boolean,"tmid":string,"msg":string,"ts":Date,"u":IUserMessage,"_updatedAt":Date,"urls":string[],"mentions":[],"channels":[],"md":[{"type":"PARAGRAPH","value":[{"type":"PLAIN_TEXT","value":"olaaa"}]}],"attachments":[],"reactions":[],"unread":false,"status":0} - export interface ISubscription { _id: string; // _id belongs watermelonDB id: string; // id from server @@ -55,39 +60,24 @@ export interface ISubscription { jitsiTimeout: number; autoTranslate?: boolean; autoTranslateLanguage?: boolean; - // lastMessage: - // messages - // threads - // threadMessages - // hideUnreadStatus - // sysMes - // uids - // usernames - // visitor - // departmentId - // servedBy - // livechatData - // tags - // E2EKey - // encrypted - // e2eKeyId - // avatarETag - // teamId - // teamMain + lastMessage: ILastMessage; + hideUnreadStatus: boolean; + sysMes?: string[] | boolean; + uids?: string[]; + usernames?: string[]; + visitor?: IVisitor; + departmentId?: string; + servedBy?: IServedBy; + livechatData?: any; + tags?: string[]; + E2EKey?: string; + encrypted?: boolean; + e2eKeyId?: string; + avatarETag?: string; + teamId?: string; + teamMain?: boolean; + messages: Collection; + // threads: Collection + // threadMessages: Collection + // uploads: Collection } -// updatedAt: Date; -// rid: string; -// t: SubscriptionType; -// name: string; -// fname: string; -// prid?: string; -// tmid?: string; -// topic?: string; -// teamMain?: boolean; -// teamId?: string; -// encrypted?: boolean; -// visitor?: boolean; -// autoTranslateLanguage?: boolean; -// autoTranslate?: boolean; -// observe?: Function; -// usedCannedResponse: string; From 46a18d4cb2f0d020cde29151e13cab3f6dfffd4a Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 11:59:25 -0300 Subject: [PATCH 17/51] Subscription Model --- app/definitions/ISubscription.ts | 3 +++ app/stacks/types.ts | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index 3333ae5f7ac..157589da0e0 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -1,4 +1,5 @@ import Collection from '@nozbe/watermelondb/Collection'; +import Model from '@nozbe/watermelondb/Model'; import { ILastMessage, TMessageModel } from './IMessage'; import { IServedBy } from './IServedBy'; @@ -81,3 +82,5 @@ export interface ISubscription { // threadMessages: Collection // uploads: Collection } + +export type TSubscriptionModel = ISubscription & Model; diff --git a/app/stacks/types.ts b/app/stacks/types.ts index 5a26caabfa2..daf366d9240 100644 --- a/app/stacks/types.ts +++ b/app/stacks/types.ts @@ -6,7 +6,7 @@ import { IOptionsField } from '../views/NotificationPreferencesView/options'; import { IServer } from '../definitions/IServer'; import { IAttachment } from '../definitions/IAttachment'; import { IMessage } from '../definitions/IMessage'; -import { ISubscription, SubscriptionType } from '../definitions/ISubscription'; +import { ISubscription, SubscriptionType, TSubscriptionModel } from '../definitions/ISubscription'; export type ChatsStackParamList = { RoomsListView: undefined; @@ -79,7 +79,7 @@ export type ChatsStackParamList = { }; AutoTranslateView: { rid: string; - room: ISubscription; + room: TSubscriptionModel; }; DirectoryView: undefined; NotificationPrefView: { From 8d7b38771a35445e360e072b48e923bbd2336d49 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 12:05:45 -0300 Subject: [PATCH 18/51] IServerHistory --- app/definitions/IServerHistory.ts | 10 ++++++++++ app/views/NewServerView/index.tsx | 17 ++++++----------- 2 files changed, 16 insertions(+), 11 deletions(-) create mode 100644 app/definitions/IServerHistory.ts diff --git a/app/definitions/IServerHistory.ts b/app/definitions/IServerHistory.ts new file mode 100644 index 00000000000..296cba4ed46 --- /dev/null +++ b/app/definitions/IServerHistory.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IServerHistory { + id: string; + url: string; + username: string; + updatedAt: Date; +} + +export type TServerHistory = IServerHistory & Model; diff --git a/app/views/NewServerView/index.tsx b/app/views/NewServerView/index.tsx index aaacdf90f01..53594d9c0a1 100644 --- a/app/views/NewServerView/index.tsx +++ b/app/views/NewServerView/index.tsx @@ -8,7 +8,6 @@ import { TouchableOpacity } from 'react-native-gesture-handler'; import Orientation from 'react-native-orientation-locker'; import { StackNavigationProp } from '@react-navigation/stack'; import { Dispatch } from 'redux'; -import Model from '@nozbe/watermelondb/Model'; import UserPreferences from '../../lib/userPreferences'; import EventEmitter from '../../utils/events'; @@ -34,6 +33,7 @@ import { verticalScale, moderateScale } from '../../utils/scaling'; import { withDimensions } from '../../dimensions'; import ServerInput from './ServerInput'; import { OutsideParamList } from '../../stacks/types'; +import { TServerHistory } from '../../definitions/IServerHistory'; const styles = StyleSheet.create({ onboardingImage: { @@ -68,11 +68,6 @@ const styles = StyleSheet.create({ } }); -export interface IServer extends Model { - url: string; - username: string; -} - interface INewServerView { navigation: StackNavigationProp; theme: string; @@ -90,7 +85,7 @@ interface IState { text: string; connectingOpen: boolean; certificate: any; - serversHistory: IServer[]; + serversHistory: TServerHistory[]; } interface ISubmitParams { @@ -166,7 +161,7 @@ class NewServerView extends React.Component { const likeString = sanitizeLikeString(text); whereClause = [...whereClause, Q.where('url', Q.like(`%${likeString}%`))]; } - const serversHistory = (await serversHistoryCollection.query(...whereClause).fetch()) as IServer[]; + const serversHistory = (await serversHistoryCollection.query(...whereClause).fetch()) as TServerHistory[]; this.setState({ serversHistory }); } catch { // Do nothing @@ -190,7 +185,7 @@ class NewServerView extends React.Component { connectServer(server); }; - onPressServerHistory = (serverHistory: IServer) => { + onPressServerHistory = (serverHistory: TServerHistory) => { this.setState({ text: serverHistory.url }, () => this.submit({ fromServerHistory: true, username: serverHistory?.username })); }; @@ -283,14 +278,14 @@ class NewServerView extends React.Component { }); }; - deleteServerHistory = async (item: IServer) => { + deleteServerHistory = async (item: TServerHistory) => { const db = database.servers; try { await db.write(async () => { await item.destroyPermanently(); }); this.setState((prevstate: IState) => ({ - serversHistory: prevstate.serversHistory.filter((server: IServer) => server.id !== item.id) + serversHistory: prevstate.serversHistory.filter((server: TServerHistory) => server.id !== item.id) })); } catch { // Nothing From c824825c60008ad0c68efffd4f53a50f5eec063e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 12:15:17 -0300 Subject: [PATCH 19/51] IServer --- app/definitions/IServer.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/definitions/IServer.ts b/app/definitions/IServer.ts index 534a29c9ce2..014a2702bd8 100644 --- a/app/definitions/IServer.ts +++ b/app/definitions/IServer.ts @@ -1,3 +1,5 @@ +import Model from '@nozbe/watermelondb/Model'; + export interface IServer { name: string; iconURL: string; @@ -14,3 +16,5 @@ export interface IServer { enterpriseModules: string; E2E_Enable: boolean; } + +export type TServerModel = IServer & Model; From 6e336b4651bc473a9ac8e973aab050719ca918bd Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 12:16:00 -0300 Subject: [PATCH 20/51] fix lint serverHistory --- app/views/NewServerView/ServerInput/Item.tsx | 6 +++--- app/views/NewServerView/ServerInput/index.tsx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/views/NewServerView/ServerInput/Item.tsx b/app/views/NewServerView/ServerInput/Item.tsx index 9fb44719e49..cc8a9e3a747 100644 --- a/app/views/NewServerView/ServerInput/Item.tsx +++ b/app/views/NewServerView/ServerInput/Item.tsx @@ -6,7 +6,7 @@ import { themes } from '../../../constants/colors'; import { CustomIcon } from '../../../lib/Icons'; import sharedStyles from '../../Styles'; import Touch from '../../../utils/touch'; -import { IServer } from '../index'; +import { TServerHistory } from '../../../definitions/IServerHistory'; const styles = StyleSheet.create({ container: { @@ -28,10 +28,10 @@ const styles = StyleSheet.create({ }); interface IItem { - item: IServer; + item: TServerHistory; theme: string; onPress(url: string): void; - onDelete(item: IServer): void; + onDelete(item: TServerHistory): void; } const Item = ({ item, theme, onPress, onDelete }: IItem): JSX.Element => ( diff --git a/app/views/NewServerView/ServerInput/index.tsx b/app/views/NewServerView/ServerInput/index.tsx index 1da15136797..e2b14fd69ff 100644 --- a/app/views/NewServerView/ServerInput/index.tsx +++ b/app/views/NewServerView/ServerInput/index.tsx @@ -5,8 +5,8 @@ import TextInput from '../../../containers/TextInput'; import * as List from '../../../containers/List'; import { themes } from '../../../constants/colors'; import I18n from '../../../i18n'; +import { TServerHistory } from '../../../definitions/IServerHistory'; import Item from './Item'; -import { IServer } from '../index'; const styles = StyleSheet.create({ container: { @@ -33,8 +33,8 @@ interface IServerInput extends TextInputProps { theme: string; serversHistory: any[]; onSubmit(): void; - onDelete(item: IServer): void; - onPressServerHistory(serverHistory: IServer): void; + onDelete(item: TServerHistory): void; + onPressServerHistory(serverHistory: TServerHistory): void; } const ServerInput = ({ From 83521183f313094646163634d9a31c0301c6826a Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 12:29:00 -0300 Subject: [PATCH 21/51] LoggedUser --- app/definitions/ILoggedUser.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 app/definitions/ILoggedUser.ts diff --git a/app/definitions/ILoggedUser.ts b/app/definitions/ILoggedUser.ts new file mode 100644 index 00000000000..487d29c18a8 --- /dev/null +++ b/app/definitions/ILoggedUser.ts @@ -0,0 +1,18 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface ILoggedUser { + id: string; + token: string; + username: string; + name: string; + language?: string; + status: string; + statusText?: string; + roles: string[]; + avatarETag?: string; + showMessageInMainThread: boolean; + isFromWebView: boolean; + enableMessageParserEarlyAdoption?: boolean; +} + +export type TLoggedUser = ILoggedUser & Model; From 29be47ba5d99c6ebc77a3939f5cd88099b979883 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 15:38:11 -0300 Subject: [PATCH 22/51] ISettings --- app/definitions/ISettings.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/definitions/ISettings.ts diff --git a/app/definitions/ISettings.ts b/app/definitions/ISettings.ts new file mode 100644 index 00000000000..513f6d2b55c --- /dev/null +++ b/app/definitions/ISettings.ts @@ -0,0 +1,12 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface ISettings { + id: string; + valueAsString: string; + valueAsBoolean: boolean; + valueAsNumber: number; + valueAsArray: string[]; + _updatedAt: Date; +} + +export type TSettingsModel = ISettings & Model; From 5e40d6de3bef49b9a95c39dace5548bb40b63360 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 15:44:51 -0300 Subject: [PATCH 23/51] ISlashCommand --- app/definitions/ISlashCommand.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/definitions/ISlashCommand.ts diff --git a/app/definitions/ISlashCommand.ts b/app/definitions/ISlashCommand.ts new file mode 100644 index 00000000000..d98610ad181 --- /dev/null +++ b/app/definitions/ISlashCommand.ts @@ -0,0 +1,12 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface ISlashCommand { + id: string; + params: string; + description: string; + clientOnly: boolean; + providesPreview: boolean; + appId?: string; +} + +export type TSlashCommandModel = ISlashCommand & Model; From 6783bff338a306428dd1dc37c68bfd9769024451 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 16:03:22 -0300 Subject: [PATCH 24/51] IThread and models --- app/definitions/IMessage.ts | 4 +- .../{IReactions.ts => IReaction.ts} | 0 app/definitions/ISubscription.ts | 3 +- app/definitions/IThread.ts | 72 +++++++++++++++++++ app/definitions/IUrl.ts | 6 ++ 5 files changed, 82 insertions(+), 3 deletions(-) rename app/definitions/{IReactions.ts => IReaction.ts} (100%) create mode 100644 app/definitions/IThread.ts create mode 100644 app/definitions/IUrl.ts diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 0850229f436..28af21e2109 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -2,10 +2,10 @@ import Model from '@nozbe/watermelondb/Model'; import { MarkdownAST } from '@rocket.chat/message-parser'; import { IAttachment } from './IAttachment'; -import { IReaction } from './IReactions'; +import { IReaction } from './IReaction'; import { SubscriptionType } from './ISubscription'; -interface IUserMessage { +export interface IUserMessage { _id: string; username?: string; name?: string; diff --git a/app/definitions/IReactions.ts b/app/definitions/IReaction.ts similarity index 100% rename from app/definitions/IReactions.ts rename to app/definitions/IReaction.ts diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index 157589da0e0..f4df3d3aaf2 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -3,6 +3,7 @@ import Model from '@nozbe/watermelondb/Model'; import { ILastMessage, TMessageModel } from './IMessage'; import { IServedBy } from './IServedBy'; +import { TThreadModel } from './IThread'; export enum SubscriptionType { GROUP = 'p', @@ -78,7 +79,7 @@ export interface ISubscription { teamId?: string; teamMain?: boolean; messages: Collection; - // threads: Collection + threads: Collection; // threadMessages: Collection // uploads: Collection } diff --git a/app/definitions/IThread.ts b/app/definitions/IThread.ts new file mode 100644 index 00000000000..a0318d65861 --- /dev/null +++ b/app/definitions/IThread.ts @@ -0,0 +1,72 @@ +import Model from '@nozbe/watermelondb/Model'; +import { MarkdownAST } from '@rocket.chat/message-parser'; + +import { IAttachment } from './IAttachment'; +import { IUserChannel, IUserMention, IUserMessage } from './IMessage'; +import { IReaction } from './IReaction'; +import { SubscriptionType } from './ISubscription'; +import { IUrl } from './IUrl'; + +interface IFileThread { + _id: string; + name: string; + type: string; +} + +export interface IThreadResult { + _id: string; + rid: string; + ts: string; + msg: string; + file?: IFileThread; + files?: IFileThread[]; + groupable?: boolean; + attachments?: IAttachment[]; + md?: MarkdownAST; + u: IUserMessage; + _updatedAt: string; + urls: IUrl[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + replies: string[]; + tcount: number; + tlm: string; +} + +export interface IThread { + id: string; + msg: string; + t: SubscriptionType; + rid: string; + _updatedAt: Date; + ts: Date; + u: IUserMessage; + alias: any; + parseUrls: any; + groupable: boolean; + avatar: string; + emoji: any; + attachments: IAttachment[]; + urls: IUrl[]; + status: number; + pinned: boolean; + starred: boolean; + editedBy: { _id: string; username: string }; + reactions: IReaction[]; + role: string; + drid: string; + dcount: number; + dlm: number; + tmid: string; + tcount: number; + tlm: Date; + replies: string[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + unread: boolean; + autoTranslate: boolean; + translations: any; + e2e: any; +} + +export type TThreadModel = IThread & Model; diff --git a/app/definitions/IUrl.ts b/app/definitions/IUrl.ts new file mode 100644 index 00000000000..9b72fda2681 --- /dev/null +++ b/app/definitions/IUrl.ts @@ -0,0 +1,6 @@ +export interface IUrl { + title: string; + description: string; + image: string; + url: string; +} From cc35a761951dae69e9fcb774ca6b48a5f2b03efd Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 16:19:19 -0300 Subject: [PATCH 25/51] IThreadMessage almost there --- app/definitions/IMessage.ts | 7 +++++- app/definitions/IThread.ts | 12 +++++----- app/definitions/IThreadMessage.ts | 39 +++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 7 deletions(-) create mode 100644 app/definitions/IThreadMessage.ts diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 28af21e2109..6c8e9f95422 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -21,6 +21,11 @@ export interface IUserChannel { _id: string; } +export interface IEditedBy { + _id: string; + username: string; +} + export type TOnLinkPress = (link: string) => void; export interface ITranslations { @@ -65,7 +70,7 @@ export interface IMessage { status: number; pinned: boolean; starred: boolean; - editedBy?: { _id: string; username: string }; + editedBy?: IEditedBy; reactions: IReaction[]; role: string; drid: string; diff --git a/app/definitions/IThread.ts b/app/definitions/IThread.ts index a0318d65861..d89c788f72e 100644 --- a/app/definitions/IThread.ts +++ b/app/definitions/IThread.ts @@ -2,7 +2,7 @@ import Model from '@nozbe/watermelondb/Model'; import { MarkdownAST } from '@rocket.chat/message-parser'; import { IAttachment } from './IAttachment'; -import { IUserChannel, IUserMention, IUserMessage } from './IMessage'; +import { IEditedBy, IUserChannel, IUserMention, IUserMessage } from './IMessage'; import { IReaction } from './IReaction'; import { SubscriptionType } from './ISubscription'; import { IUrl } from './IUrl'; @@ -41,17 +41,17 @@ export interface IThread { _updatedAt: Date; ts: Date; u: IUserMessage; - alias: any; - parseUrls: any; + alias: string; + parseUrls: boolean; groupable: boolean; avatar: string; - emoji: any; + emoji: string; attachments: IAttachment[]; urls: IUrl[]; status: number; pinned: boolean; starred: boolean; - editedBy: { _id: string; username: string }; + editedBy: IEditedBy; reactions: IReaction[]; role: string; drid: string; @@ -66,7 +66,7 @@ export interface IThread { unread: boolean; autoTranslate: boolean; translations: any; - e2e: any; + e2e: string; } export type TThreadModel = IThread & Model; diff --git a/app/definitions/IThreadMessage.ts b/app/definitions/IThreadMessage.ts new file mode 100644 index 00000000000..6f592b46296 --- /dev/null +++ b/app/definitions/IThreadMessage.ts @@ -0,0 +1,39 @@ +import { IAttachment } from './IAttachment'; +import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage } from './IMessage'; +import { IReaction } from './IReaction'; +import { SubscriptionType } from './ISubscription'; + +export interface IThreadMessage { + msg: string; + t?: SubscriptionType; + ts: Date; + u: IUserMessage; + subscription: { id: string }; + alias: string; + parseUrls: boolean; + groupable: boolean; + avatar: string; + emoji: string; + attachments: IAttachment[]; + urls: string[]; + _updatedAt: Date; + status: number; + pinned: boolean; + starred: boolean; + editedBy?: IEditedBy; + reactions: IReaction[]; + role: string; + drid: string; + dcount: number; + dlm: Date; + tmid: string; + tcount: number; + tlm: Date; + replies: string[]; + mentions: IUserMention[]; + channels: IUserChannel[]; + unread: boolean; + autoTranslate: boolean; + translations: ITranslations[]; + e2e: string; +} From 0a918f6a80533c773519cbe0e25ab0afd867566c Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 16:49:21 -0300 Subject: [PATCH 26/51] IThreadMessagesModel --- app/definitions/IMessage.ts | 2 +- app/definitions/ISubscription.ts | 3 ++- app/definitions/IThreadMessage.ts | 6 +++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 6c8e9f95422..f765077b6cf 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -58,7 +58,6 @@ export interface IMessage { t?: SubscriptionType; ts: Date; u: IUserMessage; - subscription: { id: string }; alias: string; parseUrls: boolean; groupable: boolean; @@ -90,6 +89,7 @@ export interface IMessage { e2e: string; tshow: boolean; md: MarkdownAST; + subscription: { id: string }; } export type TMessageModel = IMessage & Model; diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index f4df3d3aaf2..8f60949c7b9 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -4,6 +4,7 @@ import Model from '@nozbe/watermelondb/Model'; import { ILastMessage, TMessageModel } from './IMessage'; import { IServedBy } from './IServedBy'; import { TThreadModel } from './IThread'; +import { TThreadMessageModel } from './IThreadMessage'; export enum SubscriptionType { GROUP = 'p', @@ -80,7 +81,7 @@ export interface ISubscription { teamMain?: boolean; messages: Collection; threads: Collection; - // threadMessages: Collection + threadMessages: Collection; // uploads: Collection } diff --git a/app/definitions/IThreadMessage.ts b/app/definitions/IThreadMessage.ts index 6f592b46296..aff006c2b39 100644 --- a/app/definitions/IThreadMessage.ts +++ b/app/definitions/IThreadMessage.ts @@ -1,3 +1,5 @@ +import Model from '@nozbe/watermelondb/Model'; + import { IAttachment } from './IAttachment'; import { IEditedBy, ITranslations, IUserChannel, IUserMention, IUserMessage } from './IMessage'; import { IReaction } from './IReaction'; @@ -8,7 +10,6 @@ export interface IThreadMessage { t?: SubscriptionType; ts: Date; u: IUserMessage; - subscription: { id: string }; alias: string; parseUrls: boolean; groupable: boolean; @@ -36,4 +37,7 @@ export interface IThreadMessage { autoTranslate: boolean; translations: ITranslations[]; e2e: string; + subscription: { id: string }; } + +export type TThreadMessageModel = IThreadMessage & Model; From 220e2ba73d8a54a337601d7f3b7dc5c667dce788 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 21:47:09 -0300 Subject: [PATCH 27/51] minor tweak IUrl --- app/definitions/IThread.ts | 8 +++++++- app/definitions/IUrl.ts | 6 ------ 2 files changed, 7 insertions(+), 7 deletions(-) delete mode 100644 app/definitions/IUrl.ts diff --git a/app/definitions/IThread.ts b/app/definitions/IThread.ts index d89c788f72e..76980f9d49e 100644 --- a/app/definitions/IThread.ts +++ b/app/definitions/IThread.ts @@ -5,7 +5,13 @@ import { IAttachment } from './IAttachment'; import { IEditedBy, IUserChannel, IUserMention, IUserMessage } from './IMessage'; import { IReaction } from './IReaction'; import { SubscriptionType } from './ISubscription'; -import { IUrl } from './IUrl'; + +export interface IUrl { + title: string; + description: string; + image: string; + url: string; +} interface IFileThread { _id: string; diff --git a/app/definitions/IUrl.ts b/app/definitions/IUrl.ts deleted file mode 100644 index 9b72fda2681..00000000000 --- a/app/definitions/IUrl.ts +++ /dev/null @@ -1,6 +0,0 @@ -export interface IUrl { - title: string; - description: string; - image: string; - url: string; -} From a23a3e86bf0db89880b253791ebed294183c7507 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 21:55:27 -0300 Subject: [PATCH 28/51] IUploads --- app/definitions/IUpload.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/definitions/IUpload.ts diff --git a/app/definitions/IUpload.ts b/app/definitions/IUpload.ts new file mode 100644 index 00000000000..a8d7a9a6ae1 --- /dev/null +++ b/app/definitions/IUpload.ts @@ -0,0 +1,16 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IUpload { + id: string; + path: string; + name: string; + description: string; + size: number; + type: string; + store: string; + progress: number; + error: boolean; + subscription: { id: string }; +} + +export type TUploadModel = IUpload & Model; From 8bf85cb1d7927571b7b489ee5f13c6537f70d932 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 21:57:14 -0300 Subject: [PATCH 29/51] ISubscription done --- app/definitions/ISubscription.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index 8f60949c7b9..2d30b53927c 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -5,6 +5,7 @@ import { ILastMessage, TMessageModel } from './IMessage'; import { IServedBy } from './IServedBy'; import { TThreadModel } from './IThread'; import { TThreadMessageModel } from './IThreadMessage'; +import { TUploadModel } from './IUpload'; export enum SubscriptionType { GROUP = 'p', @@ -82,7 +83,7 @@ export interface ISubscription { messages: Collection; threads: Collection; threadMessages: Collection; - // uploads: Collection + uploads: Collection; } export type TSubscriptionModel = ISubscription & Model; From b5b0a7af751c110c8e4667704d89d7708c162288 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:13:48 -0300 Subject: [PATCH 30/51] relation to ISubscrition --- app/definitions/ISubscription.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index 2d30b53927c..d87ec7fe442 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -1,5 +1,5 @@ -import Collection from '@nozbe/watermelondb/Collection'; import Model from '@nozbe/watermelondb/Model'; +import Relation from '@nozbe/watermelondb/Relation'; import { ILastMessage, TMessageModel } from './IMessage'; import { IServedBy } from './IServedBy'; @@ -80,10 +80,11 @@ export interface ISubscription { avatarETag?: string; teamId?: string; teamMain?: boolean; - messages: Collection; - threads: Collection; - threadMessages: Collection; - uploads: Collection; + // https://nozbe.github.io/WatermelonDB/Relation.html#relation-api + messages: Relation; + threads: Relation; + threadMessages: Relation; + uploads: Relation; } export type TSubscriptionModel = ISubscription & Model; From aa167147f4ddf3b230d252e5108ec0aef642c44e Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:23:49 -0300 Subject: [PATCH 31/51] optionals to Subscription --- app/definitions/ISubscription.ts | 37 ++++++++++++++++---------------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/app/definitions/ISubscription.ts b/app/definitions/ISubscription.ts index d87ec7fe442..5f561edfb59 100644 --- a/app/definitions/ISubscription.ts +++ b/app/definitions/ISubscription.ts @@ -35,37 +35,36 @@ export interface ISubscription { rid: string; // the same as id open: boolean; alert: boolean; - roles: string[]; + roles?: string[]; unread: number; userMentions: number; groupMentions: number; - tunread: string[]; - tunreadUser: string[]; - tunreadGroup: string[]; + tunread?: string[]; + tunreadUser?: string[]; + tunreadGroup?: string[]; roomUpdatedAt: Date; ro: boolean; - lastOpen: Date; + lastOpen?: Date; description?: string; announcement?: string; bannerClosed?: boolean; topic?: string; - blocked: boolean; - blocker: boolean; - reactWhenReadOnly: boolean; + blocked?: boolean; + blocker?: boolean; + reactWhenReadOnly?: boolean; archived: boolean; - joinCodeRequired: boolean; - notifications: any; - muted: string[]; - ignored: string[]; + joinCodeRequired?: boolean; + muted?: string[]; + ignored?: string[]; broadcast?: boolean; - prid: string; - draftMessage: string; - lastThreadSync: Date; - jitsiTimeout: number; + prid?: string; + draftMessage?: string; + lastThreadSync?: Date; + jitsiTimeout?: number; autoTranslate?: boolean; - autoTranslateLanguage?: boolean; - lastMessage: ILastMessage; - hideUnreadStatus: boolean; + autoTranslateLanguage: string; + lastMessage?: ILastMessage; + hideUnreadStatus?: boolean; sysMes?: string[] | boolean; uids?: string[]; usernames?: string[]; From 999d029fe6e43a749a2e398900dc94aca28d1a38 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:27:55 -0300 Subject: [PATCH 32/51] IUser done --- app/definitions/IUser.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 app/definitions/IUser.ts diff --git a/app/definitions/IUser.ts b/app/definitions/IUser.ts new file mode 100644 index 00000000000..012ef808714 --- /dev/null +++ b/app/definitions/IUser.ts @@ -0,0 +1,10 @@ +import Model from '@nozbe/watermelondb/Model'; + +export interface IUser { + _id: string; + name?: string; + username: string; + avatarETag?: string; +} + +export type TUserModel = IUser & Model; From eb217aca44b0ea3ef8e69212b43b1547858a38f0 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:39:12 -0300 Subject: [PATCH 33/51] IRoom and IMessage optionals --- app/definitions/IMessage.ts | 57 +++++++++++++++++++------------------ app/definitions/IRoom.ts | 8 +++--- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index f765077b6cf..3e0a5c0d2fa 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -54,41 +54,42 @@ export interface ILastMessage { } export interface IMessage { - msg: string; + msg?: string; t?: SubscriptionType; + rid: string; ts: Date; u: IUserMessage; alias: string; parseUrls: boolean; - groupable: boolean; - avatar: string; - emoji: string; - attachments: IAttachment[]; - urls: string[]; + groupable?: boolean; + avatar?: string; + emoji?: string; + attachments?: IAttachment[]; + urls?: string[]; _updatedAt: Date; - status: number; - pinned: boolean; - starred: boolean; + status?: number; + pinned?: boolean; + starred?: boolean; editedBy?: IEditedBy; - reactions: IReaction[]; - role: string; - drid: string; - dcount: number; - dlm: Date; - tmid: string; - tcount: number; - tlm: Date; - replies: string[]; - mentions: IUserMention[]; - channels: IUserChannel[]; - unread: boolean; - autoTranslate: boolean; - translations: ITranslations[]; - tmsg: string; - blocks: any; - e2e: string; - tshow: boolean; - md: MarkdownAST; + reactions?: IReaction[]; + role?: string; + drid?: string; + dcount?: number; + dlm?: Date; + tmid?: string; + tcount?: number; + tlm?: Date; + replies?: string[]; + mentions?: IUserMention[]; + channels?: IUserChannel[]; + unread?: boolean; + autoTranslate?: boolean; + translations?: ITranslations[]; + tmsg?: string; + blocks?: any; + e2e?: string; + tshow?: boolean; + md?: MarkdownAST; subscription: { id: string }; } diff --git a/app/definitions/IRoom.ts b/app/definitions/IRoom.ts index 3aea342485e..d55cf34a55e 100644 --- a/app/definitions/IRoom.ts +++ b/app/definitions/IRoom.ts @@ -7,13 +7,13 @@ export interface IRoom { customFields: string[]; broadcast: boolean; encrypted: boolean; - e2eKeyId?: string; ro: boolean; - v: string[]; - servedBy: IServedBy; - departmentId: string; + v?: string[]; + servedBy?: IServedBy; + departmentId?: string; livechatData?: any; tags?: string[]; + e2eKeyId?: string; avatarETag?: string; } From f5ff302b6f7ed9da6fb7d27742af470c64f48a90 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:46:51 -0300 Subject: [PATCH 34/51] IThread and IThreadMessage optionals --- app/definitions/IThread.ts | 56 +++++++++++++++--------------- app/definitions/IThreadMessage.ts | 57 ++++++++++++++++--------------- 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/app/definitions/IThread.ts b/app/definitions/IThread.ts index 76980f9d49e..ad151283b9b 100644 --- a/app/definitions/IThread.ts +++ b/app/definitions/IThread.ts @@ -41,38 +41,38 @@ export interface IThreadResult { export interface IThread { id: string; - msg: string; - t: SubscriptionType; + msg?: string; + t?: SubscriptionType; rid: string; _updatedAt: Date; ts: Date; u: IUserMessage; - alias: string; - parseUrls: boolean; - groupable: boolean; - avatar: string; - emoji: string; - attachments: IAttachment[]; - urls: IUrl[]; - status: number; - pinned: boolean; - starred: boolean; - editedBy: IEditedBy; - reactions: IReaction[]; - role: string; - drid: string; - dcount: number; - dlm: number; - tmid: string; - tcount: number; - tlm: Date; - replies: string[]; - mentions: IUserMention[]; - channels: IUserChannel[]; - unread: boolean; - autoTranslate: boolean; - translations: any; - e2e: string; + alias?: string; + parseUrls?: boolean; + groupable?: boolean; + avatar?: string; + emoji?: string; + attachments?: IAttachment[]; + urls?: IUrl[]; + status?: number; + pinned?: boolean; + starred?: boolean; + editedBy?: IEditedBy; + reactions?: IReaction[]; + role?: string; + drid?: string; + dcount?: number; + dlm?: number; + tmid?: string; + tcount?: number; + tlm?: Date; + replies?: string[]; + mentions?: IUserMention[]; + channels?: IUserChannel[]; + unread?: boolean; + autoTranslate?: boolean; + translations?: any; + e2e?: string; } export type TThreadModel = IThread & Model; diff --git a/app/definitions/IThreadMessage.ts b/app/definitions/IThreadMessage.ts index aff006c2b39..c773e4dc5c4 100644 --- a/app/definitions/IThreadMessage.ts +++ b/app/definitions/IThreadMessage.ts @@ -6,38 +6,39 @@ import { IReaction } from './IReaction'; import { SubscriptionType } from './ISubscription'; export interface IThreadMessage { - msg: string; + msg?: string; t?: SubscriptionType; + rid: string; ts: Date; u: IUserMessage; - alias: string; - parseUrls: boolean; - groupable: boolean; - avatar: string; - emoji: string; - attachments: IAttachment[]; - urls: string[]; - _updatedAt: Date; - status: number; - pinned: boolean; - starred: boolean; + alias?: string; + parseUrls?: boolean; + groupable?: boolean; + avatar?: string; + emoji?: string; + attachments?: IAttachment[]; + urls?: string[]; + _updatedAt?: Date; + status?: number; + pinned?: boolean; + starred?: boolean; editedBy?: IEditedBy; - reactions: IReaction[]; - role: string; - drid: string; - dcount: number; - dlm: Date; - tmid: string; - tcount: number; - tlm: Date; - replies: string[]; - mentions: IUserMention[]; - channels: IUserChannel[]; - unread: boolean; - autoTranslate: boolean; - translations: ITranslations[]; - e2e: string; - subscription: { id: string }; + reactions?: IReaction[]; + role?: string; + drid?: string; + dcount?: number; + dlm?: Date; + tmid?: string; + tcount?: number; + tlm?: Date; + replies?: string[]; + mentions?: IUserMention[]; + channels?: IUserChannel[]; + unread?: boolean; + autoTranslate?: boolean; + translations?: ITranslations[]; + e2e?: string; + subscription?: { id: string }; } export type TThreadMessageModel = IThreadMessage & Model; From 14a99215730565101e93e7b447882b4ee5a74e19 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 22 Dec 2021 22:53:02 -0300 Subject: [PATCH 35/51] optionals done --- app/definitions/IMessage.ts | 1 - app/definitions/IRole.ts | 2 +- app/definitions/ISettings.ts | 10 +++++----- app/definitions/ISlashCommand.ts | 8 ++++---- app/definitions/IUpload.ts | 10 +++++----- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/app/definitions/IMessage.ts b/app/definitions/IMessage.ts index 3e0a5c0d2fa..d4c9d32667b 100644 --- a/app/definitions/IMessage.ts +++ b/app/definitions/IMessage.ts @@ -56,7 +56,6 @@ export interface ILastMessage { export interface IMessage { msg?: string; t?: SubscriptionType; - rid: string; ts: Date; u: IUserMessage; alias: string; diff --git a/app/definitions/IRole.ts b/app/definitions/IRole.ts index 82dbef3bb8b..1fec4215095 100644 --- a/app/definitions/IRole.ts +++ b/app/definitions/IRole.ts @@ -2,7 +2,7 @@ import Model from '@nozbe/watermelondb/Model'; export interface IRole { id: string; - description: string; + description?: string; } export type TRoleModel = IRole & Model; diff --git a/app/definitions/ISettings.ts b/app/definitions/ISettings.ts index 513f6d2b55c..1fbb63ac8dd 100644 --- a/app/definitions/ISettings.ts +++ b/app/definitions/ISettings.ts @@ -2,11 +2,11 @@ import Model from '@nozbe/watermelondb/Model'; export interface ISettings { id: string; - valueAsString: string; - valueAsBoolean: boolean; - valueAsNumber: number; - valueAsArray: string[]; - _updatedAt: Date; + valueAsString?: string; + valueAsBoolean?: boolean; + valueAsNumber?: number; + valueAsArray?: string[]; + _updatedAt?: Date; } export type TSettingsModel = ISettings & Model; diff --git a/app/definitions/ISlashCommand.ts b/app/definitions/ISlashCommand.ts index d98610ad181..a859448df74 100644 --- a/app/definitions/ISlashCommand.ts +++ b/app/definitions/ISlashCommand.ts @@ -2,10 +2,10 @@ import Model from '@nozbe/watermelondb/Model'; export interface ISlashCommand { id: string; - params: string; - description: string; - clientOnly: boolean; - providesPreview: boolean; + params?: string; + description?: string; + clientOnly?: boolean; + providesPreview?: boolean; appId?: string; } diff --git a/app/definitions/IUpload.ts b/app/definitions/IUpload.ts index a8d7a9a6ae1..6ff03c519f7 100644 --- a/app/definitions/IUpload.ts +++ b/app/definitions/IUpload.ts @@ -2,12 +2,12 @@ import Model from '@nozbe/watermelondb/Model'; export interface IUpload { id: string; - path: string; - name: string; - description: string; + path?: string; + name?: string; + description?: string; size: number; - type: string; - store: string; + type?: string; + store?: string; progress: number; error: boolean; subscription: { id: string }; From ae3efe127ef09f4eb15ea1e26678b410e6bed2c8 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 29 Dec 2021 14:23:38 -0300 Subject: [PATCH 36/51] Chore: Migrate Database to Typescript --- app/lib/database/{index.js => index.ts} | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) rename app/lib/database/{index.js => index.ts} (86%) diff --git a/app/lib/database/index.js b/app/lib/database/index.ts similarity index 86% rename from app/lib/database/index.js rename to app/lib/database/index.ts index ee02e6212d8..0bc11e4c4b5 100644 --- a/app/lib/database/index.js +++ b/app/lib/database/index.ts @@ -32,9 +32,9 @@ if (__DEV__ && isIOS) { console.log(appGroupPath); } -const getDatabasePath = name => `${appGroupPath}${name}${isOfficial ? '' : '-experimental'}.db`; +const getDatabasePath = (name: string) => `${appGroupPath}${name}${isOfficial ? '' : '-experimental'}.db`; -export const getDatabase = (database = '') => { +export const getDatabase = (database = ''): Database => { const path = database.replace(/(^\w+:|^)\/\//, '').replace(/\//g, '.'); const dbName = getDatabasePath(path); @@ -64,8 +64,14 @@ export const getDatabase = (database = '') => { }); }; +interface IDatabases { + shareDB?: Database; + serversDB: Database; + activeDB?: Database; +} + class DB { - databases = { + databases: IDatabases = { serversDB: new Database({ adapter: new SQLiteAdapter({ dbName: getDatabasePath('default'), @@ -76,8 +82,9 @@ class DB { }) }; - get active() { - return this.databases.shareDB || this.databases.activeDB; + // Expected at least one database + get active(): Database { + return this.databases.shareDB || this.databases.activeDB!; } get share() { @@ -119,7 +126,7 @@ class DB { }); } - setActiveDB(database) { + setActiveDB(database: string) { this.databases.activeDB = getDatabase(database); } } From 74de6a07102355360393c014d9269bb958e127f2 Mon Sep 17 00:00:00 2001 From: Reinaldo Neto Date: Wed, 29 Dec 2021 21:57:04 -0300 Subject: [PATCH 37/51] Created Interfaces.ts for database and fix lint errors --- app/containers/Avatar/index.tsx | 9 ++- app/containers/EmojiPicker/index.tsx | 9 +-- app/containers/MessageActions/Header.tsx | 12 +++- app/containers/MessageActions/index.tsx | 17 ++--- app/containers/MessageErrorActions.tsx | 4 +- app/containers/message/utils.ts | 3 +- app/definitions/IFrequentlyUsedEmoji.ts | 2 +- app/lib/database/index.ts | 11 ++-- app/lib/database/interfaces.ts | 64 +++++++++++++++++++ .../CreateDiscussionView/SelectChannel.tsx | 3 +- .../CreateDiscussionView/SelectUsers.tsx | 4 +- app/views/NewMessageView.tsx | 4 +- .../NotificationPreferencesView/index.tsx | 4 +- app/views/SelectedUsersView.tsx | 4 +- 14 files changed, 117 insertions(+), 33 deletions(-) create mode 100644 app/lib/database/interfaces.ts diff --git a/app/containers/Avatar/index.tsx b/app/containers/Avatar/index.tsx index 9c95db83902..07c1b83a1e4 100644 --- a/app/containers/Avatar/index.tsx +++ b/app/containers/Avatar/index.tsx @@ -1,9 +1,11 @@ import React from 'react'; import { connect } from 'react-redux'; import { Q } from '@nozbe/watermelondb'; +import { Observable } from 'rxjs'; import database from '../../lib/database'; import { getUserSelector } from '../../selectors/login'; +import { TSubscriptionModel } from '../../definitions/ISubscription'; import Avatar from './Avatar'; import { IAvatar } from './interfaces'; @@ -59,15 +61,16 @@ class AvatarContainer extends React.Component, any> { record = user; } else { const { rid } = this.props; - record = await subsCollection.find(rid); + record = await subsCollection.find(rid!); } } catch { // Record not found } if (record) { - const observable = record.observe(); - this.subscription = observable.subscribe((r: any) => { + // TODO: Refactor this + const observable = record.observe() as Observable; + this.subscription = observable.subscribe(r => { const { avatarETag } = r; if (this.mounted) { this.setState({ avatarETag }); diff --git a/app/containers/EmojiPicker/index.tsx b/app/containers/EmojiPicker/index.tsx index 12217cf9521..b129e6f4d6a 100644 --- a/app/containers/EmojiPicker/index.tsx +++ b/app/containers/EmojiPicker/index.tsx @@ -14,6 +14,7 @@ import database from '../../lib/database'; import { emojisByCategory } from '../../emojis'; import protectedFunction from '../../lib/methods/helpers/protectedFunction'; import shortnameToUnicode from '../../utils/shortnameToUnicode'; +import { TFrequentlyUsedEmojiModel } from '../../definitions/IFrequentlyUsedEmoji'; import log from '../../utils/log'; import { themes } from '../../constants/colors'; import { withTheme } from '../../theme'; @@ -36,7 +37,7 @@ interface IEmojiPickerProps { } interface IEmojiPickerState { - frequentlyUsed: []; + frequentlyUsed: TFrequentlyUsedEmojiModel[]; customEmojis: any; show: boolean; width: number | null; @@ -114,7 +115,7 @@ class EmojiPicker extends Component { // Do nothing } - await db.action(async () => { + await db.write(async () => { if (freqEmojiRecord) { await freqEmojiRecord.update((f: any) => { f.count += 1; @@ -132,8 +133,8 @@ class EmojiPicker extends Component { updateFrequentlyUsed = async () => { const db = database.active; const frequentlyUsedRecords = await db.get('frequently_used_emojis').query().fetch(); - let frequentlyUsed: any = orderBy(frequentlyUsedRecords, ['count'], ['desc']); - frequentlyUsed = frequentlyUsed.map((item: IEmoji) => { + let frequentlyUsed = orderBy(frequentlyUsedRecords, ['count'], ['desc']); + frequentlyUsed = frequentlyUsed.map(item => { if (item.isCustom) { return { content: item.content, extension: item.extension, isCustom: item.isCustom }; } diff --git a/app/containers/MessageActions/Header.tsx b/app/containers/MessageActions/Header.tsx index d3556ccb6bd..c07618144ea 100644 --- a/app/containers/MessageActions/Header.tsx +++ b/app/containers/MessageActions/Header.tsx @@ -10,6 +10,7 @@ import database from '../../lib/database'; import { Button } from '../ActionSheet'; import { useDimensions } from '../../dimensions'; import sharedStyles from '../../views/Styles'; +import { TFrequentlyUsedEmojiModel } from '../../definitions/IFrequentlyUsedEmoji'; import { IEmoji } from '../EmojiPicker/interfaces'; interface IHeader { @@ -63,7 +64,14 @@ const styles = StyleSheet.create({ const keyExtractor = (item: any) => item?.id || item; -const DEFAULT_EMOJIS = ['clap', '+1', 'heart_eyes', 'grinning', 'thinking_face', 'smiley']; +const DEFAULT_EMOJIS = [ + 'clap', + '+1', + 'heart_eyes', + 'grinning', + 'thinking_face', + 'smiley' +] as unknown as TFrequentlyUsedEmojiModel[]; const HeaderItem = React.memo(({ item, onReaction, server, theme }: THeaderItem) => (