Add Discussions to ThreadMessagesView

This commit is contained in:
Gerzon Z 2021-07-19 11:33:09 -04:00
parent a0eecdcaf4
commit 659f2c8646
3 changed files with 42 additions and 19 deletions

View File

@ -688,6 +688,7 @@
"No_threads": "There are no threads", "No_threads": "There are no threads",
"No_threads_following": "You are not following any threads", "No_threads_following": "You are not following any threads",
"No_threads_unread": "There are no unread threads", "No_threads_unread": "There are no unread threads",
"No_discussions": "There are no discussions",
"Messagebox_Send_to_channel": "Send to channel", "Messagebox_Send_to_channel": "Send to channel",
"Leader": "Leader", "Leader": "Leader",
"Moderator": "Moderator", "Moderator": "Moderator",

View File

@ -903,7 +903,7 @@ class RoomActionsView extends React.Component {
room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue room, membersCount, canViewMembers, canAddUser, canInviteUser, joined, canAutoTranslate, canForwardGuest, canReturnQueue
} = this.state; } = this.state;
const { const {
rid, t rid, t, prid
} = room; } = room;
const isGroupChat = RocketChat.isGroupChat(room); const isGroupChat = RocketChat.isGroupChat(room);
@ -974,14 +974,20 @@ class RoomActionsView extends React.Component {
) )
: null} : null}
{['c', 'p'].includes(t) {['c', 'p'].includes(t) && !prid
? ( ? (
<> <>
<List.Item <List.Item
title='Discussions' title='Discussions'
onPress={() => this.onPressTouchable({ onPress={() => this.onPressTouchable({
route: 'ThreadMessagesView', route: 'ThreadMessagesView',
params: { rid, t, name: 'Discussions' } params: {
rid,
t,
prid,
name: 'Discussions',
isDiscussion: true
}
})} })}
testID='room-actions-discussions' testID='room-actions-discussions'
left={() => <List.Icon name='discussions' />} left={() => <List.Icon name='discussions' />}

View File

@ -55,6 +55,9 @@ class ThreadMessagesView extends React.Component {
this.mounted = false; this.mounted = false;
this.rid = props.route.params?.rid; this.rid = props.route.params?.rid;
this.t = props.route.params?.t; 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 = { this.state = {
loading: false, loading: false,
end: false, end: false,
@ -131,7 +134,7 @@ class ThreadMessagesView extends React.Component {
/> />
), ),
headerTitleAlign: 'center', headerTitleAlign: 'center',
headerTitle: I18n.t('Threads'), headerTitle: this.isDiscussion ? this.name : I18n.t('Threads'),
headerTitleContainerStyle: { headerTitleContainerStyle: {
left: null, left: null,
right: null right: null
@ -296,6 +299,18 @@ class ThreadMessagesView extends React.Component {
this.setState({ loading: true }); this.setState({ loading: true });
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 { try {
const result = await RocketChat.getThreadsList({ const result = await RocketChat.getThreadsList({
rid: this.rid, count: API_FETCH_COUNT, offset: messages.length, text: searchText rid: this.rid, count: API_FETCH_COUNT, offset: messages.length, text: searchText
@ -311,6 +326,7 @@ class ThreadMessagesView extends React.Component {
log(e); log(e);
this.setState({ loading: false, end: true }); this.setState({ loading: false, end: true });
} }
}
}, 300) }, 300)
// eslint-disable-next-line react/sort-comp // eslint-disable-next-line react/sort-comp
@ -434,7 +450,7 @@ class ThreadMessagesView extends React.Component {
renderHeader = () => { renderHeader = () => {
const { messages, currentFilter } = this.state; const { messages, currentFilter } = this.state;
if (!messages.length) { if (!messages.length || this.isDiscussion) {
return null; return null;
} }
@ -458,7 +474,7 @@ class ThreadMessagesView extends React.Component {
} else if (currentFilter === FILTER.UNREAD) { } else if (currentFilter === FILTER.UNREAD) {
text = I18n.t('No_threads_unread'); text = I18n.t('No_threads_unread');
} else { } else {
text = I18n.t('No_threads'); text = this.isDiscussion ? I18n.t('No_discussions') : I18n.t('No_threads');
} }
return ( return (
<> <>