From c0d5a84ccd7be05f7ab517e7d6133f80f8964e61 Mon Sep 17 00:00:00 2001 From: Diego Mello Date: Mon, 28 Nov 2022 16:26:45 -0300 Subject: [PATCH] First "asPlain" test --- app/lib/database/model/Subscription.js | 64 ++++++++++++++++++++++++++ app/views/RoomsListView/index.tsx | 36 +-------------- 2 files changed, 65 insertions(+), 35 deletions(-) diff --git a/app/lib/database/model/Subscription.js b/app/lib/database/model/Subscription.js index 26fb764d7..5938e1ab0 100644 --- a/app/lib/database/model/Subscription.js +++ b/app/lib/database/model/Subscription.js @@ -136,4 +136,68 @@ export default class Subscription extends Model { @field('on_hold') onHold; @json('source', sanitizer) source; + + // TODO: if this is proven to be the best way to do it, we should use TS to map through the properties + asPlain() { + return { + _id: this._id, + f: this.f, + t: this.t, + ts: this.ts, + ls: this.ls, + name: this.name, + fname: this.fname, + rid: this.rid, + open: this.open, + alert: this.alert, + unread: this.unread, + userMentions: this.userMentions, + groupMentions: this.groupMentions, + roomUpdatedAt: this.roomUpdatedAt, + ro: this.ro, + lastOpen: this.lastOpen, + description: this.description, + announcement: this.announcement, + bannerClosed: this.bannerClosed, + topic: this.topic, + blocked: this.blocked, + blocker: this.blocker, + reactWhenReadOnly: this.reactWhenReadOnly, + archived: this.archived, + joinCodeRequired: this.joinCodeRequired, + notifications: this.notifications, + broadcast: this.broadcast, + prid: this.prid, + draftMessage: this.draftMessage, + lastThreadSync: this.lastThreadSync, + jitsiTimeout: this.jitsiTimeout, + autoTranslate: this.autoTranslate, + autoTranslateLanguage: this.autoTranslateLanguage, + hideUnreadStatus: this.hideUnreadStatus, + hideMentionStatus: this.hideMentionStatus, + departmentId: this.departmentId, + E2EKey: this.E2EKey, + encrypted: this.encrypted, + e2eKeyId: this.e2eKeyId, + avatarETag: this.avatarETag, + teamId: this.teamId, + teamMain: this.teamMain, + onHold: this.onHold, + roles: this.roles, + tunread: this.tunread, + tunreadUser: this.tunreadUser, + tunreadGroup: this.tunreadGroup, + muted: this.muted, + ignored: this.ignored, + lastMessage: this.lastMessage, + sysMes: this.sysMes, + uids: this.uids, + usernames: this.usernames, + visitor: this.visitor, + servedBy: this.servedBy, + livechatData: this.livechatData, + tags: this.tags, + source: this.source + }; + } } diff --git a/app/views/RoomsListView/index.tsx b/app/views/RoomsListView/index.tsx index 5e75d4dac..475651b35 100644 --- a/app/views/RoomsListView/index.tsx +++ b/app/views/RoomsListView/index.tsx @@ -522,41 +522,7 @@ class RoomsListView extends React.Component { console.log('update query'); let tempChats = [] as TSubscriptionModel[]; - let chats = data.map(item => ({ - rid: item.rid, - t: item.t, - prid: item.prid, - name: item.name, - fname: item.fname, - usernames: item.usernames, - // avatar: item.avatar, - // testID: item.testID, - status: item.status, - // isGroupChat: item.isGroupChat, - // isRead: item.isRead, - teamMain: item.teamMain, - roomUpdatedAt: item.roomUpdatedAt, - // date: item.date, - // accessibilityLabel: item.accessibilityLabel, - lastMessage: item.lastMessage, - f: item.f, - alert: item.alert, - hideUnreadStatus: item.hideUnreadStatus, - unread: item.unread, - userMentions: item.userMentions, - groupMentions: item.groupMentions, - tunread: item.tunread, - tunreadUser: item.tunreadUser, - tunreadGroup: item.tunreadGroup, - // size: item.size, - // sourceType: item.sourceType, - hideMentionStatus: item.hideMentionStatus, - onHold: item.onHold, - v: item.v, - visitor: item.visitor, - archived: item.archived, - open: item.open - })); + let chats = data.map(item => item.asPlain()); let omnichannelsUpdate: string[] = []; const isOmnichannelAgent = user?.roles?.includes('livechat-agent');