Moves conversation.getProps out of models
Co-authored-by: Scott Nonnenberg <scott@signal.org>
This commit is contained in:
parent
a0d7c36e3b
commit
7c1957c30d
21 changed files with 810 additions and 598 deletions
49
ts/util/getDraftPreview.ts
Normal file
49
ts/util/getDraftPreview.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ConversationAttributesType } from '../model-types';
|
||||
import type { DraftPreviewType } from '../state/ducks/conversations';
|
||||
import { findAndFormatContact } from './findAndFormatContact';
|
||||
import { hydrateRanges } from '../types/BodyRange';
|
||||
import { isVoiceMessage } from '../types/Attachment';
|
||||
import { stripNewlinesForLeftPane } from './stripNewlinesForLeftPane';
|
||||
|
||||
export function getDraftPreview(
|
||||
attributes: ConversationAttributesType
|
||||
): DraftPreviewType {
|
||||
const { draft } = attributes;
|
||||
|
||||
const rawBodyRanges = attributes.draftBodyRanges || [];
|
||||
const bodyRanges = hydrateRanges(rawBodyRanges, findAndFormatContact);
|
||||
|
||||
if (draft) {
|
||||
return {
|
||||
text: stripNewlinesForLeftPane(draft),
|
||||
bodyRanges,
|
||||
};
|
||||
}
|
||||
|
||||
const draftAttachments = attributes.draftAttachments || [];
|
||||
if (draftAttachments.length > 0) {
|
||||
if (isVoiceMessage(draftAttachments[0])) {
|
||||
return {
|
||||
text: window.i18n('icu:message--getNotificationText--voice-message'),
|
||||
prefix: '🎤',
|
||||
};
|
||||
}
|
||||
return {
|
||||
text: window.i18n('icu:Conversation--getDraftPreview--attachment'),
|
||||
};
|
||||
}
|
||||
|
||||
const { quotedMessageId } = attributes;
|
||||
if (quotedMessageId) {
|
||||
return {
|
||||
text: window.i18n('icu:Conversation--getDraftPreview--quote'),
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
text: window.i18n('icu:Conversation--getDraftPreview--draft'),
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue