import AbortController from 'abort-controller'; import { batchFirstSubIsSuccess, batchGlobalIsSuccess, OpenGroupBatchRow, sogsBatchSend, } from './sogsV3BatchPoll'; import { OpenGroupRequestCommonType } from '../../../../data/types'; import { DURATION } from '../../../constants'; /** * Deletes messages on open group server using onion v4 logic and batch send */ export const deleteSogsMessageByServerIds = async ( idsToRemove: Array, roomInfos: OpenGroupRequestCommonType ): Promise => { const options: Array = idsToRemove.map(idToRemove => ({ type: 'deleteMessage', deleteMessage: { roomId: roomInfos.roomId, messageId: idToRemove }, })); const result = await sogsBatchSend( roomInfos.serverUrl, new Set([roomInfos.roomId]), new AbortController().signal, options, 'batch', 10 * DURATION.SECONDS ); try { return batchGlobalIsSuccess(result) && batchFirstSubIsSuccess(result); } catch (e) { window?.log?.error("deleteMessageByServerIds Can't decode JSON body"); } return false; };