1
1
import ByteBuffer from 'bytebuffer' ;
2
2
import { isEmpty } from 'lodash' ;
3
+ import Long from 'long' ;
3
4
import { SignalService } from '../../../../protobuf' ;
4
5
import { Reaction } from '../../../../types/Reaction' ;
5
6
import { DataMessage } from '../DataMessage' ;
6
7
import { LokiProfile } from '../../../../types/message' ;
7
8
import { ExpirableMessageParams } from '../ExpirableMessage' ;
9
+ import { attachmentIdAsLongFromUrl } from '../../../utils' ;
8
10
9
11
interface AttachmentPointerCommon {
10
12
contentType ?: string ;
@@ -21,12 +23,10 @@ interface AttachmentPointerCommon {
21
23
22
24
export interface AttachmentPointer extends AttachmentPointerCommon {
23
25
url ?: string ;
24
- id ?: number ;
25
26
}
26
27
27
28
export interface AttachmentPointerWithUrl extends AttachmentPointerCommon {
28
29
url : string ;
29
- id : number ;
30
30
}
31
31
32
32
export interface Preview {
@@ -37,7 +37,6 @@ export interface Preview {
37
37
38
38
export interface PreviewWithAttachmentUrl {
39
39
url : string ;
40
- id : number ;
41
40
title ?: string ;
42
41
image ?: AttachmentPointerWithUrl ;
43
42
}
@@ -75,12 +74,12 @@ export interface VisibleMessageParams extends ExpirableMessageParams {
75
74
export class VisibleMessage extends DataMessage {
76
75
public readonly reaction ?: Reaction ;
77
76
78
- private readonly attachments ?: Array < AttachmentPointerWithUrl > ;
77
+ private readonly attachments ?: Array < AttachmentPointerWithUrl & { id : Long } > ;
79
78
private readonly body ?: string ;
80
79
private readonly quote ?: Quote ;
81
80
private readonly profileKey ?: Uint8Array ;
82
81
private readonly profile ?: SignalService . DataMessage . ILokiProfile ;
83
- private readonly preview ?: Array < PreviewWithAttachmentUrl > ;
82
+ private readonly preview ?: Array < PreviewWithAttachmentUrl & { id ?: Long } > ;
84
83
85
84
/// In the case of a sync message, the public key of the person the message was targeted at.
86
85
/// - Note: `null or undefined` if this isn't a sync message.
@@ -93,7 +92,10 @@ export class VisibleMessage extends DataMessage {
93
92
expirationType : params . expirationType ,
94
93
expireTimer : params . expireTimer ,
95
94
} ) ;
96
- this . attachments = params . attachments ;
95
+ this . attachments = params . attachments ?. map ( attachment => ( {
96
+ ...attachment ,
97
+ id : attachmentIdAsLongFromUrl ( attachment . url ) ,
98
+ } ) ) ;
97
99
this . body = params . body ;
98
100
this . quote = params . quote ;
99
101
@@ -102,7 +104,10 @@ export class VisibleMessage extends DataMessage {
102
104
this . profile = profile . lokiProfile ;
103
105
this . profileKey = profile . profileKey ;
104
106
105
- this . preview = params . preview ;
107
+ this . preview = params . preview ?. map ( attachment => ( {
108
+ ...attachment ,
109
+ id : attachment . image ?. url ? attachmentIdAsLongFromUrl ( attachment . image . url ) : undefined ,
110
+ } ) ) ;
106
111
this . reaction = params . reaction ;
107
112
this . syncTarget = params . syncTarget ;
108
113
}
@@ -122,9 +127,6 @@ export class VisibleMessage extends DataMessage {
122
127
123
128
dataMessage . attachments = this . attachments || [ ] ;
124
129
125
- if ( this . preview ) {
126
- dataMessage . preview = this . preview ;
127
- }
128
130
if ( this . reaction ) {
129
131
dataMessage . reaction = this . reaction ;
130
132
}
@@ -173,7 +175,9 @@ export class VisibleMessage extends DataMessage {
173
175
if ( preview . url ) {
174
176
item . url = preview . url ;
175
177
}
176
- item . image = preview . image || null ;
178
+ item . image = preview . image
179
+ ? { ...preview . image , id : attachmentIdAsLongFromUrl ( preview . image . url ) }
180
+ : null ;
177
181
178
182
return item ;
179
183
} ) ;
0 commit comments