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

56
ts/util/avatarUtils.ts Normal file
View 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;
}