@@ -9,15 +9,20 @@ import { DEFAULT_MESSAGE_SET_PAGINATION } from '../../src/constants';
99import { generateUUIDv4 as uuidv4 } from '../../src/utils' ;
1010
1111import { vi , describe , beforeEach , afterEach , it , expect } from 'vitest' ;
12+ import { MockOfflineDB } from './offline-support/MockOfflineDB' ;
1213
1314const toISOString = ( timestampMs ) => new Date ( timestampMs ) . toISOString ( ) ;
1415
1516describe ( 'ChannelState addMessagesSorted' , function ( ) {
1617 let state ;
18+ let client ;
1719
18- beforeEach ( ( ) => {
19- const client = new StreamChat ( ) ;
20- client . userID = 'userId' ;
20+ beforeEach ( async ( ) => {
21+ client = new StreamChat ( ) ;
22+ const offlineDb = new MockOfflineDB ( { client } ) ;
23+
24+ client . setOfflineDBApi ( offlineDb ) ;
25+ await client . offlineDb . init ( client . userID ) ;
2126 const channel = new Channel ( client , 'type' , 'id' , { } ) ;
2227 client . _addChannelConfig ( { cid : channel . cid , config : { } } ) ;
2328 state = new ChannelState ( channel ) ;
@@ -277,6 +282,36 @@ describe('ChannelState addMessagesSorted', function () {
277282 expect ( state . latestMessages [ 2 ] . id ) . to . be . equal ( '14' ) ;
278283 } ) ;
279284
285+ it ( 'should remove blocked messages from the latest messages from the offline database' , ( ) => {
286+ state . addMessagesSorted (
287+ [
288+ generateMsg ( {
289+ id : '12' ,
290+ date : toISOString ( 1200 ) ,
291+ type : 'error' ,
292+ moderation_details : { action : 'MESSAGE_RESPONSE_ACTION_REMOVE' } ,
293+ } ) ,
294+ generateMsg ( {
295+ id : '13' ,
296+ date : toISOString ( 1300 ) ,
297+ type : 'error' ,
298+ moderation : { action : 'remove' } ,
299+ } ) ,
300+ generateMsg ( { id : '14' , date : toISOString ( 1400 ) } ) ,
301+ ] ,
302+ false ,
303+ false ,
304+ true ,
305+ 'latest' ,
306+ ) ;
307+ expect ( state . latestMessages . length ) . to . be . equal ( 3 ) ;
308+ state . filterErrorMessages ( ) ;
309+ expect ( state . latestMessages . length ) . to . be . equal ( 1 ) ;
310+ expect ( client . offlineDb . hardDeleteMessage ) . toHaveBeenCalledTimes ( 2 ) ;
311+ expect ( client . offlineDb . hardDeleteMessage ) . toHaveBeenCalledWith ( { id : '12' } ) ;
312+ expect ( client . offlineDb . hardDeleteMessage ) . toHaveBeenCalledWith ( { id : '13' } ) ;
313+ } ) ;
314+
280315 it ( 'adds message page sorted' , ( ) => {
281316 // load first page
282317 state . addMessagesSorted (
0 commit comments