mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-04-19 16:08:34 +01:00
Admin Delete
This commit is contained in:
@@ -1,19 +1,71 @@
|
||||
// Copyright 2023 Signal Messenger, LLC
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
import type { AciString } from '../types/ServiceId.std.js';
|
||||
import type { ConversationAttributesType } from '../model-types.d.ts';
|
||||
import type { LastMessageType } from '../state/ducks/conversations.preload.js';
|
||||
import { dropNull } from './dropNull.std.js';
|
||||
import { findAndFormatContact } from './findAndFormatContact.preload.js';
|
||||
import { hydrateRanges } from './BodyRange.node.js';
|
||||
import { stripNewlinesForLeftPane } from './stripNewlinesForLeftPane.std.js';
|
||||
import { itemStorage } from '../textsecure/Storage.preload.js';
|
||||
import { getTitle } from './getTitle.preload.js';
|
||||
|
||||
function getNameForAci(
|
||||
aci: AciString | null | undefined,
|
||||
options?: { isShort?: boolean }
|
||||
): string | null {
|
||||
if (aci == null) {
|
||||
return null;
|
||||
}
|
||||
const conversation = window.ConversationController.get(aci);
|
||||
if (conversation != null) {
|
||||
return getTitle(conversation.attributes, options);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function getDisplayNameForAci(
|
||||
aci: AciString | null | undefined,
|
||||
ourAci: AciString | null | undefined
|
||||
): string | null {
|
||||
if (aci === ourAci) {
|
||||
return window.SignalContext.i18n('icu:you');
|
||||
}
|
||||
return getNameForAci(aci, { isShort: true });
|
||||
}
|
||||
|
||||
export function getLastMessage(
|
||||
conversationAttrs: ConversationAttributesType
|
||||
): LastMessageType | undefined {
|
||||
const ourAci = itemStorage.user.getAci();
|
||||
|
||||
if (conversationAttrs.lastMessageDeletedForEveryone) {
|
||||
return { deletedForEveryone: true };
|
||||
const { lastMessageAuthorAci, lastMessageDeletedForEveryoneByAdminAci } =
|
||||
conversationAttrs;
|
||||
|
||||
// Only show admin name when the admin deleted someone else's message
|
||||
const isAdminDeletingOwnMessage =
|
||||
lastMessageDeletedForEveryoneByAdminAci != null &&
|
||||
lastMessageDeletedForEveryoneByAdminAci === lastMessageAuthorAci;
|
||||
const deletedByAdminName = isAdminDeletingOwnMessage
|
||||
? null
|
||||
: getNameForAci(lastMessageDeletedForEveryoneByAdminAci);
|
||||
|
||||
const authorName =
|
||||
getDisplayNameForAci(lastMessageAuthorAci, ourAci) ??
|
||||
// Deprecated: fall back to lastMessageAuthor from old database rows
|
||||
conversationAttrs.lastMessageAuthor ??
|
||||
null;
|
||||
|
||||
return {
|
||||
deletedForEveryone: true,
|
||||
deletedByAdminName,
|
||||
isOutgoing: lastMessageAuthorAci === ourAci,
|
||||
authorName,
|
||||
};
|
||||
}
|
||||
|
||||
const lastMessageText = conversationAttrs.lastMessage;
|
||||
if (!lastMessageText) {
|
||||
return undefined;
|
||||
@@ -25,8 +77,14 @@ export function getLastMessage(
|
||||
const text = stripNewlinesForLeftPane(lastMessageText);
|
||||
const prefix = conversationAttrs.lastMessagePrefix;
|
||||
|
||||
const author =
|
||||
getDisplayNameForAci(conversationAttrs.lastMessageAuthorAci, ourAci) ??
|
||||
// Deprecated: fall back to lastMessageAuthor from old database rows
|
||||
conversationAttrs.lastMessageAuthor ??
|
||||
null;
|
||||
|
||||
return {
|
||||
author: dropNull(conversationAttrs.lastMessageAuthor),
|
||||
author,
|
||||
bodyRanges,
|
||||
deletedForEveryone: false,
|
||||
prefix,
|
||||
|
||||
Reference in New Issue
Block a user