2023-06-02 13:54:36 -04:00
|
|
|
// Copyright 2023 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2025-09-16 17:39:03 -07:00
|
|
|
import type { ConversationAttributesType } from '../model-types.d.ts';
|
|
|
|
import type { LastMessageType } from '../state/ducks/conversations.js';
|
|
|
|
import { dropNull } from './dropNull.js';
|
|
|
|
import { findAndFormatContact } from './findAndFormatContact.js';
|
|
|
|
import { hydrateRanges } from '../types/BodyRange.js';
|
|
|
|
import { stripNewlinesForLeftPane } from './stripNewlinesForLeftPane.js';
|
2023-06-02 13:54:36 -04:00
|
|
|
|
|
|
|
export function getLastMessage(
|
|
|
|
conversationAttrs: ConversationAttributesType
|
|
|
|
): LastMessageType | undefined {
|
|
|
|
if (conversationAttrs.lastMessageDeletedForEveryone) {
|
|
|
|
return { deletedForEveryone: true };
|
|
|
|
}
|
|
|
|
const lastMessageText = conversationAttrs.lastMessage;
|
|
|
|
if (!lastMessageText) {
|
|
|
|
return undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
const rawBodyRanges = conversationAttrs.lastMessageBodyRanges || [];
|
|
|
|
const bodyRanges = hydrateRanges(rawBodyRanges, findAndFormatContact);
|
|
|
|
|
|
|
|
const text = stripNewlinesForLeftPane(lastMessageText);
|
|
|
|
const prefix = conversationAttrs.lastMessagePrefix;
|
|
|
|
|
|
|
|
return {
|
|
|
|
author: dropNull(conversationAttrs.lastMessageAuthor),
|
|
|
|
bodyRanges,
|
|
|
|
deletedForEveryone: false,
|
|
|
|
prefix,
|
|
|
|
status: dropNull(conversationAttrs.lastMessageStatus),
|
|
|
|
text,
|
|
|
|
};
|
|
|
|
}
|