Skip to content

Commit a12b27b

Browse files
authored
fix: Refresh channel before fetching message search list (#408)
* If you set the `channel.invitedAt` with the other timestamp by force you will get the message search list which is fetched from the timestamp * Refresh the channel before fetching message search list, to get the real value of the channel property
1 parent f958df3 commit a12b27b

File tree

1 file changed

+32
-30
lines changed

1 file changed

+32
-30
lines changed

src/smart-components/MessageSearch/context/hooks/useGetSearchedMessages.ts

+32-30
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,41 @@ function useGetSearchedMessages(
4646
});
4747
if (sdk && channelUrl && sdk.createMessageSearchQuery && currentChannel) {
4848
if (requestString) {
49-
const inputSearchMessageQueryObject: MessageSearchQueryParams = {
50-
order: MessageSearchOrder.TIMESTAMP,
51-
channelUrl,
52-
messageTimestampFrom: currentChannel.invitedAt,
53-
keyword: requestString,
54-
...messageSearchQuery,
55-
};
56-
const createdQuery = sdk.createMessageSearchQuery(inputSearchMessageQueryObject);
57-
createdQuery.next().then((messages) => {
58-
logger.info('MessageSearch | useGetSearchedMessages: succeeded getting messages', messages);
59-
messageSearchDispatcher({
60-
type: messageActionTypes.GET_SEARCHED_MESSAGES,
61-
payload: {
62-
messages,
63-
createdQuery,
64-
},
49+
currentChannel.refresh().then((channel) => {
50+
const inputSearchMessageQueryObject: MessageSearchQueryParams = {
51+
order: MessageSearchOrder.TIMESTAMP,
52+
channelUrl,
53+
messageTimestampFrom: channel.invitedAt,
54+
keyword: requestString,
55+
...messageSearchQuery,
56+
};
57+
const createdQuery = sdk.createMessageSearchQuery(inputSearchMessageQueryObject);
58+
createdQuery.next().then((messages) => {
59+
logger.info('MessageSearch | useGetSearchedMessages: succeeded getting messages', messages);
60+
messageSearchDispatcher({
61+
type: messageActionTypes.GET_SEARCHED_MESSAGES,
62+
payload: {
63+
messages,
64+
createdQuery,
65+
},
66+
});
67+
if (onResultLoaded && typeof onResultLoaded === 'function') {
68+
onResultLoaded(messages, null);
69+
}
70+
}).catch((error) => {
71+
logger.warning('MessageSearch | useGetSearchedMessages: getting failed', error);
72+
messageSearchDispatcher({
73+
type: messageActionTypes.SET_QUERY_INVALID,
74+
payload: null,
75+
});
76+
if (onResultLoaded && typeof onResultLoaded === 'function') {
77+
onResultLoaded(null, error);
78+
}
6579
});
66-
if (onResultLoaded && typeof onResultLoaded === 'function') {
67-
onResultLoaded(messages, null);
68-
}
69-
}).catch((error) => {
70-
logger.warning('MessageSearch | useGetSearchedMessages: getting failed', error);
7180
messageSearchDispatcher({
72-
type: messageActionTypes.SET_QUERY_INVALID,
73-
payload: null,
81+
type: messageActionTypes.START_GETTING_SEARCHED_MESSAGES,
82+
payload: createdQuery,
7483
});
75-
if (onResultLoaded && typeof onResultLoaded === 'function') {
76-
onResultLoaded(null, error);
77-
}
78-
});
79-
messageSearchDispatcher({
80-
type: messageActionTypes.START_GETTING_SEARCHED_MESSAGES,
81-
payload: createdQuery,
8284
});
8385
} else {
8486
logger.info('MessageSearch | useGetSeasrchedMessages: search string is empty');

0 commit comments

Comments
 (0)