Skip to content

Commit 45eef8e

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

File tree

4 files changed

+22
-10
lines changed

4 files changed

+22
-10
lines changed

ts/components/Lightbox.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export function Lightbox({
190190

191191
const handleJumpToConversation = useCallback(
192192
(
193-
event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
193+
_event: KeyboardEvent | React.MouseEvent<HTMLButtonElement, MouseEvent>
194194
) => {
195195
if (isViewOnce) {
196196
return;
@@ -828,7 +828,7 @@ function LightboxHeader({
828828
i18n: LocalizerType;
829829
message: ReadonlyDeep<MediaItemMessageType>;
830830
}): JSX.Element {
831-
const conversation = getConversation(message.conversationId);
831+
const conversation = getConversation(message.authorId);
832832

833833
const now = Date.now();
834834

ts/model-types.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ export type MessageAttributesType = {
217217
verified?: boolean;
218218
verifiedChanged?: string;
219219

220+
authorId: string;
220221
id: string;
221222
type: MessageType;
222223
body?: string;

ts/state/ducks/lightbox.ts

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import { showStickerPackPreview } from './globalModals';
4141
import { useBoundActions } from '../../hooks/useBoundActions';
4242
import { DataReader } from '../../sql/Client';
43+
import { MessageModel } from '../../models/messages';
4344

4445
// eslint-disable-next-line local-rules/type-alias-readonlydeep
4546
export type LightboxStateType =
@@ -196,6 +197,8 @@ function showLightboxForViewOnceMedia(
196197

197198
const { contentType } = tempAttachment;
198199

200+
const authorId = getAuthorId(message);
201+
199202
const media = [
200203
{
201204
attachment: tempAttachment,
@@ -208,6 +211,7 @@ function showLightboxForViewOnceMedia(
208211
attachments: message.get('attachments') || [],
209212
id: message.get('id'),
210213
conversationId: message.get('conversationId'),
214+
authorId,
211215
receivedAt: message.get('received_at'),
212216
receivedAtMs: Number(message.get('received_at_ms')),
213217
sentAt: message.get('sent_at'),
@@ -228,6 +232,16 @@ function showLightboxForViewOnceMedia(
228232
};
229233
}
230234

235+
function getAuthorId(message: MessageModel) {
236+
return (
237+
window.ConversationController.lookupOrCreate({
238+
serviceId: message.get('sourceServiceId'),
239+
e164: message.get('source'),
240+
reason: 'conversation_view.showLightBox',
241+
})?.id || message.get('conversationId')
242+
);
243+
}
244+
231245
function filterValidAttachments(
232246
attributes: ReadonlyMessageAttributesType
233247
): Array<AttachmentType> {
@@ -278,12 +292,8 @@ function showLightbox(opts: {
278292
const attachments = filterValidAttachments(message.attributes);
279293
const loop = isGIF(attachments);
280294

281-
const authorId =
282-
window.ConversationController.lookupOrCreate({
283-
serviceId: message.get('sourceServiceId'),
284-
e164: message.get('source'),
285-
reason: 'conversation_view.showLightBox',
286-
})?.id || message.get('conversationId');
295+
const authorId = getAuthorId(message);
296+
const conversationId = message.get('conversationId');
287297
const receivedAt = message.get('received_at');
288298
const sentAt = message.get('sent_at');
289299

@@ -296,7 +306,8 @@ function showLightbox(opts: {
296306
message: {
297307
attachments: message.get('attachments') || [],
298308
id: messageId,
299-
conversationId: authorId,
309+
conversationId,
310+
authorId,
300311
receivedAt,
301312
receivedAtMs: Number(message.get('received_at_ms')),
302313
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)