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';
|
2023-08-16 20:54:39 +00:00
|
|
|
import {
|
|
|
|
getSource,
|
|
|
|
getSourceDevice,
|
|
|
|
getSourceServiceId,
|
|
|
|
} from '../messages/helpers';
|
2022-04-22 18:35:14 +00:00
|
|
|
import { isDirectConversation, isGroupV2 } from './whatTypeOfConversation';
|
2024-01-02 19:36:49 +00:00
|
|
|
import { getE164 } from './getE164';
|
2024-03-12 16:29:31 +00:00
|
|
|
import type { ConversationType } from '../state/ducks/conversations';
|
2022-04-22 18:35:14 +00:00
|
|
|
|
2022-10-03 23:10:20 +00:00
|
|
|
export function getMessageIdForLogging(
|
|
|
|
message: Pick<
|
|
|
|
MessageAttributesType,
|
2023-08-16 20:54:39 +00:00
|
|
|
'type' | 'sourceServiceId' | 'sourceDevice' | 'sent_at'
|
2022-10-03 23:10:20 +00:00
|
|
|
>
|
|
|
|
): string {
|
2023-08-16 20:54:39 +00:00
|
|
|
const account = getSourceServiceId(message) || getSource(message);
|
2022-04-22 18:35:14 +00:00
|
|
|
const device = getSourceDevice(message);
|
|
|
|
const timestamp = message.sent_at;
|
|
|
|
|
|
|
|
return `${account}.${device} ${timestamp}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getConversationIdForLogging(
|
2024-03-12 16:29:31 +00:00
|
|
|
conversation: ConversationAttributesType | ConversationType
|
2022-04-22 18:35:14 +00:00
|
|
|
): string {
|
|
|
|
if (isDirectConversation(conversation)) {
|
2024-01-02 19:36:49 +00:00
|
|
|
const { serviceId, pni, id } = conversation;
|
|
|
|
return `${serviceId || pni || getE164(conversation)} (${id})`;
|
2022-04-22 18:35:14 +00:00
|
|
|
}
|
|
|
|
if (isGroupV2(conversation)) {
|
|
|
|
return `groupv2(${conversation.groupId})`;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `group(${conversation.groupId})`;
|
|
|
|
}
|