2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2020 Signal Messenger, LLC
|
2022-04-22 18:35:14 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import type {
|
|
|
|
ConversationAttributesType,
|
|
|
|
MessageAttributesType,
|
|
|
|
} from '../model-types.d';
|
|
|
|
import { getSource, getSourceDevice, getSourceUuid } from '../messages/helpers';
|
|
|
|
import { isDirectConversation, isGroupV2 } from './whatTypeOfConversation';
|
|
|
|
|
2022-10-03 23:10:20 +00:00
|
|
|
export function getMessageIdForLogging(
|
|
|
|
message: Pick<
|
|
|
|
MessageAttributesType,
|
|
|
|
'type' | 'sourceUuid' | 'sourceDevice' | 'sent_at'
|
|
|
|
>
|
|
|
|
): string {
|
2022-04-22 18:35:14 +00:00
|
|
|
const account = getSourceUuid(message) || getSource(message);
|
|
|
|
const device = getSourceDevice(message);
|
|
|
|
const timestamp = message.sent_at;
|
|
|
|
|
|
|
|
return `${account}.${device} ${timestamp}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getConversationIdForLogging(
|
|
|
|
conversation: ConversationAttributesType
|
|
|
|
): string {
|
|
|
|
if (isDirectConversation(conversation)) {
|
|
|
|
const { uuid, e164, id } = conversation;
|
|
|
|
return `${uuid || e164} (${id})`;
|
|
|
|
}
|
|
|
|
if (isGroupV2(conversation)) {
|
|
|
|
return `groupv2(${conversation.groupId})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `group(${conversation.groupId})`;
|
|
|
|
}
|