1
1
import AbortController , { AbortSignal } from 'abort-controller' ;
2
2
import { isUndefined , toNumber } from 'lodash' ;
3
- import { OpenGroupV2Room , OpenGroupV2RoomWithImageID } from '../../../../data/opengroups' ;
3
+ import {
4
+ OpenGroupData ,
5
+ OpenGroupV2Room ,
6
+ OpenGroupV2RoomWithImageID ,
7
+ } from '../../../../data/opengroups' ;
4
8
import { MIME } from '../../../../types' ;
5
9
import { processNewAttachment } from '../../../../types/MessageAttachment' ;
6
10
import { callUtilsWorker } from '../../../../webworker/workers/util_worker_interface' ;
@@ -16,7 +20,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
16
20
serverPubkey : string ;
17
21
blinded : boolean ;
18
22
abortSignal : AbortSignal ;
19
- doNotIncludeOurSogsHeaders ?: boolean ;
20
23
headers : Record < string , any > | null ;
21
24
roomId : string ;
22
25
fileId : string ;
@@ -28,7 +31,6 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
28
31
blinded,
29
32
abortSignal,
30
33
headers : includedHeaders ,
31
- doNotIncludeOurSogsHeaders,
32
34
roomId,
33
35
fileId,
34
36
throwError,
@@ -41,15 +43,13 @@ export async function fetchBinaryFromSogsWithOnionV4(sendOptions: {
41
43
throw new Error ( 'endpoint needs a leading /' ) ;
42
44
}
43
45
const builtUrl = new URL ( `${ serverUrl } ${ endpoint } ` ) ;
44
- let headersWithSogsHeadersIfNeeded = doNotIncludeOurSogsHeaders
45
- ? { }
46
- : await OpenGroupPollingUtils . getOurOpenGroupHeaders (
47
- serverPubkey ,
48
- endpoint ,
49
- method ,
50
- blinded ,
51
- stringifiedBody
52
- ) ;
46
+ let headersWithSogsHeadersIfNeeded = await OpenGroupPollingUtils . getOurOpenGroupHeaders (
47
+ serverPubkey ,
48
+ endpoint ,
49
+ method ,
50
+ blinded ,
51
+ stringifiedBody
52
+ ) ;
53
53
54
54
if ( isUndefined ( headersWithSogsHeadersIfNeeded ) ) {
55
55
return null ;
@@ -98,12 +98,15 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
98
98
return ;
99
99
}
100
100
101
+ const room = OpenGroupData . getV2OpenGroupRoom ( convoId ) ;
102
+ const blinded = roomHasBlindEnabled ( room ) ;
103
+
101
104
// make sure this runs only once for each rooms.
102
- // we don't want to trigger one of those on each setPollInfo resultsas it happens on each batch poll.
103
- const oneAtAtimeResult = ( await allowOnlyOneAtATime (
105
+ // we don't want to trigger one of those on each setPollInfo results as it happens on each batch poll.
106
+ const oneAtAtimeResult = await allowOnlyOneAtATime (
104
107
`sogsV3FetchPreview-${ serverUrl } -${ roomId } ` ,
105
- ( ) => sogsV3FetchPreview ( roomInfos )
106
- ) ) as Uint8Array | null ; // force the return type as allowOnlyOneAtATime does not keep it
108
+ ( ) => sogsV3FetchPreview ( roomInfos , blinded )
109
+ ) ;
107
110
108
111
if ( ! oneAtAtimeResult || ! oneAtAtimeResult ?. byteLength ) {
109
112
window ?. log ?. warn ( 'sogsV3FetchPreviewAndSaveIt failed for room: ' , roomId ) ;
@@ -139,7 +142,7 @@ export async function sogsV3FetchPreviewAndSaveIt(roomInfos: OpenGroupV2RoomWith
139
142
* @returns the fetchedData in base64
140
143
*/
141
144
export async function sogsV3FetchPreviewBase64 ( roomInfos : OpenGroupV2RoomWithImageID ) {
142
- const fetched = await sogsV3FetchPreview ( roomInfos ) ;
145
+ const fetched = await sogsV3FetchPreview ( roomInfos , true ) ; // left pane are session official default rooms, which do require blinded
143
146
if ( fetched && fetched . byteLength ) {
144
147
return callUtilsWorker ( 'arrayBufferToStringBase64' , fetched ) ;
145
148
}
@@ -155,7 +158,8 @@ export async function sogsV3FetchPreviewBase64(roomInfos: OpenGroupV2RoomWithIma
155
158
* Those default rooms do not have a conversation associated with them, as they are not joined yet
156
159
*/
157
160
const sogsV3FetchPreview = async (
158
- roomInfos : OpenGroupV2RoomWithImageID
161
+ roomInfos : OpenGroupV2RoomWithImageID ,
162
+ blinded : boolean
159
163
) : Promise < Uint8Array | null > => {
160
164
if ( ! roomInfos || ! roomInfos . imageID ) {
161
165
return null ;
@@ -164,11 +168,10 @@ const sogsV3FetchPreview = async (
164
168
// not a batch call yet as we need to exclude headers for this call for now
165
169
const fetched = await fetchBinaryFromSogsWithOnionV4 ( {
166
170
abortSignal : new AbortController ( ) . signal ,
167
- blinded : false ,
171
+ blinded,
168
172
headers : null ,
169
173
serverPubkey : roomInfos . serverPublicKey ,
170
174
serverUrl : roomInfos . serverUrl ,
171
- doNotIncludeOurSogsHeaders : true ,
172
175
roomId : roomInfos . roomId ,
173
176
fileId : roomInfos . imageID ,
174
177
throwError : false ,
@@ -198,7 +201,6 @@ export const sogsV3FetchFileByFileID = async (
198
201
headers : null ,
199
202
serverPubkey : roomInfos . serverPublicKey ,
200
203
serverUrl : roomInfos . serverUrl ,
201
- doNotIncludeOurSogsHeaders : true ,
202
204
roomId : roomInfos . roomId ,
203
205
fileId,
204
206
throwError : true ,
0 commit comments