Include authorUuid when sending replies

This commit is contained in:
Josh Perez 2022-03-11 18:14:32 -05:00 committed by GitHub
parent 4123c12303
commit 2114c851c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 36 deletions

View file

@ -19,7 +19,7 @@ import {
} from '../../state/selectors/message'; } from '../../state/selectors/message';
import type { AttachmentType } from '../../textsecure/SendMessage'; import type { AttachmentType } from '../../textsecure/SendMessage';
import type { LinkPreviewType } from '../../types/message/LinkPreviews'; 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 { WhatIsThis } from '../../window.d';
import type { LoggerType } from '../../types/Logging'; import type { LoggerType } from '../../types/Logging';
import type { import type {
@ -141,7 +141,7 @@ export async function sendNormalMessage(
preview, preview,
quote, quote,
sticker, sticker,
storyContextTimestamp, storyContext,
} = await getMessageSendData({ log, message }); } = await getMessageSendData({ log, message });
let messageSendPromise: Promise<CallbackResultType | void>; let messageSendPromise: Promise<CallbackResultType | void>;
@ -254,7 +254,7 @@ export async function sendNormalMessage(
groupId: undefined, groupId: undefined,
profileKey, profileKey,
options: sendOptions, options: sendOptions,
storyContextTimestamp, storyContext,
}); });
} }
@ -402,7 +402,7 @@ async function getMessageSendData({
preview: Array<LinkPreviewType>; preview: Array<LinkPreviewType>;
quote: WhatIsThis; quote: WhatIsThis;
sticker: WhatIsThis; sticker: WhatIsThis;
storyContextTimestamp?: number; storyContext?: StoryContextType;
}> { }> {
const { const {
loadAttachmentData, loadAttachmentData,
@ -426,18 +426,22 @@ async function getMessageSendData({
messageTimestamp = Date.now(); messageTimestamp = Date.now();
} }
const [attachmentsWithData, preview, quote, sticker] = await Promise.all([ const storyId = message.get('storyId');
// 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 const [attachmentsWithData, preview, quote, sticker, storyMessage] =
// a failed message across restarts, we don't touch the cache for simplicity. If await Promise.all([
// sends are failing, let's not add the complication of a cache. // We don't update the caches here because (1) we expect the caches to be populated
Promise.all((message.get('attachments') ?? []).map(loadAttachmentData)), // on initial send, so they should be there in the 99% case (2) if you're retrying
message.cachedOutgoingPreviewData || // a failed message across restarts, we don't touch the cache for simplicity. If
loadPreviewData(message.get('preview')), // sends are failing, let's not add the complication of a cache.
message.cachedOutgoingQuoteData || loadQuoteData(message.get('quote')), Promise.all((message.get('attachments') ?? []).map(loadAttachmentData)),
message.cachedOutgoingStickerData || message.cachedOutgoingPreviewData ||
loadStickerData(message.get('sticker')), 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( const { body, attachments } = window.Whisper.Message.getLongMessageAttachment(
{ {
@ -457,8 +461,11 @@ async function getMessageSendData({
preview, preview,
quote, quote,
sticker, sticker,
storyContextTimestamp: message.get('storyId') storyContext: storyMessage
? message.get('sent_at') ? {
authorUuid: storyMessage.get('sourceUuid'),
timestamp: storyMessage.get('sent_at'),
}
: undefined, : undefined,
}; };
} }

View file

@ -204,6 +204,12 @@ export async function sendReaction(
return; return;
} }
let storyMessage: MessageModel | undefined;
const storyId = message.get('storyId');
if (storyId) {
storyMessage = await getMessageById(storyId);
}
log.info('sending direct reaction message'); log.info('sending direct reaction message');
promise = window.textsecure.messaging.sendMessageToIdentifier({ promise = window.textsecure.messaging.sendMessageToIdentifier({
identifier: recipientIdentifiersWithoutMe[0], identifier: recipientIdentifiersWithoutMe[0],
@ -220,7 +226,12 @@ export async function sendReaction(
groupId: undefined, groupId: undefined,
profileKey, profileKey,
options: sendOptions, options: sendOptions,
storyContextTimestamp: message.get('sent_at'), storyContext: storyMessage
? {
authorUuid: storyMessage.get('sourceUuid'),
timestamp: storyMessage.get('sent_at'),
}
: undefined,
}); });
} else { } else {
log.info('sending group reaction message'); log.info('sending group reaction message');

View file

@ -160,7 +160,7 @@ function reactToStory(
function replyToStory( function replyToStory(
conversationId: string, conversationId: string,
message: string, messageBody: string,
mentions: Array<BodyRangeType>, mentions: Array<BodyRangeType>,
timestamp: number, timestamp: number,
story: StoryViewType story: StoryViewType
@ -169,7 +169,7 @@ function replyToStory(
if (conversation) { if (conversation) {
conversation.enqueueMessageForSend( conversation.enqueueMessageForSend(
message, messageBody,
[], [],
undefined, undefined,
undefined, undefined,

View file

@ -59,7 +59,7 @@ import {
SendMessageProtoError, SendMessageProtoError,
HTTPError, HTTPError,
} from './Errors'; } from './Errors';
import type { BodyRangesType } from '../types/Util'; import type { BodyRangesType, StoryContextType } from '../types/Util';
import type { import type {
LinkPreviewImage, LinkPreviewImage,
LinkPreviewMetadata, LinkPreviewMetadata,
@ -193,7 +193,7 @@ export type MessageOptionsType = {
timestamp: number; timestamp: number;
mentions?: BodyRangesType; mentions?: BodyRangesType;
groupCallUpdate?: GroupCallUpdateType; groupCallUpdate?: GroupCallUpdateType;
storyContextTimestamp?: number; storyContext?: StoryContextType;
}; };
export type GroupSendOptionsType = { export type GroupSendOptionsType = {
attachments?: Array<AttachmentType>; attachments?: Array<AttachmentType>;
@ -211,7 +211,7 @@ export type GroupSendOptionsType = {
timestamp: number; timestamp: number;
mentions?: BodyRangesType; mentions?: BodyRangesType;
groupCallUpdate?: GroupCallUpdateType; groupCallUpdate?: GroupCallUpdateType;
storyContextTimestamp?: number; storyContext?: StoryContextType;
}; };
class Message { class Message {
@ -256,7 +256,7 @@ class Message {
groupCallUpdate?: GroupCallUpdateType; groupCallUpdate?: GroupCallUpdateType;
storyContextTimestamp?: number; storyContext?: StoryContextType;
constructor(options: MessageOptionsType) { constructor(options: MessageOptionsType) {
this.attachments = options.attachments || []; this.attachments = options.attachments || [];
@ -276,7 +276,7 @@ class Message {
this.deletedForEveryoneTimestamp = options.deletedForEveryoneTimestamp; this.deletedForEveryoneTimestamp = options.deletedForEveryoneTimestamp;
this.mentions = options.mentions; this.mentions = options.mentions;
this.groupCallUpdate = options.groupCallUpdate; this.groupCallUpdate = options.groupCallUpdate;
this.storyContextTimestamp = options.storyContextTimestamp; this.storyContext = options.storyContext;
if (!(this.recipients instanceof Array)) { if (!(this.recipients instanceof Array)) {
throw new Error('Invalid recipient list'); throw new Error('Invalid recipient list');
@ -477,14 +477,14 @@ class Message {
proto.groupCallUpdate = groupCallUpdate; proto.groupCallUpdate = groupCallUpdate;
} }
if (this.storyContextTimestamp) { if (this.storyContext) {
const { StoryContext } = Proto.DataMessage; const { StoryContext } = Proto.DataMessage;
const storyContext = new StoryContext(); const storyContext = new StoryContext();
storyContext.authorUuid = String( if (this.storyContext.authorUuid) {
window.textsecure.storage.user.getCheckedUuid() storyContext.authorUuid = this.storyContext.authorUuid;
); }
storyContext.sentTimestamp = this.storyContextTimestamp; storyContext.sentTimestamp = this.storyContext.timestamp;
proto.storyContext = storyContext; proto.storyContext = storyContext;
} }
@ -798,7 +798,7 @@ export default class MessageSender {
quote, quote,
reaction, reaction,
sticker, sticker,
storyContextTimestamp, storyContext,
timestamp, timestamp,
} = options; } = options;
@ -853,7 +853,7 @@ export default class MessageSender {
reaction, reaction,
recipients, recipients,
sticker, sticker,
storyContextTimestamp, storyContext,
timestamp, timestamp,
}; };
} }
@ -1043,7 +1043,7 @@ export default class MessageSender {
groupId, groupId,
profileKey, profileKey,
options, options,
storyContextTimestamp, storyContext,
}: Readonly<{ }: Readonly<{
identifier: string; identifier: string;
messageText: string | undefined; messageText: string | undefined;
@ -1058,7 +1058,7 @@ export default class MessageSender {
contentHint: number; contentHint: number;
groupId: string | undefined; groupId: string | undefined;
profileKey?: Uint8Array; profileKey?: Uint8Array;
storyContextTimestamp?: number; storyContext?: StoryContextType;
options?: SendOptionsType; options?: SendOptionsType;
}>): Promise<CallbackResultType> { }>): Promise<CallbackResultType> {
return this.sendMessage({ return this.sendMessage({
@ -1074,7 +1074,7 @@ export default class MessageSender {
deletedForEveryoneTimestamp, deletedForEveryoneTimestamp,
expireTimer, expireTimer,
profileKey, profileKey,
storyContextTimestamp, storyContext,
}, },
contentHint, contentHint,
groupId, groupId,

View file

@ -1,6 +1,8 @@
// Copyright 2018-2021 Signal Messenger, LLC // Copyright 2018-2021 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only // SPDX-License-Identifier: AGPL-3.0-only
import type { UUIDStringType } from './UUID';
export type BodyRangeType = { export type BodyRangeType = {
start: number; start: number;
length: number; length: number;
@ -11,6 +13,11 @@ export type BodyRangeType = {
export type BodyRangesType = Array<BodyRangeType>; export type BodyRangesType = Array<BodyRangeType>;
export type StoryContextType = {
authorUuid?: UUIDStringType;
timestamp: number;
};
export type RenderTextCallbackType = (options: { export type RenderTextCallbackType = (options: {
text: string; text: string;
key: number; key: number;