Skip to content

Commit

Permalink
Include authorUuid when sending replies
Browse files Browse the repository at this point in the history
Co-authored-by: Josh Perez <60019601+josh-signal@users.noreply.github.com>
  • Loading branch information
automated-signal and josh-signal committed Mar 11, 2022
1 parent c4e1322 commit 7db8014
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 36 deletions.
43 changes: 25 additions & 18 deletions ts/jobs/helpers/sendNormalMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
} from '../../state/selectors/message';
import type { AttachmentType } from '../../textsecure/SendMessage';
import type { LinkPreviewType } from '../../types/message/LinkPreviews';
import type { BodyRangesType } from '../../types/Util';
import type { BodyRangesType, StoryContextType } from '../../types/Util';
import type { WhatIsThis } from '../../window.d';
import type { LoggerType } from '../../types/Logging';
import type {
Expand Down Expand Up @@ -141,7 +141,7 @@ export async function sendNormalMessage(
preview,
quote,
sticker,
storyContextTimestamp,
storyContext,
} = await getMessageSendData({ log, message });

let messageSendPromise: Promise<CallbackResultType | void>;
Expand Down Expand Up @@ -254,7 +254,7 @@ export async function sendNormalMessage(
groupId: undefined,
profileKey,
options: sendOptions,
storyContextTimestamp,
storyContext,
});
}

Expand Down Expand Up @@ -402,7 +402,7 @@ async function getMessageSendData({
preview: Array<LinkPreviewType>;
quote: WhatIsThis;
sticker: WhatIsThis;
storyContextTimestamp?: number;
storyContext?: StoryContextType;
}> {
const {
loadAttachmentData,
Expand All @@ -426,18 +426,22 @@ async function getMessageSendData({
messageTimestamp = Date.now();
}

const [attachmentsWithData, preview, quote, sticker] = await Promise.all([
// We don't update the caches here because (1) we expect the caches to be populated
// on initial send, so they should be there in the 99% case (2) if you're retrying
// a failed message across restarts, we don't touch the cache for simplicity. If
// sends are failing, let's not add the complication of a cache.
Promise.all((message.get('attachments') ?? []).map(loadAttachmentData)),
message.cachedOutgoingPreviewData ||
loadPreviewData(message.get('preview')),
message.cachedOutgoingQuoteData || loadQuoteData(message.get('quote')),
message.cachedOutgoingStickerData ||
loadStickerData(message.get('sticker')),
]);
const storyId = message.get('storyId');

const [attachmentsWithData, preview, quote, sticker, storyMessage] =
await Promise.all([
// We don't update the caches here because (1) we expect the caches to be populated
// on initial send, so they should be there in the 99% case (2) if you're retrying
// a failed message across restarts, we don't touch the cache for simplicity. If
// sends are failing, let's not add the complication of a cache.
Promise.all((message.get('attachments') ?? []).map(loadAttachmentData)),
message.cachedOutgoingPreviewData ||
loadPreviewData(message.get('preview')),
message.cachedOutgoingQuoteData || loadQuoteData(message.get('quote')),
message.cachedOutgoingStickerData ||
loadStickerData(message.get('sticker')),
storyId ? getMessageById(storyId) : undefined,
]);

const { body, attachments } = window.Whisper.Message.getLongMessageAttachment(
{
Expand All @@ -457,8 +461,11 @@ async function getMessageSendData({
preview,
quote,
sticker,
storyContextTimestamp: message.get('storyId')
? message.get('sent_at')
storyContext: storyMessage
? {
authorUuid: storyMessage.get('sourceUuid'),
timestamp: storyMessage.get('sent_at'),
}
: undefined,
};
}
Expand Down
13 changes: 12 additions & 1 deletion ts/jobs/helpers/sendReaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,12 @@ export async function sendReaction(
return;
}

let storyMessage: MessageModel | undefined;
const storyId = message.get('storyId');
if (storyId) {
storyMessage = await getMessageById(storyId);
}

log.info('sending direct reaction message');
promise = window.textsecure.messaging.sendMessageToIdentifier({
identifier: recipientIdentifiersWithoutMe[0],
Expand All @@ -220,7 +226,12 @@ export async function sendReaction(
groupId: undefined,
profileKey,
options: sendOptions,
storyContextTimestamp: message.get('sent_at'),
storyContext: storyMessage
? {
authorUuid: storyMessage.get('sourceUuid'),
timestamp: storyMessage.get('sent_at'),
}
: undefined,
});
} else {
log.info('sending group reaction message');
Expand Down
4 changes: 2 additions & 2 deletions ts/state/ducks/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function reactToStory(

function replyToStory(
conversationId: string,
message: string,
messageBody: string,
mentions: Array<BodyRangeType>,
timestamp: number,
story: StoryViewType
Expand All @@ -169,7 +169,7 @@ function replyToStory(

if (conversation) {
conversation.enqueueMessageForSend(
message,
messageBody,
[],
undefined,
undefined,
Expand Down
30 changes: 15 additions & 15 deletions ts/textsecure/SendMessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
SendMessageProtoError,
HTTPError,
} from './Errors';
import type { BodyRangesType } from '../types/Util';
import type { BodyRangesType, StoryContextType } from '../types/Util';
import type {
LinkPreviewImage,
LinkPreviewMetadata,
Expand Down Expand Up @@ -193,7 +193,7 @@ export type MessageOptionsType = {
timestamp: number;
mentions?: BodyRangesType;
groupCallUpdate?: GroupCallUpdateType;
storyContextTimestamp?: number;
storyContext?: StoryContextType;
};
export type GroupSendOptionsType = {
attachments?: Array<AttachmentType>;
Expand All @@ -211,7 +211,7 @@ export type GroupSendOptionsType = {
timestamp: number;
mentions?: BodyRangesType;
groupCallUpdate?: GroupCallUpdateType;
storyContextTimestamp?: number;
storyContext?: StoryContextType;
};

class Message {
Expand Down Expand Up @@ -256,7 +256,7 @@ class Message {

groupCallUpdate?: GroupCallUpdateType;

storyContextTimestamp?: number;
storyContext?: StoryContextType;

constructor(options: MessageOptionsType) {
this.attachments = options.attachments || [];
Expand All @@ -276,7 +276,7 @@ class Message {
this.deletedForEveryoneTimestamp = options.deletedForEveryoneTimestamp;
this.mentions = options.mentions;
this.groupCallUpdate = options.groupCallUpdate;
this.storyContextTimestamp = options.storyContextTimestamp;
this.storyContext = options.storyContext;

if (!(this.recipients instanceof Array)) {
throw new Error('Invalid recipient list');
Expand Down Expand Up @@ -477,14 +477,14 @@ class Message {
proto.groupCallUpdate = groupCallUpdate;
}

if (this.storyContextTimestamp) {
if (this.storyContext) {
const { StoryContext } = Proto.DataMessage;

const storyContext = new StoryContext();
storyContext.authorUuid = String(
window.textsecure.storage.user.getCheckedUuid()
);
storyContext.sentTimestamp = this.storyContextTimestamp;
if (this.storyContext.authorUuid) {
storyContext.authorUuid = this.storyContext.authorUuid;
}
storyContext.sentTimestamp = this.storyContext.timestamp;

proto.storyContext = storyContext;
}
Expand Down Expand Up @@ -798,7 +798,7 @@ export default class MessageSender {
quote,
reaction,
sticker,
storyContextTimestamp,
storyContext,
timestamp,
} = options;

Expand Down Expand Up @@ -853,7 +853,7 @@ export default class MessageSender {
reaction,
recipients,
sticker,
storyContextTimestamp,
storyContext,
timestamp,
};
}
Expand Down Expand Up @@ -1043,7 +1043,7 @@ export default class MessageSender {
groupId,
profileKey,
options,
storyContextTimestamp,
storyContext,
}: Readonly<{
identifier: string;
messageText: string | undefined;
Expand All @@ -1058,7 +1058,7 @@ export default class MessageSender {
contentHint: number;
groupId: string | undefined;
profileKey?: Uint8Array;
storyContextTimestamp?: number;
storyContext?: StoryContextType;
options?: SendOptionsType;
}>): Promise<CallbackResultType> {
return this.sendMessage({
Expand All @@ -1074,7 +1074,7 @@ export default class MessageSender {
deletedForEveryoneTimestamp,
expireTimer,
profileKey,
storyContextTimestamp,
storyContext,
},
contentHint,
groupId,
Expand Down
7 changes: 7 additions & 0 deletions ts/types/Util.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only

import type { UUIDStringType } from './UUID';

export type BodyRangeType = {
start: number;
length: number;
Expand All @@ -11,6 +13,11 @@ export type BodyRangeType = {

export type BodyRangesType = Array<BodyRangeType>;

export type StoryContextType = {
authorUuid?: UUIDStringType;
timestamp: number;
};

export type RenderTextCallbackType = (options: {
text: string;
key: number;
Expand Down

0 comments on commit 7db8014

Please sign in to comment.