Skip to content

Commit

Permalink
runfix: stop counting e2ei system messages as unread [WPB-6081] (#16503)
Browse files Browse the repository at this point in the history
* runfix: do not count e2ei verification messages

* refactor: improve string render logic
  • Loading branch information
PatrykBuniX authored Jan 10, 2024
1 parent 8b82de5 commit 495fd60
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
29 changes: 17 additions & 12 deletions src/script/conversation/ConversationCellState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,21 @@ const _getStateRemoved = {

const _getStateUnreadMessage = {
description: (conversationEntity: Conversation): string => {
const unreadMessages = conversationEntity.unreadState().allMessages;
const unreadState = conversationEntity.unreadState();

for (const messageEntity of unreadMessages) {
const {allMessages, systemMessages} = unreadState;

const allUnread = [...allMessages, ...systemMessages];

for (const messageEntity of allUnread) {
let string;

if (messageEntity.isPing()) {
string = t('notificationPing');
} else if (messageEntity.hasAssetText()) {
string = true;
} else if (messageEntity.hasAsset()) {
} else if (messageEntity.isContent() && messageEntity.hasAssetText()) {
const assetText = messageEntity.getFirstAsset().text;
string = getRenderedTextContent(assetText);
} else if (messageEntity.isContent() && messageEntity.hasAsset()) {
const assetEntity = messageEntity.getFirstAsset();
const isUploaded = (assetEntity as FileAsset).status() === AssetTransferState.UPLOADED;

Expand Down Expand Up @@ -351,19 +356,19 @@ const _getStateUnreadMessage = {
: t('conversationsSecondaryLineEphemeralMessage');
}

const hasString = string && string !== true;
const stateText: string = hasString
? (string as string)
: getRenderedTextContent((messageEntity.getFirstAsset() as Text).text);
return conversationEntity.isGroup() && !messageEntity.isE2EIVerification()
? `${messageEntity.unsafeSenderName()}: ${stateText}`
: stateText;
? `${messageEntity.unsafeSenderName()}: ${string}`
: string;
}
}
return '';
},
icon: () => ConversationStatusIcon.UNREAD_MESSAGES,
match: (conversationEntity: Conversation) => conversationEntity.unreadState().allMessages.length > 0,
match: (conversationEntity: Conversation) => {
const {allMessages, systemMessages} = conversationEntity.unreadState();
const hasUnreadMessages = [...allMessages, ...systemMessages].length > 0;
return hasUnreadMessages;
},
};

const _getStateUserName = {
Expand Down
7 changes: 4 additions & 3 deletions src/script/entity/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import {CallMessage} from './message/CallMessage';
import type {ContentMessage} from './message/ContentMessage';
import type {Message} from './message/Message';
import {PingMessage} from './message/PingMessage';
import {SystemMessage} from './message/SystemMessage';
import type {User} from './User';

import type {Call} from '../calling/Call';
Expand All @@ -72,7 +71,7 @@ interface UnreadState {
pings: PingMessage[];
selfMentions: ContentMessage[];
selfReplies: ContentMessage[];
systemMessages: SystemMessage[];
systemMessages: Message[];
}

enum TIMESTAMP_TYPE {
Expand Down Expand Up @@ -462,7 +461,7 @@ export class Conversation {

const isE2EIVerification = messageEntity.isE2EIVerification();

if (isMissedCall || isPing || isMessage || isE2EIVerification) {
if (isMissedCall || isPing || isMessage) {
unreadState.allMessages.push(messageEntity as ContentMessage);
}

Expand All @@ -476,6 +475,8 @@ export class Conversation {
unreadState.pings.push(messageEntity);
} else if (isMessage) {
unreadState.otherMessages.push(messageEntity as ContentMessage);
} else if (isE2EIVerification) {
unreadState.systemMessages.push(messageEntity);
}

unreadState.allEvents.push(messageEntity as ContentMessage);
Expand Down

0 comments on commit 495fd60

Please sign in to comment.