Skip to content

Commit b59288b

Browse files
committed
fix get lastMessage from badgeCount
1 parent ce85568 commit b59288b

2 files changed

Lines changed: 19 additions & 20 deletions

File tree

libs/store/src/lib/clans/clans.slice.ts

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { captureSentryError } from '@mezon/logger';
2-
import type { IClan, LoadingStatus } from '@mezon/utils';
2+
import type { ApiChannelMessageHeaderWithChannel, IClan, LoadingStatus } from '@mezon/utils';
33
import { FOR_1_HOUR_SEC, LIMIT_CLAN_ITEM, ONE_MILISECONDS } from '@mezon/utils';
44
import type { EntityState, PayloadAction } from '@reduxjs/toolkit';
55
import { createAsyncThunk, createEntityAdapter, createSelector, createSlice } from '@reduxjs/toolkit';
@@ -18,6 +18,7 @@ import { accountActions } from '../account/account.slice';
1818
import { setUserAvatarOverride } from '../avatarOverride/avatarOverride';
1919
import type { CacheMetadata } from '../cache-metadata';
2020
import { createApiKey, createCacheMetadata, markApiFirstCalled, shouldForceApiCall } from '../cache-metadata';
21+
import type { ChannelMetaEntity } from '../channels/channelmeta.slice';
2122
import { channelMetaActions } from '../channels/channelmeta.slice';
2223
import { channelsActions } from '../channels/channels.slice';
2324
import { fetchClanMembersWithStatus, usersClanActions } from '../clanMembers/clan.members';
@@ -173,8 +174,23 @@ export const listChannelBadgeCount = createAsyncThunk('clans/listChannelBadgeCou
173174
'channel_badge_count'
174175
);
175176

176-
if ((response as any)?.channeldesc && clanId && !state.clans.checkJoinList[clanId]) {
177-
thunkAPI.dispatch(channelMetaActions.updateBulkChannelMetadata({ data: (response as any)?.channeldesc, clanId }));
177+
if (response.channeldesc && clanId && !state.clans.checkJoinList[clanId]) {
178+
thunkAPI.dispatch(channelMetaActions.updateBulkChannelMetadata({ data: response?.channeldesc as ChannelMetaEntity[], clanId }));
179+
180+
const listLastMessage = (response.channeldesc ?? []).reduce<ApiChannelMessageHeaderWithChannel[]>((acc, channel) => {
181+
if (channel.channel_id) {
182+
acc.push({
183+
channel_id: channel.channel_id,
184+
content: channel.last_sent_message?.content,
185+
id: channel.last_sent_message?.id,
186+
sender_id: channel.last_sent_message?.sender_id,
187+
timestamp_seconds: channel.last_seen_message?.timestamp_seconds
188+
});
189+
}
190+
return acc;
191+
}, []);
192+
193+
thunkAPI.dispatch(messagesActions.setManyLastMessages(listLastMessage));
178194
}
179195
return { channeldesc: (response as any)?.channeldesc as ApiChannelDescription[], clanId };
180196
} catch (error) {

libs/store/src/lib/messages/messages.slice.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,6 @@ export const fetchMessagesCached = async (
234234
};
235235
}
236236

237-
// const response = await fetchDataWithSocketFallback(
238-
// ensuredMezon,
239-
// {
240-
// api_name: 'ListChannelMessages',
241-
// list_channel_message_req: {
242-
// channel_id: channelId,
243-
// message_id: messageId,
244-
// direction,
245-
// clan_id: clanId,
246-
// topic_id: topicId,
247-
// limit: LIMIT_MESSAGE
248-
// }
249-
// },
250-
// () => ensuredMezon.client.listChannelMessages(ensuredMezon.session, clanId, channelId, messageId, direction, LIMIT_MESSAGE, topicId),
251-
// 'channel_message_list'
252-
// );
253-
254237
const response = await withRetry(
255238
(session) =>
256239
ensuredMezon.client.listChannelMessages(session, clanId, channelId, topicId ? undefined : messageId, direction, LIMIT_MESSAGE, topicId),

0 commit comments

Comments
 (0)