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
56
ts/util/avatarUtils.ts
Normal file
56
ts/util/avatarUtils.ts
Normal file
|
@ -0,0 +1,56 @@
|
|||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { ConversationAttributesType } from '../model-types.d';
|
||||
import { isMe } from './whatTypeOfConversation';
|
||||
import { isSignalConversation } from './isSignalConversation';
|
||||
|
||||
export function getAvatarHash(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): undefined | string {
|
||||
const avatar = isMe(conversationAttrs)
|
||||
? conversationAttrs.profileAvatar || conversationAttrs.avatar
|
||||
: conversationAttrs.avatar || conversationAttrs.profileAvatar;
|
||||
return avatar?.hash || undefined;
|
||||
}
|
||||
|
||||
export function getAvatarPath(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): undefined | string {
|
||||
const shouldShowProfileAvatar =
|
||||
isMe(conversationAttrs) ||
|
||||
window.storage.get('preferContactAvatars') === false;
|
||||
const avatar = shouldShowProfileAvatar
|
||||
? conversationAttrs.profileAvatar || conversationAttrs.avatar
|
||||
: conversationAttrs.avatar || conversationAttrs.profileAvatar;
|
||||
return avatar?.path || undefined;
|
||||
}
|
||||
|
||||
export function getAbsoluteAvatarPath(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): string | undefined {
|
||||
const { getAbsoluteAttachmentPath } = window.Signal.Migrations;
|
||||
const avatarPath = getAvatarPath(conversationAttrs);
|
||||
if (isSignalConversation(conversationAttrs)) {
|
||||
return avatarPath;
|
||||
}
|
||||
return avatarPath ? getAbsoluteAttachmentPath(avatarPath) : undefined;
|
||||
}
|
||||
|
||||
export function getAbsoluteProfileAvatarPath(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): string | undefined {
|
||||
const { getAbsoluteAttachmentPath } = window.Signal.Migrations;
|
||||
const avatarPath = conversationAttrs.profileAvatar?.path;
|
||||
return avatarPath ? getAbsoluteAttachmentPath(avatarPath) : undefined;
|
||||
}
|
||||
|
||||
export function getAbsoluteUnblurredAvatarPath(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): string | undefined {
|
||||
const { getAbsoluteAttachmentPath } = window.Signal.Migrations;
|
||||
const { unblurredAvatarPath } = conversationAttrs;
|
||||
return unblurredAvatarPath
|
||||
? getAbsoluteAttachmentPath(unblurredAvatarPath)
|
||||
: undefined;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue