From 26e22191e8d61e4c7511956824c1ee01548378e6 Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 29 Apr 2021 11:37:33 +1000 Subject: [PATCH] add a way to fetch roomDetails and preview but providing the serverPubkey as the room might not be saved yet on the db, we have to provided the pubkey to the request --- ts/opengroup/opengroupV2/ApiUtil.ts | 1 + ts/opengroup/opengroupV2/OpenGroupAPIV2.ts | 42 ++++++++++++++++------ 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/ts/opengroup/opengroupV2/ApiUtil.ts b/ts/opengroup/opengroupV2/ApiUtil.ts index 2381ee349..8ee4ec045 100644 --- a/ts/opengroup/opengroupV2/ApiUtil.ts +++ b/ts/opengroup/opengroupV2/ApiUtil.ts @@ -26,6 +26,7 @@ export type OpenGroupV2Request = { queryParams?: Record; headers?: Record; isAuthRequired: boolean; + serverPublicKey?: string; // if not provided, a db called will be made to try to get it. }; export type OpenGroupV2CompactPollRequest = { diff --git a/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts b/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts index e688e0533..d82eac42c 100644 --- a/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts +++ b/ts/opengroup/opengroupV2/OpenGroupAPIV2.ts @@ -1,5 +1,9 @@ import _ from 'lodash'; -import { getV2OpenGroupRoomByRoomId, saveV2OpenGroupRoom } from '../../data/opengroups'; +import { + getV2OpenGroupRoomByRoomId, + OpenGroupV2Room, + saveV2OpenGroupRoom, +} from '../../data/opengroups'; import { ConversationController } from '../../session/conversations'; import { sendViaOnion } from '../../session/onions/onionSend'; import { PubKey } from '../../session/types'; @@ -46,12 +50,18 @@ async function sendOpenGroupV2Request(request: OpenGroupV2Request): Promise { +export const getAllRoomInfos = async (roomInfos: OpenGroupV2Room) => { // room should not be required here const request: OpenGroupV2Request = { method: 'GET', @@ -426,6 +444,7 @@ export const getAllRoomInfos = async (roomInfos: OpenGroupRequestCommonType) => server: roomInfos.serverUrl, isAuthRequired: false, endpoint: 'rooms', + serverPublicKey: roomInfos.serverPublicKey, }; const result = await sendOpenGroupV2Request(request); const statusCode = parseStatusCodeFromOnionRequest(result); @@ -535,7 +554,7 @@ export const downloadFileOpenGroupV2ByUrl = async ( * It can be used directly, or saved on the attachments directory if needed, but this function does not handle it */ export const downloadPreviewOpenGroupV2 = async ( - roomInfos: OpenGroupRequestCommonType + roomInfos: OpenGroupV2Room ): Promise => { const request: OpenGroupV2Request = { method: 'GET', @@ -543,6 +562,7 @@ export const downloadPreviewOpenGroupV2 = async ( server: roomInfos.serverUrl, isAuthRequired: false, endpoint: `rooms/${roomInfos.roomId}/image`, + serverPublicKey: roomInfos.serverPublicKey, }; const result = await sendOpenGroupV2Request(request);