mirror of
https://github.com/signalapp/Signal-Desktop.git
synced 2026-02-15 07:28:59 +00:00
46 lines
1.4 KiB
TypeScript
46 lines
1.4 KiB
TypeScript
// Copyright 2026 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { isIncoming } from '../messages/helpers.std.js';
|
|
import type { ReadonlyMessageAttributesType } from '../model-types.js';
|
|
import { DataReader } from '../sql/Client.preload.js';
|
|
import { itemStorage } from '../textsecure/Storage.preload.js';
|
|
import type { AciString } from '../types/ServiceId.std.js';
|
|
import { strictAssert } from './assert.std.js';
|
|
import { isAciString } from './isAciString.std.js';
|
|
|
|
export type PinnedMessageTarget = Readonly<{
|
|
conversationId: string;
|
|
targetMessageId: string;
|
|
targetAuthorAci: AciString;
|
|
targetSentTimestamp: number;
|
|
}>;
|
|
|
|
function getMessageAuthorAci(
|
|
message: ReadonlyMessageAttributesType
|
|
): AciString {
|
|
if (isIncoming(message)) {
|
|
strictAssert(
|
|
isAciString(message.sourceServiceId),
|
|
'Message sourceServiceId must be an ACI'
|
|
);
|
|
return message.sourceServiceId;
|
|
}
|
|
return itemStorage.user.getCheckedAci();
|
|
}
|
|
|
|
export async function getPinnedMessageTarget(
|
|
targetMessageId: string
|
|
): Promise<PinnedMessageTarget | null> {
|
|
const message = await DataReader.getMessageById(targetMessageId);
|
|
if (message == null) {
|
|
return null;
|
|
}
|
|
return {
|
|
conversationId: message.conversationId,
|
|
targetMessageId: message.id,
|
|
targetAuthorAci: getMessageAuthorAci(message),
|
|
targetSentTimestamp: message.sent_at,
|
|
};
|
|
}
|