Skip to content

Commit d4a198a

Browse files
authored
Merge pull request #1529 from session-foundation/fix-uneeded-local-refs-attachments-id
fix: remove uneeded local refs to attachment ids
2 parents 305b3ca + 53cb46e commit d4a198a

File tree

17 files changed

+62
-46
lines changed

17 files changed

+62
-46
lines changed

protos/SignalService.proto

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ message AttachmentPointer {
261261
}
262262

263263
// @required
264-
required fixed64 id = 1;
264+
required fixed64 deprecated_id = 1;
265265
optional string contentType = 2;
266266
optional bytes key = 3;
267267
optional uint32 size = 4;

ts/components/conversation/ImageGrid.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const Row = (
5959
attachment={attachment}
6060
playIconOverlay={isVideoAttachment(attachment)}
6161
height={renderedSize}
62-
key={attachment.id}
62+
key={attachment.path}
6363
width={renderedSize}
6464
url={isMessageVisible ? getThumbnailUrl(attachment) : undefined}
6565
attachmentIndex={startIndex + index}

ts/components/conversation/right-panel/overlay/message-info/components/AttachmentInfo.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const AttachmentInfo = (props: Props) => {
2626
<Flex $container={true} $flexDirection="column">
2727
<LabelWithInfo
2828
label={tr('attachmentsFileId')}
29-
info={attachment?.id ? String(attachment.id) : tr('attachmentsNa')}
29+
info={attachment?.url ? String(attachment.url) : tr('attachmentsNa')}
3030
/>
3131
<StyledLabelContainer $container={true} $flexDirection="row" $flexWrap="wrap">
3232
<LabelWithInfo

ts/models/message.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ export class MessageModel extends Model<MessageAttributes> {
715715
}
716716

717717
const {
718-
id,
719718
path,
720719
contentType,
721720
width,
@@ -737,7 +736,6 @@ export class MessageModel extends Model<MessageAttributes> {
737736
false;
738737

739738
return {
740-
id,
741739
contentType,
742740
caption,
743741
size: size || 0,
@@ -817,11 +815,12 @@ export class MessageModel extends Model<MessageAttributes> {
817815
fileIdsToLink.push(attachmentIdAsStrFromUrl(preview.image.url));
818816
}
819817

820-
if (quote && quote.attachments?.length) {
818+
if (quote && quote.attachments?.length && quote.attachments[0].thumbnail) {
821819
// typing for all of this Attachment + quote + preview + send or unsend is pretty bad
822-
const firstQuoteAttachmentId = (quote.attachments[0].thumbnail as any)?.id;
823-
if (firstQuoteAttachmentId) {
824-
fileIdsToLink.push(firstQuoteAttachmentId);
820+
const firstQuoteAttachmentUrl =
821+
'url' in quote.attachments[0].thumbnail ? quote.attachments[0].thumbnail.url : undefined;
822+
if (firstQuoteAttachmentUrl && attachmentIdAsStrFromUrl(firstQuoteAttachmentUrl)) {
823+
fileIdsToLink.push(attachmentIdAsStrFromUrl(firstQuoteAttachmentUrl));
825824
}
826825
}
827826

@@ -1105,6 +1104,7 @@ export class MessageModel extends Model<MessageAttributes> {
11051104
}
11061105

11071106
const errorStr = `${providedError.name} - "${providedError.message || 'unknown error message'}"`;
1107+
window.log.info(`save message error to msg ${this.idForLogging()} with error:`, errorStr);
11081108

11091109
this.set({ errors: errorStr });
11101110
await this.commit();

ts/receiver/attachments.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { omit, startsWith } from 'lodash';
22

33
import { MessageModel } from '../models/message';
44
import { Data } from '../data/data';
5-
import { AttachmentDownloads } from '../session/utils';
5+
import { AttachmentDownloads, attachmentIdAsStrFromUrl } from '../session/utils';
66
import { ConversationModel } from '../models/conversation';
77
import { getUnpaddedAttachment } from '../session/crypto/BufferPadding';
88
import { decryptAttachment } from '../util/crypto/attachmentsEncrypter';
@@ -32,7 +32,7 @@ export async function downloadAttachment(attachment: {
3232
let res: ArrayBuffer | null = null;
3333
// try to get the fileId from the end of the URL
3434

35-
const attachmentId = attachment.id || attachment.url;
35+
const attachmentId = attachmentIdAsStrFromUrl(attachment.url);
3636
if (!defaultFileServer) {
3737
window.log.warn(
3838
`downloadAttachment attachment is neither opengroup attachment nor fileserver... Dropping it ${asURL.href}`
@@ -92,7 +92,6 @@ export async function downloadAttachment(attachment: {
9292
*/
9393
export async function downloadAttachmentSogsV3(
9494
attachment: {
95-
id: number;
9695
url: string;
9796
size: number | null;
9897
},
@@ -103,7 +102,10 @@ export async function downloadAttachmentSogsV3(
103102
throw new Error(`Didn't find such a room ${roomInfos.serverUrl}: ${roomInfos.roomId}`);
104103
}
105104

106-
const dataUint = await sogsV3FetchFileByFileID(roomDetails, `${attachment.id}`);
105+
const dataUint = await sogsV3FetchFileByFileID(
106+
roomDetails,
107+
attachmentIdAsStrFromUrl(attachment.url)
108+
);
107109

108110
if (!dataUint?.length) {
109111
window?.log?.error('Failed to download attachment. Length is 0');

ts/receiver/dataMessage.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import { GroupV2Receiver } from './groupv2/handleGroupV2Message';
2929
import { ConversationTypeEnum } from '../models/types';
3030
import { ed25519Str } from '../session/utils/String';
3131

32-
function cleanAttachment(attachment: any) {
32+
function cleanAttachment(attachment: SignalService.IAttachmentPointer) {
3333
return {
3434
...omit(attachment, 'thumbnail'),
35-
id: attachment.id.toString(),
35+
id: 0,
3636
key: attachment.key ? StringUtils.decode(attachment.key, 'base64') : null,
3737
digest:
3838
attachment.digest && attachment.digest.length > 0

ts/session/apis/file_server_api/FileServerApi.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const uploadFileToFsWithOnionV4 = async (
6060
return null;
6161
}
6262

63-
const fileId = result?.body?.id as number | undefined;
63+
const fileId = result?.body?.id as string | undefined;
6464
const expires = result?.body?.expires as number; // expires is returned as a floating point timestamp in seconds, i.e. 1754863793.186137.
6565
if (
6666
!fileId ||

ts/session/apis/open_group_api/sogsv3/sogsV3BatchPoll.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ export type SubRequestUpdateRoomType = {
204204
type: 'updateRoom';
205205
updateRoom: {
206206
roomId: string;
207+
// imageId has to be a number to be understood by the sogs
207208
imageId: number; // the fileId uploaded to this sogs and to be referenced as preview/room image
208209
// name and other options are unsupported for now
209210
};

ts/session/apis/open_group_api/sogsv3/sogsV3RoomImage.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import AbortController from 'abort-controller';
2-
import { isNumber } from 'lodash';
2+
import { isString, toNumber } from 'lodash';
33
import { batchFirstSubIsSuccess, batchGlobalIsSuccess, sogsBatchSend } from './sogsV3BatchPoll';
44
import { uploadFileToRoomSogs3 } from './sogsV3SendFile';
55
import { OpenGroupRequestCommonType } from '../../../../data/types';
@@ -17,25 +17,30 @@ import { DURATION } from '../../../constants';
1717
export const uploadImageForRoomSogsV3 = async (
1818
fileContent: Uint8Array,
1919
roomInfos: OpenGroupRequestCommonType
20-
): Promise<{ fileUrl: string; fileId: number } | null> => {
20+
): Promise<{ fileUrl: string } | null> => {
2121
if (!fileContent || !fileContent.length) {
2222
return null;
2323
}
2424

2525
const result = await uploadFileToRoomSogs3(fileContent, roomInfos);
26-
if (!result || !isNumber(result.fileId)) {
26+
if (!result || !isString(result.fileId)) {
2727
return null;
2828
}
29-
const { fileId, fileUrl } = result;
30-
if (!fileId || !fileContent.length) {
29+
const { fileUrl } = result;
30+
if (!fileContent.length) {
3131
return null;
3232
}
3333

3434
const batchResult = await sogsBatchSend(
3535
roomInfos.serverUrl,
3636
new Set([roomInfos.roomId]),
3737
new AbortController().signal,
38-
[{ type: 'updateRoom', updateRoom: { roomId: roomInfos.roomId, imageId: fileId } }],
38+
[
39+
{
40+
type: 'updateRoom',
41+
updateRoom: { roomId: roomInfos.roomId, imageId: toNumber(result.fileId) },
42+
},
43+
],
3944
'batch',
4045
30 * DURATION.SECONDS // longer time for image upload
4146
);
@@ -45,6 +50,5 @@ export const uploadImageForRoomSogsV3 = async (
4550
}
4651
return {
4752
fileUrl,
48-
fileId,
4953
};
5054
};

ts/session/apis/open_group_api/sogsv3/sogsV3SendFile.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isNumber } from 'lodash';
12
import AbortController from 'abort-controller';
23
import { OpenGroupData } from '../../../../data/opengroups';
34
import { roomHasBlindEnabled } from '../../../../types/sqlSharedTypes';
@@ -12,7 +13,7 @@ import { DURATION } from '../../../constants';
1213
export const uploadFileToRoomSogs3 = async (
1314
fileContent: Uint8Array,
1415
roomInfos: OpenGroupRequestCommonType
15-
): Promise<{ fileId: number; fileUrl: string } | null> => {
16+
): Promise<{ fileUrl: string; fileId: string } | null> => {
1617
if (!fileContent || !fileContent.length) {
1718
return null;
1819
}
@@ -40,13 +41,14 @@ export const uploadFileToRoomSogs3 = async (
4041
}
4142

4243
const fileId = (result?.body as any | undefined)?.id as number | undefined;
43-
if (!fileId) {
44+
45+
if (!fileId || !isNumber(fileId)) {
4446
return null;
4547
}
4648
const fileUrl = `${roomInfos.serverUrl}/room/${roomDetails.roomId}/file/${fileId}`;
4749

4850
return {
49-
fileId,
5051
fileUrl,
52+
fileId: `${fileId}`,
5153
};
5254
};

0 commit comments

Comments
 (0)