Send Reactions

This commit is contained in:
Ken Powers 2020-01-23 18:57:37 -05:00 committed by Scott Nonnenberg
parent 3b050116fc
commit 153503efc5
16 changed files with 683 additions and 41 deletions

View file

@ -952,6 +952,138 @@
window.reduxActions.stickers.useSticker(packId, stickerId);
},
/**
* Sends a reaction message
* @param {object} reaction - The reaction to send
* @param {string} reaction.emoji - The emoji to react with
* @param {boolean} [reaction.remove] - Set to `true` if we are removing a
* reaction with the given emoji
* @param {object} target - The target of the reaction
* @param {string} target.targetAuthorE164 - The E164 address of the target
* message's author
* @param {number} target.targetTimestamp - The sent_at timestamp of the
* target message
*/
async sendReactionMessage(reaction, target) {
if (!window.ENABLE_REACTION_SEND) {
return null;
}
const timestamp = Date.now();
const outgoingReaction = { ...reaction, ...target };
const reactionModel = Whisper.Reactions.add({
...outgoingReaction,
fromId: this.ourNumber || textsecure.storage.user.getNumber(),
timestamp,
fromSync: true,
});
Whisper.Reactions.onReaction(reactionModel);
const destination = this.id;
const recipients = this.getRecipients();
let profileKey;
if (this.get('profileSharing')) {
profileKey = storage.get('profileKey');
}
return this.queueJob(async () => {
window.log.info(
'Sending reaction to conversation',
this.idForLogging(),
'with timestamp',
timestamp
);
// Here we move attachments to disk
const attributes = {
id: window.getGuid(),
type: 'outgoing',
conversationId: destination,
sent_at: timestamp,
received_at: timestamp,
recipients,
reaction: outgoingReaction,
};
if (this.isPrivate()) {
attributes.destination = destination;
}
// We are only creating this model so we can use its sync message
// sending functionality. It will not be saved to the datbase.
const message = new Whisper.Message(attributes);
// We're offline!
if (!textsecure.messaging) {
throw new Error('Cannot send reaction while offline!');
}
// Special-case the self-send case - we send only a sync message
if (this.isMe()) {
const dataMessage = await textsecure.messaging.getMessageProto(
destination,
null,
null,
null,
null,
null,
outgoingReaction,
timestamp,
null,
profileKey
);
return message.sendSyncMessageOnly(dataMessage);
}
const options = this.getSendOptions();
const groupNumbers = this.getRecipients();
const promise = (() => {
if (this.isPrivate()) {
return textsecure.messaging.sendMessageToNumber(
destination,
null,
null,
null,
null,
null,
outgoingReaction,
timestamp,
null,
profileKey,
options
);
}
return textsecure.messaging.sendMessageToGroup(
destination,
groupNumbers,
null,
null,
null,
null,
null,
outgoingReaction,
timestamp,
null,
profileKey,
options
);
})();
return message.send(this.wrapSend(promise));
}).catch(error => {
window.log.error('Error sending reaction', reaction, target, error);
const reverseReaction = reactionModel.clone();
reverseReaction.set('remove', !reverseReaction.get('remove'));
Whisper.Reactions.onReaction(reverseReaction);
throw error;
});
},
sendMessage(body, attachments, quote, preview, sticker) {
this.clearTypingTimers();
@ -1055,6 +1187,7 @@
quote,
preview,
sticker,
null,
now,
expireTimer,
profileKey
@ -1076,6 +1209,7 @@
quote,
preview,
sticker,
null,
now,
expireTimer,
profileKey,
@ -1090,6 +1224,7 @@
quote,
preview,
sticker,
null,
now,
expireTimer,
profileKey,
@ -1401,6 +1536,7 @@
null,
[],
null,
null,
message.get('sent_at'),
expireTimer,
profileKey,