Moves conversation.getProps out of models

Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
Josh Perez 2023-06-02 13:54:36 -04:00 committed by GitHub
parent a0d7c36e3b
commit 7c1957c30d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 810 additions and 598 deletions

36
ts/util/getLastMessage.ts Normal file
View file

@ -0,0 +1,36 @@
// Copyright 2023 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { ConversationAttributesType } from '../model-types.d';
import type { LastMessageType } from '../state/ducks/conversations';
import { dropNull } from './dropNull';
import { findAndFormatContact } from './findAndFormatContact';
import { hydrateRanges } from '../types/BodyRange';
import { stripNewlinesForLeftPane } from './stripNewlinesForLeftPane';
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,
};
}