2023-01-03 19:55:46 +00:00
|
|
|
// Copyright 2021 Signal Messenger, LLC
|
2022-02-16 18:36:21 +00:00
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
import { isNumber } from 'lodash';
|
|
|
|
|
|
|
|
import * as Errors from '../../types/errors';
|
2022-11-02 23:48:38 +00:00
|
|
|
import { strictAssert } from '../../util/assert';
|
2022-02-16 18:36:21 +00:00
|
|
|
import { repeat, zipObject } from '../../util/iterables';
|
|
|
|
import type { CallbackResultType } from '../../textsecure/Types.d';
|
|
|
|
import type { MessageModel } from '../../models/messages';
|
|
|
|
import type { MessageReactionType } from '../../model-types.d';
|
|
|
|
import type { ConversationModel } from '../../models/conversations';
|
2024-07-22 18:16:33 +00:00
|
|
|
import { DataWriter } from '../../sql/Client';
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
import * as reactionUtil from '../../reactions/util';
|
|
|
|
import { isSent, SendStatus } from '../../messages/MessageSendState';
|
2023-10-04 00:12:57 +00:00
|
|
|
import { __DEPRECATED$getMessageById } from '../../messages/getMessageById';
|
2023-08-28 22:03:32 +00:00
|
|
|
import { isIncoming } from '../../messages/helpers';
|
2022-02-16 18:36:21 +00:00
|
|
|
import {
|
|
|
|
isMe,
|
|
|
|
isDirectConversation,
|
|
|
|
isGroupV2,
|
|
|
|
} from '../../util/whatTypeOfConversation';
|
|
|
|
import { getSendOptions } from '../../util/getSendOptions';
|
|
|
|
import { SignalService as Proto } from '../../protobuf';
|
|
|
|
import { handleMessageSend } from '../../util/handleMessageSend';
|
|
|
|
import { ourProfileKeyService } from '../../services/ourProfileKey';
|
2022-04-22 18:45:45 +00:00
|
|
|
import { canReact, isStory } from '../../state/selectors/message';
|
2022-02-16 18:36:21 +00:00
|
|
|
import { findAndFormatContact } from '../../util/findAndFormatContact';
|
2023-08-28 22:03:32 +00:00
|
|
|
import type { AciString, ServiceIdString } from '../../types/ServiceId';
|
2023-09-14 17:04:48 +00:00
|
|
|
import { isAciString } from '../../util/isAciString';
|
2022-02-16 18:36:21 +00:00
|
|
|
import { handleMultipleSendErrors } from './handleMultipleSendErrors';
|
2022-05-10 19:02:21 +00:00
|
|
|
import { incrementMessageCounter } from '../../util/incrementMessageCounter';
|
2024-10-08 03:17:03 +00:00
|
|
|
import { generateMessageId } from '../../util/generateMessageId';
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
import type {
|
|
|
|
ConversationQueueJobBundle,
|
|
|
|
ReactionJobData,
|
|
|
|
} from '../conversationJobQueue';
|
2022-02-22 20:34:57 +00:00
|
|
|
import { isConversationAccepted } from '../../util/isConversationAccepted';
|
|
|
|
import { isConversationUnregistered } from '../../util/isConversationUnregistered';
|
2022-05-31 19:46:56 +00:00
|
|
|
import type { LoggerType } from '../../types/Logging';
|
2023-04-11 03:54:43 +00:00
|
|
|
import { sendToGroup } from '../../util/sendToGroup';
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
export async function sendReaction(
|
|
|
|
conversation: ConversationModel,
|
|
|
|
{
|
|
|
|
isFinalAttempt,
|
2022-06-13 21:39:35 +00:00
|
|
|
messaging,
|
2022-02-16 18:36:21 +00:00
|
|
|
shouldContinue,
|
|
|
|
timeRemaining,
|
|
|
|
log,
|
|
|
|
}: ConversationQueueJobBundle,
|
|
|
|
data: ReactionJobData
|
|
|
|
): Promise<void> {
|
|
|
|
const { messageId, revision } = data;
|
2023-08-10 16:43:33 +00:00
|
|
|
const ourAci = window.textsecure.storage.user.getCheckedAci();
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
await window.ConversationController.load();
|
|
|
|
|
|
|
|
const ourConversationId =
|
|
|
|
window.ConversationController.getOurConversationIdOrThrow();
|
|
|
|
|
2023-10-04 00:12:57 +00:00
|
|
|
const message = await __DEPRECATED$getMessageById(messageId);
|
2022-02-16 18:36:21 +00:00
|
|
|
if (!message) {
|
|
|
|
log.info(
|
|
|
|
`message ${messageId} was not found, maybe because it was deleted. Giving up on sending its reactions`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-11-02 23:48:38 +00:00
|
|
|
strictAssert(
|
|
|
|
!isStory(message.attributes),
|
|
|
|
'Story reactions should be handled by sendStoryReaction'
|
|
|
|
);
|
2022-02-16 18:36:21 +00:00
|
|
|
const { pendingReaction, emojiToRemove } =
|
|
|
|
reactionUtil.getNewestPendingOutgoingReaction(
|
|
|
|
getReactions(message),
|
|
|
|
ourConversationId
|
|
|
|
);
|
2022-11-02 23:48:38 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
if (!pendingReaction) {
|
|
|
|
log.info(`no pending reaction for ${messageId}. Doing nothing`);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!canReact(message.attributes, ourConversationId, findAndFormatContact)) {
|
|
|
|
log.info(`could not react to ${messageId}. Removing this pending reaction`);
|
|
|
|
markReactionFailed(message, pendingReaction);
|
2024-07-22 18:16:33 +00:00
|
|
|
await DataWriter.saveMessage(message.attributes, { ourAci });
|
2022-02-16 18:36:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!shouldContinue) {
|
|
|
|
log.info(
|
|
|
|
`reacting to message ${messageId} ran out of time. Giving up on sending it`
|
|
|
|
);
|
|
|
|
markReactionFailed(message, pendingReaction);
|
2024-07-22 18:16:33 +00:00
|
|
|
await DataWriter.saveMessage(message.attributes, { ourAci });
|
2022-02-16 18:36:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let sendErrors: Array<Error> = [];
|
|
|
|
const saveErrors = (errors: Array<Error>): void => {
|
|
|
|
sendErrors = errors;
|
|
|
|
};
|
|
|
|
|
|
|
|
let originalError: Error | undefined;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const messageConversation = message.getConversation();
|
|
|
|
if (messageConversation !== conversation) {
|
|
|
|
log.error(
|
|
|
|
`message conversation '${messageConversation?.idForLogging()}' does not match job conversation ${conversation.idForLogging()}`
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-10-07 22:11:13 +00:00
|
|
|
const expireTimer = messageConversation.get('expireTimer');
|
2022-02-16 18:36:21 +00:00
|
|
|
const {
|
2023-08-10 16:43:33 +00:00
|
|
|
allRecipientServiceIds,
|
|
|
|
recipientServiceIdsWithoutMe,
|
|
|
|
untrustedServiceIds,
|
2022-05-31 19:46:56 +00:00
|
|
|
} = getRecipients(log, pendingReaction, conversation);
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (untrustedServiceIds.length) {
|
2022-02-16 18:36:21 +00:00
|
|
|
window.reduxActions.conversations.conversationStoppedByMissingVerification(
|
|
|
|
{
|
|
|
|
conversationId: conversation.id,
|
2023-08-10 16:43:33 +00:00
|
|
|
untrustedServiceIds,
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
);
|
|
|
|
throw new Error(
|
2023-08-10 16:43:33 +00:00
|
|
|
`Reaction for message ${messageId} sending blocked because ${untrustedServiceIds.length} conversation(s) were untrusted. Failing this attempt.`
|
2022-02-16 18:36:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
const profileKey = conversation.get('profileSharing')
|
|
|
|
? await ourProfileKeyService.get()
|
|
|
|
: undefined;
|
|
|
|
|
2023-08-28 22:03:32 +00:00
|
|
|
const { emoji, ...restOfPendingReaction } = pendingReaction;
|
|
|
|
|
|
|
|
let targetAuthorAci: AciString;
|
|
|
|
if (isIncoming(message.attributes)) {
|
|
|
|
strictAssert(
|
|
|
|
isAciString(message.attributes.sourceServiceId),
|
|
|
|
'incoming message does not have sender ACI'
|
|
|
|
);
|
|
|
|
({ sourceServiceId: targetAuthorAci } = message.attributes);
|
|
|
|
} else {
|
|
|
|
targetAuthorAci = ourAci;
|
|
|
|
}
|
2023-08-10 16:43:33 +00:00
|
|
|
|
|
|
|
const reactionForSend = {
|
|
|
|
...restOfPendingReaction,
|
|
|
|
emoji: emoji || emojiToRemove,
|
|
|
|
targetAuthorAci,
|
|
|
|
remove: !emoji,
|
|
|
|
};
|
2022-02-16 18:36:21 +00:00
|
|
|
const ephemeralMessageForReactionSend = new window.Whisper.Message({
|
2024-10-08 03:17:03 +00:00
|
|
|
...generateMessageId(incrementMessageCounter()),
|
2022-02-16 18:36:21 +00:00
|
|
|
type: 'outgoing',
|
|
|
|
conversationId: conversation.get('id'),
|
|
|
|
sent_at: pendingReaction.timestamp,
|
|
|
|
received_at_ms: pendingReaction.timestamp,
|
|
|
|
timestamp: pendingReaction.timestamp,
|
|
|
|
sendStateByConversationId: zipObject(
|
|
|
|
Object.keys(pendingReaction.isSentByConversationId || {}),
|
|
|
|
repeat({
|
|
|
|
status: SendStatus.Pending,
|
|
|
|
updatedAt: Date.now(),
|
|
|
|
})
|
|
|
|
),
|
|
|
|
});
|
2023-10-23 16:40:09 +00:00
|
|
|
// Adds the reaction's attributes to the message cache so that we can
|
|
|
|
// safely `set` on it later.
|
|
|
|
window.MessageCache.toMessageAttributes(
|
|
|
|
ephemeralMessageForReactionSend.attributes
|
|
|
|
);
|
2022-05-10 19:02:21 +00:00
|
|
|
|
2022-11-02 23:48:38 +00:00
|
|
|
ephemeralMessageForReactionSend.doNotSave = true;
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
let didFullySend: boolean;
|
|
|
|
const successfulConversationIds = new Set<string>();
|
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
if (recipientServiceIdsWithoutMe.length === 0) {
|
2022-02-16 18:36:21 +00:00
|
|
|
log.info('sending sync reaction message only');
|
2023-05-31 15:54:45 +00:00
|
|
|
const dataMessage = await messaging.getDataOrEditMessage({
|
2022-02-16 18:36:21 +00:00
|
|
|
attachments: [],
|
|
|
|
expireTimer,
|
2024-08-21 16:03:28 +00:00
|
|
|
expireTimerVersion: conversation.getExpireTimerVersion(),
|
2022-02-16 18:36:21 +00:00
|
|
|
groupV2: conversation.getGroupV2Info({
|
2023-08-10 16:43:33 +00:00
|
|
|
members: recipientServiceIdsWithoutMe,
|
2022-02-16 18:36:21 +00:00
|
|
|
}),
|
|
|
|
preview: [],
|
|
|
|
profileKey,
|
|
|
|
reaction: reactionForSend,
|
2023-08-10 16:43:33 +00:00
|
|
|
recipients: allRecipientServiceIds,
|
2022-02-16 18:36:21 +00:00
|
|
|
timestamp: pendingReaction.timestamp,
|
|
|
|
});
|
2023-11-17 18:16:48 +00:00
|
|
|
await ephemeralMessageForReactionSend.sendSyncMessageOnly({
|
2022-02-16 18:36:21 +00:00
|
|
|
dataMessage,
|
2023-11-17 18:16:48 +00:00
|
|
|
saveErrors,
|
|
|
|
targetTimestamp: pendingReaction.timestamp,
|
|
|
|
});
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
didFullySend = true;
|
|
|
|
successfulConversationIds.add(ourConversationId);
|
|
|
|
} else {
|
|
|
|
const sendOptions = await getSendOptions(conversation.attributes);
|
|
|
|
const { ContentHint } = Proto.UnidentifiedSenderMessage.Message;
|
|
|
|
|
|
|
|
let promise: Promise<CallbackResultType>;
|
|
|
|
if (isDirectConversation(conversation.attributes)) {
|
2022-02-22 20:34:57 +00:00
|
|
|
if (!isConversationAccepted(conversation.attributes)) {
|
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} is not accepted; refusing to send`
|
|
|
|
);
|
|
|
|
markReactionFailed(message, pendingReaction);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isConversationUnregistered(conversation.attributes)) {
|
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} is unregistered; refusing to send`
|
|
|
|
);
|
|
|
|
markReactionFailed(message, pendingReaction);
|
|
|
|
return;
|
|
|
|
}
|
2022-02-25 02:40:56 +00:00
|
|
|
if (conversation.isBlocked()) {
|
|
|
|
log.info(
|
|
|
|
`conversation ${conversation.idForLogging()} is blocked; refusing to send`
|
|
|
|
);
|
|
|
|
markReactionFailed(message, pendingReaction);
|
|
|
|
return;
|
|
|
|
}
|
2022-02-22 20:34:57 +00:00
|
|
|
|
2022-02-16 18:36:21 +00:00
|
|
|
log.info('sending direct reaction message');
|
2023-08-10 16:43:33 +00:00
|
|
|
promise = messaging.sendMessageToServiceId({
|
|
|
|
serviceId: recipientServiceIdsWithoutMe[0],
|
2022-02-16 18:36:21 +00:00
|
|
|
messageText: undefined,
|
|
|
|
attachments: [],
|
|
|
|
quote: undefined,
|
|
|
|
preview: [],
|
|
|
|
sticker: undefined,
|
|
|
|
reaction: reactionForSend,
|
|
|
|
deletedForEveryoneTimestamp: undefined,
|
|
|
|
timestamp: pendingReaction.timestamp,
|
|
|
|
expireTimer,
|
2024-08-21 16:03:28 +00:00
|
|
|
expireTimerVersion: conversation.getExpireTimerVersion(),
|
2022-02-16 18:36:21 +00:00
|
|
|
contentHint: ContentHint.RESENDABLE,
|
|
|
|
groupId: undefined,
|
|
|
|
profileKey,
|
|
|
|
options: sendOptions,
|
2022-07-01 16:55:13 +00:00
|
|
|
urgent: true,
|
2022-08-15 21:53:33 +00:00
|
|
|
includePniSignatureMessage: true,
|
2022-02-16 18:36:21 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
log.info('sending group reaction message');
|
|
|
|
promise = conversation.queueJob(
|
|
|
|
'conversationQueue/sendReaction',
|
2022-05-23 22:08:13 +00:00
|
|
|
abortSignal => {
|
2022-02-16 18:36:21 +00:00
|
|
|
// Note: this will happen for all old jobs queued before 5.32.x
|
|
|
|
if (isGroupV2(conversation.attributes) && !isNumber(revision)) {
|
|
|
|
log.error('No revision provided, but conversation is GroupV2');
|
|
|
|
}
|
|
|
|
|
|
|
|
const groupV2Info = conversation.getGroupV2Info({
|
2023-08-10 16:43:33 +00:00
|
|
|
members: recipientServiceIdsWithoutMe,
|
2022-02-16 18:36:21 +00:00
|
|
|
});
|
|
|
|
if (groupV2Info && isNumber(revision)) {
|
|
|
|
groupV2Info.revision = revision;
|
|
|
|
}
|
|
|
|
|
2023-04-11 03:54:43 +00:00
|
|
|
return sendToGroup({
|
2022-05-23 22:08:13 +00:00
|
|
|
abortSignal,
|
2022-02-16 18:36:21 +00:00
|
|
|
contentHint: ContentHint.RESENDABLE,
|
|
|
|
groupSendOptions: {
|
|
|
|
groupV2: groupV2Info,
|
|
|
|
reaction: reactionForSend,
|
|
|
|
timestamp: pendingReaction.timestamp,
|
|
|
|
expireTimer,
|
|
|
|
profileKey,
|
|
|
|
},
|
|
|
|
messageId,
|
|
|
|
sendOptions,
|
|
|
|
sendTarget: conversation.toSenderKeyTarget(),
|
|
|
|
sendType: 'reaction',
|
2022-07-01 16:55:13 +00:00
|
|
|
urgent: true,
|
2022-02-16 18:36:21 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-11-17 18:16:48 +00:00
|
|
|
await ephemeralMessageForReactionSend.send({
|
|
|
|
promise: handleMessageSend(promise, {
|
2022-02-16 18:36:21 +00:00
|
|
|
messageIds: [messageId],
|
|
|
|
sendType: 'reaction',
|
|
|
|
}),
|
2023-11-17 18:16:48 +00:00
|
|
|
saveErrors,
|
|
|
|
targetTimestamp: pendingReaction.timestamp,
|
|
|
|
});
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
// Because message.send swallows and processes errors, we'll await the inner promise
|
|
|
|
// to get the SendMessageProtoError, which gives us information upstream
|
|
|
|
/// processors need to detect certain kinds of errors.
|
|
|
|
try {
|
|
|
|
await promise;
|
|
|
|
} catch (error) {
|
|
|
|
if (error instanceof Error) {
|
|
|
|
originalError = error;
|
|
|
|
} else {
|
|
|
|
log.error(
|
|
|
|
`promise threw something other than an error: ${Errors.toLogFormat(
|
|
|
|
error
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
didFullySend = true;
|
|
|
|
const reactionSendStateByConversationId =
|
|
|
|
ephemeralMessageForReactionSend.get('sendStateByConversationId') || {};
|
|
|
|
for (const [conversationId, sendState] of Object.entries(
|
|
|
|
reactionSendStateByConversationId
|
|
|
|
)) {
|
|
|
|
if (isSent(sendState.status)) {
|
|
|
|
successfulConversationIds.add(conversationId);
|
|
|
|
} else {
|
|
|
|
didFullySend = false;
|
|
|
|
}
|
|
|
|
}
|
2022-05-10 19:02:21 +00:00
|
|
|
|
|
|
|
if (!ephemeralMessageForReactionSend.doNotSave) {
|
|
|
|
const reactionMessage = ephemeralMessageForReactionSend;
|
|
|
|
|
2023-07-21 22:10:32 +00:00
|
|
|
await reactionMessage.hydrateStoryContext(message.attributes, {
|
|
|
|
shouldSave: false,
|
|
|
|
});
|
2024-07-22 18:16:33 +00:00
|
|
|
await DataWriter.saveMessage(reactionMessage.attributes, {
|
2023-08-10 16:43:33 +00:00
|
|
|
ourAci,
|
2023-07-21 22:10:32 +00:00
|
|
|
forceSave: true,
|
|
|
|
});
|
2022-05-10 19:02:21 +00:00
|
|
|
|
2024-07-25 23:29:49 +00:00
|
|
|
window.MessageCache.__DEPRECATED$register(
|
|
|
|
reactionMessage.id,
|
|
|
|
reactionMessage,
|
|
|
|
'sendReaction'
|
2022-05-10 19:02:21 +00:00
|
|
|
);
|
2024-07-25 23:29:49 +00:00
|
|
|
void conversation.addSingleMessage(reactionMessage.attributes);
|
2022-05-10 19:02:21 +00:00
|
|
|
}
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const newReactions = reactionUtil.markOutgoingReactionSent(
|
|
|
|
getReactions(message),
|
|
|
|
pendingReaction,
|
2022-11-02 23:48:38 +00:00
|
|
|
successfulConversationIds
|
2022-02-16 18:36:21 +00:00
|
|
|
);
|
|
|
|
setReactions(message, newReactions);
|
|
|
|
|
|
|
|
if (!didFullySend) {
|
|
|
|
throw new Error('reaction did not fully send');
|
|
|
|
}
|
|
|
|
} catch (thrownError: unknown) {
|
|
|
|
await handleMultipleSendErrors({
|
|
|
|
errors: [thrownError, ...sendErrors],
|
|
|
|
isFinalAttempt,
|
|
|
|
log,
|
|
|
|
markFailed: () => markReactionFailed(message, pendingReaction),
|
|
|
|
timeRemaining,
|
|
|
|
// In the case of a failed group send thrownError will not be SentMessageProtoError,
|
|
|
|
// but we should have been able to harvest the original error. In the Note to Self
|
|
|
|
// send case, thrownError will be the error we care about, and we won't have an
|
|
|
|
// originalError.
|
|
|
|
toThrow: originalError || thrownError,
|
|
|
|
});
|
|
|
|
} finally {
|
2024-07-22 18:16:33 +00:00
|
|
|
await DataWriter.saveMessage(message.attributes, { ourAci });
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-02 23:48:38 +00:00
|
|
|
const getReactions = (
|
|
|
|
message: MessageModel
|
|
|
|
): ReadonlyArray<MessageReactionType> => message.get('reactions') || [];
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
const setReactions = (
|
|
|
|
message: MessageModel,
|
|
|
|
reactions: Array<MessageReactionType>
|
|
|
|
): void => {
|
|
|
|
if (reactions.length) {
|
|
|
|
message.set('reactions', reactions);
|
|
|
|
} else {
|
2023-10-19 17:14:19 +00:00
|
|
|
message.set('reactions', undefined);
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
function getRecipients(
|
2022-05-31 19:46:56 +00:00
|
|
|
log: LoggerType,
|
2022-02-16 18:36:21 +00:00
|
|
|
reaction: Readonly<MessageReactionType>,
|
|
|
|
conversation: ConversationModel
|
|
|
|
): {
|
2023-08-10 16:43:33 +00:00
|
|
|
allRecipientServiceIds: Array<ServiceIdString>;
|
|
|
|
recipientServiceIdsWithoutMe: Array<ServiceIdString>;
|
|
|
|
untrustedServiceIds: Array<ServiceIdString>;
|
2022-02-16 18:36:21 +00:00
|
|
|
} {
|
2023-08-10 16:43:33 +00:00
|
|
|
const allRecipientServiceIds: Array<ServiceIdString> = [];
|
|
|
|
const recipientServiceIdsWithoutMe: Array<ServiceIdString> = [];
|
|
|
|
const untrustedServiceIds: Array<ServiceIdString> = [];
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2022-03-04 19:22:31 +00:00
|
|
|
const currentConversationRecipients = conversation.getMemberConversationIds();
|
2022-02-16 18:36:21 +00:00
|
|
|
|
|
|
|
for (const id of reactionUtil.getUnsentConversationIds(reaction)) {
|
|
|
|
const recipient = window.ConversationController.get(id);
|
|
|
|
if (!recipient) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const recipientIdentifier = recipient.getSendTarget();
|
|
|
|
const isRecipientMe = isMe(recipient.attributes);
|
|
|
|
|
|
|
|
if (
|
|
|
|
!recipientIdentifier ||
|
|
|
|
(!currentConversationRecipients.has(id) && !isRecipientMe)
|
|
|
|
) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (recipient.isUntrusted()) {
|
2023-08-10 16:43:33 +00:00
|
|
|
const serviceId = recipient.getServiceId();
|
|
|
|
if (!serviceId) {
|
2022-05-31 19:46:56 +00:00
|
|
|
log.error(
|
2023-08-10 16:43:33 +00:00
|
|
|
`sendReaction/getRecipients: Untrusted conversation ${recipient.idForLogging()} missing serviceId.`
|
2022-05-31 19:46:56 +00:00
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
2023-08-10 16:43:33 +00:00
|
|
|
untrustedServiceIds.push(serviceId);
|
2022-02-16 18:36:21 +00:00
|
|
|
continue;
|
|
|
|
}
|
2022-03-04 19:22:31 +00:00
|
|
|
if (recipient.isUnregistered()) {
|
|
|
|
continue;
|
|
|
|
}
|
2023-01-20 19:42:55 +00:00
|
|
|
if (recipient.isBlocked()) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-02-16 18:36:21 +00:00
|
|
|
|
2023-08-10 16:43:33 +00:00
|
|
|
allRecipientServiceIds.push(recipientIdentifier);
|
2022-02-16 18:36:21 +00:00
|
|
|
if (!isRecipientMe) {
|
2023-08-10 16:43:33 +00:00
|
|
|
recipientServiceIdsWithoutMe.push(recipientIdentifier);
|
2022-02-16 18:36:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
2023-08-10 16:43:33 +00:00
|
|
|
allRecipientServiceIds,
|
|
|
|
recipientServiceIdsWithoutMe,
|
|
|
|
untrustedServiceIds,
|
2022-02-16 18:36:21 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
function markReactionFailed(
|
|
|
|
message: MessageModel,
|
|
|
|
pendingReaction: MessageReactionType
|
|
|
|
): void {
|
|
|
|
const newReactions = reactionUtil.markOutgoingReactionFailed(
|
|
|
|
getReactions(message),
|
|
|
|
pendingReaction
|
|
|
|
);
|
|
|
|
setReactions(message, newReactions);
|
|
|
|
}
|