diff --git a/ts/components/conversation/SessionMessagesList.tsx b/ts/components/conversation/SessionMessagesList.tsx index a32b54c9b..d58d9f70b 100644 --- a/ts/components/conversation/SessionMessagesList.tsx +++ b/ts/components/conversation/SessionMessagesList.tsx @@ -120,11 +120,11 @@ export const SessionMessagesList = (props: { break; } case 'interaction-notification': { - ComponentToRender = Message; + ComponentToRender = InteractionNotification; break; } case 'regular-message': { - ComponentToRender = InteractionNotification; + ComponentToRender = Message; break; } default: diff --git a/ts/components/conversation/message/message-item/GroupUpdateMessage.tsx b/ts/components/conversation/message/message-item/GroupUpdateMessage.tsx index 5b8b77ce6..8845fd2cf 100644 --- a/ts/components/conversation/message/message-item/GroupUpdateMessage.tsx +++ b/ts/components/conversation/message/message-item/GroupUpdateMessage.tsx @@ -58,7 +58,7 @@ function useChangeItem(change?: PropsForGroupUpdateType): LocalizerComponentProp }; default: assertUnreachable(changeType, `invalid case: ${changeType}`); - break; + throw new Error('unhandled case, but this is to make typescript happy'); } } diff --git a/ts/models/message.ts b/ts/models/message.ts index a396acf02..a3977d204 100644 --- a/ts/models/message.ts +++ b/ts/models/message.ts @@ -22,7 +22,6 @@ import { MessageAttributes, MessageAttributesOptionals, MessageGroupUpdate, - MessageModelType, fillMessageAttributesWithDefaults, type DataExtractionNotificationMsg, } from './messageType'; @@ -55,7 +54,6 @@ import { MessageModelPropsWithoutConvoProps, PropsForAttachment, PropsForExpirationTimer, - PropsForExpiringMessage, PropsForGroupInvitation, PropsForGroupUpdate, PropsForGroupUpdateAdd, @@ -196,7 +194,7 @@ export class MessageModel extends Backbone.Model { } public isIncoming() { - return this.get('type') === 'incoming'; + return this.get('type') === 'incoming' || this.get('direction') === 'incoming'; } public isUnread() { @@ -429,34 +427,6 @@ export class MessageModel extends Backbone.Model { } } - private getPropsForExpiringMessage(): PropsForExpiringMessage { - const expirationType = this.getExpirationType(); - const expirationDurationMs = this.getExpireTimerSeconds() - ? this.getExpireTimerSeconds() * DURATION.SECONDS - : null; - - const expireTimerStart = this.getExpirationStartTimestamp() || null; - - const expirationTimestamp = - expirationType && expireTimerStart && expirationDurationMs - ? expireTimerStart + expirationDurationMs - : null; - - const direction = - this.get('direction') === 'outgoing' || this.get('type') === 'outgoing' - ? 'outgoing' - : 'incoming'; - - return { - convoId: this.get('conversationId'), - messageId: this.get('id'), - direction, - expirationDurationMs, - expirationTimestamp, - isExpired: this.isExpired(), - }; - } - private getPropsForTimerNotification(): PropsForExpirationTimer | null { if (!this.isExpirationTimerUpdate()) { return null; @@ -513,19 +483,13 @@ export class MessageModel extends Backbone.Model { return null; } - const sharedProps = { - isUnread: this.isUnread(), - receivedAt: this.get('received_at'), - ...this.getPropsForExpiringMessage(), - }; - if (groupUpdate.joined?.length) { const change: PropsForGroupUpdateAdd = { type: 'add', added: groupUpdate.joined as Array, withHistory: false, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.joinedWithHistory?.length) { const change: PropsForGroupUpdateAdd = { @@ -533,7 +497,7 @@ export class MessageModel extends Backbone.Model { added: groupUpdate.joinedWithHistory as Array, withHistory: true, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.kicked?.length) { @@ -541,7 +505,7 @@ export class MessageModel extends Backbone.Model { type: 'kicked', kicked: groupUpdate.kicked as Array, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.left?.length) { @@ -549,7 +513,7 @@ export class MessageModel extends Backbone.Model { type: 'left', left: groupUpdate.left as Array, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.promoted?.length) { @@ -557,20 +521,20 @@ export class MessageModel extends Backbone.Model { type: 'promoted', promoted: groupUpdate.promoted as Array, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.name) { const change: PropsForGroupUpdateName = { type: 'name', newName: groupUpdate.name, }; - return { change, ...sharedProps }; + return { change }; } if (groupUpdate.avatarChange) { const change: PropsForGroupUpdateAvatarChange = { type: 'avatarChange', }; - return { change, ...sharedProps }; + return { change }; } return null; @@ -624,8 +588,12 @@ export class MessageModel extends Backbone.Model { public getPropsForMessage(): PropsForMessageWithoutConvoProps { const sender = this.getSource(); const expirationType = this.getExpirationType(); - const expirationDurationMs = this.getExpireTimerSeconds() * DURATION.SECONDS; - const expireTimerStart = this.getExpirationStartTimestamp(); + const expirationDurationMs = this.getExpireTimerSeconds() + ? this.getExpireTimerSeconds() * DURATION.SECONDS + : null; + + const expireTimerStart = this.getExpirationStartTimestamp() || null; + const expirationTimestamp = expirationType && expireTimerStart && expirationDurationMs ? expireTimerStart + expirationDurationMs @@ -636,7 +604,7 @@ export class MessageModel extends Backbone.Model { const body = this.get('body'); const props: PropsForMessageWithoutConvoProps = { id: this.id, - direction: (this.isIncoming() ? 'incoming' : 'outgoing') as MessageModelType, + direction: this.isIncoming() ? 'incoming' : 'outgoing', timestamp: this.get('sent_at') || 0, sender, convoId: this.get('conversationId'),