Skip to content

Commit

Permalink
runfix: filter duplicated system messages (#15264)
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrykBuniX committed Jun 6, 2023
1 parent 31b2abb commit a5d7d1e
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import {LegalHoldMessage} from './LegalHoldMessage';
import {MemberMessage} from './MemberMessage';
import {MissedMessage} from './MissedMessage';
import {PingMessage} from './PingMessage';
import {ProtocolUpdateMessage} from './ProtocolUpdateMessage';
import {SystemMessage} from './SystemMessage';
import {VerificationMessage} from './VerificationMessage';

Expand Down Expand Up @@ -270,9 +269,7 @@ export const MessageWrapper: React.FC<MessageParams & {hasMarker: boolean; isMes
if (message.isFileTypeRestricted()) {
return <FileTypeRestrictedMessage message={message} />;
}
if (message.isProtocolUpdate()) {
return <ProtocolUpdateMessage message={message} />;
}

if (message.isMissed()) {
return <MissedMessage />;
}
Expand Down

This file was deleted.

11 changes: 10 additions & 1 deletion src/script/components/MessagesList/Message/SystemMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,26 @@ const SystemMessage: React.FC<SystemMessageProps> = ({message}) => {
// Only set for RenameMessage, MemberMessage has a different super_type
const messageName = (message as RenameMessage).name;

const includeSenderNameMessages = [
SystemMessageType.CONVERSATION_RENAME,
SystemMessageType.CONVERSATION_MESSAGE_TIMER_UPDATE,
SystemMessageType.CONVERSATION_RECEIPT_MODE_UPDATE,
];

return (
<>
<div className="message-header" data-uie-name="element-message-system">
<div className="message-header-icon message-header-icon--svg text-foreground">
{message.system_message_type === SystemMessageType.CONVERSATION_RENAME && <Icon.Edit />}
{message.system_message_type === SystemMessageType.CONVERSATION_MESSAGE_TIMER_UPDATE && <Icon.Timer />}
{message.system_message_type === SystemMessageType.CONVERSATION_RECEIPT_MODE_UPDATE && <Icon.Read />}
{message.system_message_type === SystemMessageType.CONVERSATION_PROTOCOL_UPDATE && <Icon.Info />}
</div>
<p className="message-header-label">
<span className="message-header-label__multiline">
<span className="message-header-sender-name">{unsafeSenderName}</span>
{includeSenderNameMessages.includes(message.system_message_type) && (
<span className="message-header-sender-name">{unsafeSenderName}</span>
)}
<span className="ellipsis">{caption}</span>
</span>
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/script/components/MessagesList/MessageList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const filterDuplicatedSystemMessages = (messages: MessageEntity[]) => {
}

if (currentMessage.isSystem()) {
const systemMessagesToFilter = [CONVERSATION_EVENT.RENAME] as string[];
const systemMessagesToFilter = [CONVERSATION_EVENT.RENAME, CONVERSATION_EVENT.PROTOCOL_UPDATE] as string[];
if (systemMessagesToFilter.includes(currentMessage.type)) {
const uniqUpdateMessages = uniqMessages.filter(
(message): message is SystemMessage => message.isSystem() && systemMessagesToFilter.includes(message.type),
Expand Down
5 changes: 0 additions & 5 deletions src/script/entity/message/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import type {LinkPreview} from './LinkPreview';
import type {MemberMessage} from './MemberMessage';
import {MissedMessage} from './MissedMessage';
import type {PingMessage} from './PingMessage';
import {ProtocolUpdateMessage} from './ProtocolUpdateMessage';
import type {SystemMessage} from './SystemMessage';
import type {VerificationMessage} from './VerificationMessage';

Expand Down Expand Up @@ -317,10 +316,6 @@ export class Message {
return this.super_type === SuperType.MISSED;
}

isProtocolUpdate(): this is ProtocolUpdateMessage {
return this.super_type === SuperType.PROTOCOL_UPDATE;
}

isCallTimeout(): this is CallingTimeoutMessage {
return this.super_type === SuperType.CALL_TIME_OUT;
}
Expand Down
6 changes: 2 additions & 4 deletions src/script/entity/message/ProtocolUpdateMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,17 @@
*/

import {ConversationProtocol} from '@wireapp/api-client/lib/conversation';
import {CONVERSATION_EVENT} from '@wireapp/api-client/lib/event/';
import ko from 'knockout';

import {SuperType} from 'src/script/message/SuperType';
import {SystemMessageType} from 'src/script/message/SystemMessageType';
import {t} from 'Util/LocalizerUtil';

import {SystemMessage} from './SystemMessage';

export class ProtocolUpdateMessage extends SystemMessage {
constructor(public protocol: ConversationProtocol.MIXED | ConversationProtocol.MLS) {
super();
this.type = CONVERSATION_EVENT.PROTOCOL_UPDATE;
this.super_type = SuperType.PROTOCOL_UPDATE;
this.system_message_type = SystemMessageType.CONVERSATION_PROTOCOL_UPDATE;
this.caption = ko.pureComputed(() =>
this.protocol === ConversationProtocol.MIXED
? t('conversationProtocolUpdatedToMixed')
Expand Down
1 change: 0 additions & 1 deletion src/script/message/SuperType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export enum SuperType {
LOCATION = 'location',
MEMBER = 'member',
MISSED = 'missed',
PROTOCOL_UPDATE = 'protocol-update',
PING = 'ping',
REACTION = 'reaction',
SPECIAL = 'special',
Expand Down
1 change: 1 addition & 0 deletions src/script/message/SystemMessageType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export enum SystemMessageType {
CONVERSATION_MESSAGE_TIMER_UPDATE = 'message-timer-update',
CONVERSATION_RECEIPT_MODE_UPDATE = 'receipt-mode-update',
CONVERSATION_RENAME = 'rename',
CONVERSATION_PROTOCOL_UPDATE = 'protocol-update',
CONVERSATION_RESUME = 'resume',
MEMBER_JOIN = 'join',
MEMBER_LEAVE = 'leave',
Expand Down

0 comments on commit a5d7d1e

Please sign in to comment.