diff --git a/app/lib/rocketchat.js b/app/lib/rocketchat.js
index 59ee94fc5..92d430d69 100644
--- a/app/lib/rocketchat.js
+++ b/app/lib/rocketchat.js
@@ -798,6 +798,18 @@ const RocketChat = {
prid, pmid, t_name, reply, users, encrypted
});
},
+ getDiscussions({
+ roomId, offset, count, text = ''
+ }) {
+ const params = {
+ roomId,
+ offset,
+ count,
+ text
+ };
+ // RC 2.4.0
+ return this.sdk.get('chat.getDiscussions', params);
+ },
createTeam({
name, users, type, readOnly, broadcast, encrypted
}) {
diff --git a/app/views/DiscussionMessagesView.js b/app/views/DiscussionMessagesView.js
index 595d8f18d..92b4c536b 100644
--- a/app/views/DiscussionMessagesView.js
+++ b/app/views/DiscussionMessagesView.js
@@ -3,13 +3,11 @@ import React, { useEffect, useState } from 'react';
import PropTypes from 'prop-types';
import { FlatList } from 'react-native';
import { useSelector } from 'react-redux';
-import { Q } from '@nozbe/watermelondb';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { HeaderBackButton } from '@react-navigation/stack';
import ActivityIndicator from '../containers/ActivityIndicator';
import I18n from '../i18n';
-import database from '../lib/database';
import StatusBar from '../containers/StatusBar';
import log from '../utils/log';
import debounce from '../utils/debounce';
@@ -23,7 +21,9 @@ import { getHeaderTitlePosition } from '../containers/Header';
import SearchHeader from './ThreadMessagesView/SearchHeader';
import { useTheme } from '../theme';
import Message from '../containers/message';
-import { sanitizeLikeString } from '../lib/database/utils';
+import RocketChat from '../lib/rocketchat';
+
+const API_FETCH_COUNT = 25;
const DiscussionMessagesView = ({ navigation, route }) => {
const rid = route.params?.rid;
@@ -38,6 +38,7 @@ const DiscussionMessagesView = ({ navigation, route }) => {
const isMasterDetail = useSelector(state => state.app.isMasterDetail);
const [loading, setLoading] = useState(false);
const [discussions, setDiscussions] = useState([]);
+ const [search, setSearch] = useState([]);
const [isSearching, setIsSearching] = useState(false);
const { theme } = useTheme();
const insets = useSafeAreaInsets();
@@ -48,39 +49,43 @@ const DiscussionMessagesView = ({ navigation, route }) => {
}
setLoading(true);
-
try {
- const db = database.active;
- const subCollection = db.get('messages');
- const subDiscussions = await subCollection.query(
- Q.where('rid', Q.eq(rid)),
- Q.where('drid', Q.notEq(null))
- );
- setDiscussions(subDiscussions);
+ const result = await RocketChat.getDiscussions({
+ roomId: rid,
+ offset: discussions.length,
+ count: API_FETCH_COUNT
+ });
+
+ if (result.success) {
+ if (isSearching) {
+ setSearch(result.messages);
+ } else {
+ setDiscussions(result.messages);
+ }
+ }
setLoading(false);
} catch (e) {
log(e);
+ setLoading(false);
}
};
const onSearchChangeText = debounce(async(text) => {
+ setLoading(true);
try {
- const db = database.active;
- const whereClause = [
- Q.where('rid', Q.eq(rid)),
- Q.where('drid', Q.notEq(null))
- ];
-
- if (text?.trim()) {
- whereClause.push(Q.where('msg', Q.like(`%${ sanitizeLikeString(text?.trim()) }%`)));
+ const result = await RocketChat.getDiscussions({
+ roomId: rid,
+ offset: search.length,
+ count: API_FETCH_COUNT,
+ text
+ });
+ if (result.success) {
+ setSearch(result.messages);
}
-
- const discussionsMessages = await db
- .get('messages')
- .query(...whereClause);
- setDiscussions(discussionsMessages);
+ setLoading(false);
} catch (e) {
log(e);
+ setLoading(false);
}
}, 300);
@@ -106,7 +111,7 @@ const DiscussionMessagesView = ({ navigation, route }) => {
/>
),
- headerTitle: () => ,
+ headerTitle: () => ,
headerTitleContainerStyle: {
left: headerTitlePosition.left,
right: headerTitlePosition.right
@@ -185,7 +190,7 @@ const DiscussionMessagesView = ({ navigation, route }) => {
item.msg}
style={{ backgroundColor: themes[theme].backgroundColor }}
@@ -194,6 +199,7 @@ const DiscussionMessagesView = ({ navigation, route }) => {
windowSize={10}
initialNumToRender={7}
removeClippedSubviews={isIOS}
+ onEndReached={() => discussions.length > 25 ?? load()}
ItemSeparatorComponent={List.Separator}
ListFooterComponent={loading ? : null}
scrollIndicatorInsets={{ right: 1 }}