File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { generateMessage , generateReaction , generateUser } from 'mock-builders' ;
22import { fromPartial } from '@total-typescript/shoehorn' ;
33import type { TFunction } from 'i18next' ;
4- import type { ChannelConfigWithInfo , MessageResponse , Mute } from 'stream-chat' ;
4+ import type {
5+ ChannelConfigWithInfo ,
6+ LocalMessage ,
7+ MessageResponse ,
8+ Mute ,
9+ } from 'stream-chat' ;
510import type { StreamChat } from 'stream-chat' ;
611import {
712 countReactions ,
@@ -15,6 +20,7 @@ import {
1520 getMessageActions ,
1621 getNonImageAttachments ,
1722 getReadByTooltipText ,
23+ isMessageBlocked ,
1824 isUserMuted ,
1925 mapToUserNameOrId ,
2026 MESSAGE_ACTIONS ,
@@ -543,4 +549,31 @@ describe('Message utils', () => {
543549 ) ;
544550 } ) ;
545551 } ) ;
552+
553+ describe ( 'isMessageBlocked function' , ( ) => {
554+ it ( 'returns true when message.shadowed is true' , ( ) => {
555+ const message = fromPartial < LocalMessage > ( {
556+ shadowed : true ,
557+ type : 'regular' ,
558+ } ) ;
559+ expect ( isMessageBlocked ( message ) ) . toBe ( true ) ;
560+ } ) ;
561+
562+ it ( 'returns true for moderation remove error messages when not shadowed' , ( ) => {
563+ const message = fromPartial < LocalMessage > ( {
564+ moderation : { action : 'remove' } ,
565+ shadowed : false ,
566+ type : 'error' ,
567+ } ) ;
568+ expect ( isMessageBlocked ( message ) ) . toBe ( true ) ;
569+ } ) ;
570+
571+ it ( 'returns false when message is not shadowed and not a moderation remove error' , ( ) => {
572+ const message = fromPartial < LocalMessage > ( {
573+ shadowed : false ,
574+ type : 'regular' ,
575+ } ) ;
576+ expect ( isMessageBlocked ( message ) ) . toBe ( false ) ;
577+ } ) ;
578+ } ) ;
546579} ) ;
Original file line number Diff line number Diff line change @@ -399,11 +399,12 @@ export const isMessageBounced = (
399399 message . moderation ?. action === 'bounce' ) ;
400400
401401export const isMessageBlocked = (
402- message : Pick < LocalMessage , 'type' | 'moderation' | 'moderation_details' > ,
402+ message : Pick < LocalMessage , 'type' | 'moderation' | 'moderation_details' | 'shadowed' > ,
403403) =>
404- message . type === 'error' &&
405- ( message . moderation_details ?. action === 'MESSAGE_RESPONSE_ACTION_REMOVE' ||
406- message . moderation ?. action === 'remove' ) ;
404+ message . shadowed ||
405+ ( message . type === 'error' &&
406+ ( message . moderation_details ?. action === 'MESSAGE_RESPONSE_ACTION_REMOVE' ||
407+ message . moderation ?. action === 'remove' ) ) ;
407408
408409export const isMessageDeleted = ( message : LocalMessage ) : boolean =>
409410 Boolean ( message . deleted_at || message . type === 'deleted' || message . deleted_for_me ) ;
You can’t perform that action at this time.
0 commit comments