Skip to content

Commit b2e9971

Browse files
committed
added authorId to MessageAttributesType
Lightbox: moved conversationId references to new authorId reference save authorId and conversationId separately
1 parent ac36214 commit b2e9971

File tree

4 files changed

+21
-9
lines changed

4 files changed

+21
-9
lines changed

ts/components/Lightbox.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ function LightboxHeader({
899899
item: ReadonlyDeep<MediaItemType>;
900900
}): JSX.Element {
901901
const { message } = item;
902-
const conversation = getConversation(message.conversationId);
902+
const conversation = getConversation(message.authorId);
903903

904904
const now = Date.now();
905905

ts/model-types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export type MessageAttributesType = {
220220
verified?: boolean;
221221
verifiedChanged?: string;
222222

223+
authorId: string;
223224
id: string;
224225
type: MessageType;
225226
body?: string;

ts/state/ducks/lightbox.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import { AttachmentDownloadUrgency } from '../../types/AttachmentDownload';
4545
import { queueAttachmentDownloads } from '../../util/queueAttachmentDownloads';
4646
import { getMessageIdForLogging } from '../../util/idForLogging';
4747
import { markViewOnceMessageViewed } from '../../services/MessageUpdater';
48+
import type { MessageModel } from '../../models/messages';
4849

4950
// eslint-disable-next-line local-rules/type-alias-readonlydeep
5051
export type LightboxStateType =
@@ -203,6 +204,8 @@ function showLightboxForViewOnceMedia(
203204

204205
const { contentType } = tempAttachment;
205206

207+
const authorId = getAuthorId(message);
208+
206209
const media = [
207210
{
208211
attachment: tempAttachment,
@@ -215,6 +218,7 @@ function showLightboxForViewOnceMedia(
215218
attachments: message.get('attachments') || [],
216219
id: message.get('id'),
217220
conversationId: message.get('conversationId'),
221+
authorId,
218222
receivedAt: message.get('received_at'),
219223
receivedAtMs: Number(message.get('received_at_ms')),
220224
sentAt: message.get('sent_at'),
@@ -235,6 +239,16 @@ function showLightboxForViewOnceMedia(
235239
};
236240
}
237241

242+
function getAuthorId(message: MessageModel) {
243+
return (
244+
window.ConversationController.lookupOrCreate({
245+
serviceId: message.get('sourceServiceId'),
246+
e164: message.get('source'),
247+
reason: 'conversation_view.showLightBox',
248+
})?.id || message.get('conversationId')
249+
);
250+
}
251+
238252
function filterValidAttachments(
239253
attributes: ReadonlyMessageAttributesType
240254
): Array<AttachmentType> {
@@ -297,12 +311,8 @@ function showLightbox(opts: {
297311
const attachments = filterValidAttachments(message.attributes);
298312
const loop = isGIF(attachments);
299313

300-
const authorId =
301-
window.ConversationController.lookupOrCreate({
302-
serviceId: message.get('sourceServiceId'),
303-
e164: message.get('source'),
304-
reason: 'conversation_view.showLightBox',
305-
})?.id || message.get('conversationId');
314+
const authorId = getAuthorId(message);
315+
const conversationId = message.get('conversationId');
306316
const receivedAt = message.get('received_at');
307317
const sentAt = message.get('sent_at');
308318

@@ -322,7 +332,8 @@ function showLightbox(opts: {
322332
message: {
323333
attachments: message.get('attachments') || [],
324334
id: messageId,
325-
conversationId: authorId,
335+
conversationId,
336+
authorId,
326337
receivedAt,
327338
receivedAtMs: Number(message.get('received_at_ms')),
328339
sentAt,

ts/types/MediaItem.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type { MIMEType } from './MIME';
77

88
export type MediaItemMessageType = Pick<
99
ReadonlyMessageAttributesType,
10-
'attachments' | 'conversationId' | 'id'
10+
'attachments' | 'conversationId' | 'authorId' | 'id'
1111
> & {
1212
receivedAt: number;
1313
receivedAtMs?: number;

0 commit comments

Comments
 (0)