From 659f2c864694794dabc53bf1a8c6fe597fe82ca9 Mon Sep 17 00:00:00 2001 From: Gerzon Z Date: Mon, 19 Jul 2021 11:33:09 -0400 Subject: [PATCH] Add Discussions to ThreadMessagesView --- app/i18n/locales/en.json | 1 + app/views/RoomActionsView/index.js | 12 +++++-- app/views/ThreadMessagesView/index.js | 48 ++++++++++++++++++--------- 3 files changed, 42 insertions(+), 19 deletions(-) diff --git a/app/i18n/locales/en.json b/app/i18n/locales/en.json index 19403166..fd1ad7d5 100644 --- a/app/i18n/locales/en.json +++ b/app/i18n/locales/en.json @@ -688,6 +688,7 @@ "No_threads": "There are no threads", "No_threads_following": "You are not following any threads", "No_threads_unread": "There are no unread threads", + "No_discussions": "There are no discussions", "Messagebox_Send_to_channel": "Send to channel", "Leader": "Leader", "Moderator": "Moderator", diff --git a/app/views/RoomActionsView/index.js b/app/views/RoomActionsView/index.js index b2b77926..e4412600 100644 --- a/app/views/RoomActionsView/index.js +++ b/app/views/RoomActionsView/index.js @@ -903,7 +903,7 @@ class RoomActionsView extends React.Component { room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue } = this.state; const { - rid, t + rid, t, prid } = room; const isGroupChat = RocketChat.isGroupChat(room); @@ -974,14 +974,20 @@ class RoomActionsView extends React.Component { ) : null} - {['c', 'p'].includes(t) + {['c', 'p'].includes(t) && !prid ? ( <> this.onPressTouchable({ route: 'ThreadMessagesView', - params: { rid, t, name: 'Discussions' } + params: { + rid, + t, + prid, + name: 'Discussions', + isDiscussion: true + } })} testID='room-actions-discussions' left={() => } diff --git a/app/views/ThreadMessagesView/index.js b/app/views/ThreadMessagesView/index.js index 48cab9c9..2b200346 100644 --- a/app/views/ThreadMessagesView/index.js +++ b/app/views/ThreadMessagesView/index.js @@ -55,6 +55,9 @@ class ThreadMessagesView extends React.Component { this.mounted = false; this.rid = props.route.params?.rid; this.t = props.route.params?.t; + this.name = props.route.params?.name; + this.isDiscussion = props.route.params?.isDiscussion; + this.prid = props.route.params?.prid; this.state = { loading: false, end: false, @@ -131,7 +134,7 @@ class ThreadMessagesView extends React.Component { /> ), headerTitleAlign: 'center', - headerTitle: I18n.t('Threads'), + headerTitle: this.isDiscussion ? this.name : I18n.t('Threads'), headerTitleContainerStyle: { left: null, right: null @@ -296,20 +299,33 @@ class ThreadMessagesView extends React.Component { this.setState({ loading: true }); - try { - const result = await RocketChat.getThreadsList({ - rid: this.rid, count: API_FETCH_COUNT, offset: messages.length, text: searchText - }); - if (result.success) { - this.updateThreads({ update: result.threads, lastThreadSync }); - this.setState({ - loading: false, - end: result.count < API_FETCH_COUNT - }); + if (this.isDiscussion) { + try { + const db = database.active; + const subCollection = db.get('subscriptions'); + const discussions = await subCollection.query( + Q.where('prid', Q.eq(this.prid)) + ); + this.setState({ loading: false, displayingThreads: discussions }); + } catch (e) { + log(e); + } + } else { + try { + const result = await RocketChat.getThreadsList({ + rid: this.rid, count: API_FETCH_COUNT, offset: messages.length, text: searchText + }); + if (result.success) { + this.updateThreads({ update: result.threads, lastThreadSync }); + this.setState({ + loading: false, + end: result.count < API_FETCH_COUNT + }); + } + } catch (e) { + log(e); + this.setState({ loading: false, end: true }); } - } catch (e) { - log(e); - this.setState({ loading: false, end: true }); } }, 300) @@ -434,7 +450,7 @@ class ThreadMessagesView extends React.Component { renderHeader = () => { const { messages, currentFilter } = this.state; - if (!messages.length) { + if (!messages.length || this.isDiscussion) { return null; } @@ -458,7 +474,7 @@ class ThreadMessagesView extends React.Component { } else if (currentFilter === FILTER.UNREAD) { text = I18n.t('No_threads_unread'); } else { - text = I18n.t('No_threads'); + text = this.isDiscussion ? I18n.t('No_discussions') : I18n.t('No_threads'); } return ( <>