Skip to content

Commit c4ab89b

Browse files
committed
fix: recognize async moderated shadow blocked messages as blocked
1 parent d0cbaad commit c4ab89b

2 files changed

Lines changed: 39 additions & 5 deletions

File tree

src/components/Message/__tests__/utils.test.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { generateMessage, generateReaction, generateUser } from 'mock-builders';
22
import { fromPartial } from '@total-typescript/shoehorn';
33
import 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';
510
import type { StreamChat } from 'stream-chat';
611
import {
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
});

src/components/Message/utils.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,12 @@ export const isMessageBounced = (
399399
message.moderation?.action === 'bounce');
400400

401401
export 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

408409
export const isMessageDeleted = (message: LocalMessage): boolean =>
409410
Boolean(message.deleted_at || message.type === 'deleted' || message.deleted_for_me);

0 commit comments

Comments
 (0)