@ -12,19 +12,15 @@ import { Reactions } from '../../../../util/reactions';
import { OnionSending } from '../../../onions/onionSend' ;
import { OnionSending } from '../../../onions/onionSend' ;
import { ToastUtils , UserUtils } from '../../../utils' ;
import { ToastUtils , UserUtils } from '../../../utils' ;
import { OpenGroupPollingUtils } from '../opengroupV2/OpenGroupPollingUtils' ;
import { OpenGroupPollingUtils } from '../opengroupV2/OpenGroupPollingUtils' ;
import { getOpenGroupV2ConversationId } from '../utils/OpenGroupUtils' ;
import { getUsBlindedInThatServer } from './knownBlindedkeys' ;
import { getUsBlindedInThatServer } from './knownBlindedkeys' ;
import { batchGlobalIsSuccess , parseBatchGlobalStatusCode } from './sogsV3BatchPoll' ;
import { batchGlobalIsSuccess , parseBatchGlobalStatusCode } from './sogsV3BatchPoll' ;
import {
addToMutationCache ,
ChangeType ,
SogsV3Mutation ,
updateMutationCache ,
} from './sogsV3MutationCache' ;
export const hasReactionSupport = async (
export const hasReactionSupport = async (
conversationId : string ,
serverId : number
serverId : number
) : Promise < { supported : boolean ; conversation : ConversationModel | null } > = > {
) : Promise < { supported : boolean ; conversation : ConversationModel | null } > = > {
const found = await Data . getMessageByServerId ( serverId) ;
const found = await Data . getMessageByServerId ( conversationId , serverId ) ;
if ( ! found ) {
if ( ! found ) {
window . log . warn ( ` Open Group Message ${ serverId } not found in db ` ) ;
window . log . warn ( ` Open Group Message ${ serverId } not found in db ` ) ;
return { supported : false , conversation : null } ;
return { supported : false , conversation : null } ;
@ -57,7 +53,10 @@ export const sendSogsReactionOnionV4 = async (
throw new Error ( ` Could not find sogs pubkey of url: ${ serverUrl } ` ) ;
throw new Error ( ` Could not find sogs pubkey of url: ${ serverUrl } ` ) ;
}
}
const { supported , conversation } = await hasReactionSupport ( reaction . id ) ;
const { supported , conversation } = await hasReactionSupport (
getOpenGroupV2ConversationId ( serverUrl , room ) ,
reaction . id
) ;
if ( ! supported ) {
if ( ! supported ) {
return false ;
return false ;
}
}
@ -82,27 +81,13 @@ export const sendSogsReactionOnionV4 = async (
const method = reaction . action === Action . REACT ? 'PUT' : 'DELETE' ;
const method = reaction . action === Action . REACT ? 'PUT' : 'DELETE' ;
const serverPubkey = allValidRoomInfos [ 0 ] . serverPublicKey ;
const serverPubkey = allValidRoomInfos [ 0 ] . serverPublicKey ;
const cacheEntry : SogsV3Mutation = {
server : serverUrl ,
room : room ,
changeType : ChangeType.REACTIONS ,
seqno : null ,
metadata : {
messageId : reaction.id ,
emoji ,
action : reaction.action === Action . REACT ? 'ADD' : 'REMOVE' ,
} ,
} ;
addToMutationCache ( cacheEntry ) ;
// Since responses can take a long time we immediately update the sender's UI and if there is a problem it is overwritten by handleOpenGroupMessageReactions later.
// Since responses can take a long time we immediately update the sender's UI and if there is a problem it is overwritten by handleOpenGroupMessageReactions later.
const me = UserUtils . getOurPubKeyStrFromCache ( ) ;
const me = UserUtils . getOurPubKeyStrFromCache ( ) ;
await Reactions . handleMessageReaction ( {
await Reactions . handleMessageReaction ( {
reaction ,
reaction ,
sender : blinded ? getUsBlindedInThatServer ( conversation ) || me : me ,
sender : blinded ? getUsBlindedInThatServer ( conversation ) || me : me ,
you : true ,
you : true ,
isOpenGroup: true ,
openGroupConversationId : getOpenGroupV2ConversationId ( serverUrl , room ) ,
} ) ;
} ) ;
// reaction endpoint requires an empty dict {}
// reaction endpoint requires an empty dict {}
@ -137,9 +122,5 @@ export const sendSogsReactionOnionV4 = async (
const success = Boolean ( reaction . action === Action . REACT ? rawMessage.added : rawMessage.removed ) ;
const success = Boolean ( reaction . action === Action . REACT ? rawMessage.added : rawMessage.removed ) ;
if ( success ) {
updateMutationCache ( cacheEntry , rawMessage . seqno ) ;
}
return success ;
return success ;
} ;
} ;