Skip to content

Commit f326bd0

Browse files
fix: replace deprecated MongoDB query/field params with explicit REST params (#1321)
1 parent f3b2a0f commit f326bd0

3 files changed

Lines changed: 20 additions & 57 deletions

File tree

packages/api/src/EmbeddedChatApi.ts

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -544,35 +544,23 @@ export default class EmbeddedChatApi {
544544
this.sdk.connection.close();
545545
}
546546

547-
/**
548-
* @param {boolean} anonymousMode
549-
* @param {Object} options This object should include query or fields.
550-
* query - json object which accepts MongoDB query operators.
551-
* fields - json object with properties that have either 1 or 0 to include them or exclude them
552-
* @returns messages
553-
*/
554547
async getMessages(
555548
anonymousMode = false,
556549
options: {
557-
query?: object | undefined;
558-
field?: object | undefined;
559-
} = {
560-
query: undefined,
561-
field: undefined,
562-
},
550+
oldest?: string;
551+
latest?: string;
552+
count?: number;
553+
} = {},
563554
isChannelPrivate = false
564555
) {
565556
const roomType = isChannelPrivate ? "groups" : "channels";
566557
const endp = anonymousMode ? "anonymousread" : "messages";
567-
const query = options?.query
568-
? `&query=${JSON.stringify(options.query)}`
569-
: "";
570-
const field = options?.field
571-
? `&field=${JSON.stringify(options.field)}`
572-
: "";
558+
const oldest = options?.oldest ? `&oldest=${options.oldest}` : "";
559+
const latest = options?.latest ? `&latest=${options.latest}` : "";
560+
const count = options?.count != null ? `&count=${options.count}` : "";
573561
try {
574562
return await this._restRequest(
575-
`/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}`
563+
`/v1/${roomType}.${endp}?roomId=${this.rid}${oldest}${latest}${count}`
576564
);
577565
} catch (err: any) {
578566
console.error(err instanceof Error ? err.message : err);
@@ -583,28 +571,22 @@ export default class EmbeddedChatApi {
583571
async getOlderMessages(
584572
anonymousMode = false,
585573
options: {
586-
query?: object | undefined;
587-
field?: object | undefined;
574+
oldest?: string;
575+
latest?: string;
576+
count?: number;
588577
offset?: number;
589-
} = {
590-
query: undefined,
591-
field: undefined,
592-
offset: 50,
593-
},
578+
} = {},
594579
isChannelPrivate = false
595580
) {
596581
const roomType = isChannelPrivate ? "groups" : "channels";
597582
const endp = anonymousMode ? "anonymousread" : "messages";
598-
const query = options?.query
599-
? `&query=${JSON.stringify(options.query)}`
600-
: "";
601-
const field = options?.field
602-
? `&field=${JSON.stringify(options.field)}`
603-
: "";
604-
const offset = options?.offset ? options.offset : 0;
583+
const oldest = options?.oldest ? `&oldest=${options.oldest}` : "";
584+
const latest = options?.latest ? `&latest=${options.latest}` : "";
585+
const count = options?.count != null ? `&count=${options.count}` : "";
586+
const offset = options?.offset ? `&offset=${options.offset}` : "&offset=0";
605587
try {
606588
return await this._restRequest(
607-
`/v1/${roomType}.${endp}?roomId=${this.rid}${query}${field}&offset=${offset}`
589+
`/v1/${roomType}.${endp}?roomId=${this.rid}${oldest}${latest}${count}${offset}`
608590
);
609591
} catch (err: any) {
610592
console.error(err instanceof Error ? err.message : String(err));

packages/react/src/hooks/useFetchChatData.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
} from '../store';
1111

1212
const useFetchChatData = (showRoles) => {
13-
const { RCInstance, ECOptions } = useContext(RCContext);
13+
const { RCInstance } = useContext(RCContext);
1414
const setMemberRoles = useMemberStore((state) => state.setMemberRoles);
1515
const isChannelPrivate = useChannelStore((state) => state.isChannelPrivate);
1616
const setMessages = useMessageStore((state) => state.setMessages);
@@ -129,15 +129,7 @@ const useFetchChatData = (showRoles) => {
129129

130130
const { messages, count } = await RCInstance.getMessages(
131131
anonymousMode,
132-
ECOptions?.enableThreads
133-
? {
134-
query: {
135-
tmid: {
136-
$exists: false,
137-
},
138-
},
139-
}
140-
: undefined,
132+
undefined,
141133
anonymousMode ? false : isChannelPrivate
142134
);
143135

@@ -175,7 +167,6 @@ const useFetchChatData = (showRoles) => {
175167
[
176168
isUserAuthenticated,
177169
RCInstance,
178-
ECOptions?.enableThreads,
179170
isChannelPrivate,
180171
showRoles,
181172
setMessages,

packages/react/src/views/ChatBody/ChatBody.js

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -230,16 +230,7 @@ const ChatBody = ({
230230
try {
231231
const olderMessages = await RCInstance.getOlderMessages(
232232
anonymousMode,
233-
ECOptions?.enableThreads
234-
? {
235-
query: {
236-
tmid: {
237-
$exists: false,
238-
},
239-
},
240-
offset,
241-
}
242-
: undefined,
233+
{ offset },
243234
anonymousMode ? false : isChannelPrivate
244235
);
245236
const messageList = messageListRef.current;
@@ -286,7 +277,6 @@ const ChatBody = ({
286277
hasMoreMessages,
287278
RCInstance,
288279
isChannelPrivate,
289-
ECOptions?.enableThreads,
290280
loadingOlderMessages,
291281
setScrollPosition,
292282
setIsUserScrolledUp,

0 commit comments

Comments
 (0)