11import { captureSentryError } from '@mezon/logger' ;
2- import type { IClan , LoadingStatus } from '@mezon/utils' ;
2+ import type { ApiChannelMessageHeaderWithChannel , IClan , LoadingStatus } from '@mezon/utils' ;
33import { FOR_1_HOUR_SEC , LIMIT_CLAN_ITEM , ONE_MILISECONDS } from '@mezon/utils' ;
44import type { EntityState , PayloadAction } from '@reduxjs/toolkit' ;
55import { createAsyncThunk , createEntityAdapter , createSelector , createSlice } from '@reduxjs/toolkit' ;
@@ -18,6 +18,7 @@ import { accountActions } from '../account/account.slice';
1818import { setUserAvatarOverride } from '../avatarOverride/avatarOverride' ;
1919import type { CacheMetadata } from '../cache-metadata' ;
2020import { createApiKey , createCacheMetadata , markApiFirstCalled , shouldForceApiCall } from '../cache-metadata' ;
21+ import type { ChannelMetaEntity } from '../channels/channelmeta.slice' ;
2122import { channelMetaActions } from '../channels/channelmeta.slice' ;
2223import { channelsActions } from '../channels/channels.slice' ;
2324import { 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 ) {
0 commit comments