@ -1,7 +1,7 @@
/* eslint-disable no-await-in-loop */
/* eslint-disable no-await-in-loop */
/* eslint-disable more/no-then */
/* eslint-disable more/no-then */
/* eslint-disable @typescript-eslint/no-misused-promises */
/* eslint-disable @typescript-eslint/no-misused-promises */
import { compact , concat , difference, flatten, last , sample , toNumber , uniqBy } from 'lodash' ;
import { compact , concat , flatten, last , sample , toNumber , uniqBy } from 'lodash' ;
import { Data , Snode } from '../../../data/data' ;
import { Data , Snode } from '../../../data/data' ;
import { SignalService } from '../../../protobuf' ;
import { SignalService } from '../../../protobuf' ;
import * as Receiver from '../../../receiver/receiver' ;
import * as Receiver from '../../../receiver/receiver' ;
@ -24,7 +24,6 @@ import { getConversationController } from '../../conversations';
import { IncomingMessage } from '../../messages/incoming/IncomingMessage' ;
import { IncomingMessage } from '../../messages/incoming/IncomingMessage' ;
import { ed25519Str } from '../../onions/onionPath' ;
import { ed25519Str } from '../../onions/onionPath' ;
import { StringUtils , UserUtils } from '../../utils' ;
import { StringUtils , UserUtils } from '../../utils' ;
import { perfEnd , perfStart } from '../../utils/Performance' ;
import { LibSessionUtil } from '../../utils/libsession/libsession_utils' ;
import { LibSessionUtil } from '../../utils/libsession/libsession_utils' ;
import { SnodeNamespace , SnodeNamespaces } from './namespaces' ;
import { SnodeNamespace , SnodeNamespaces } from './namespaces' ;
import { SnodeAPIRetrieve } from './retrieveRequest' ;
import { SnodeAPIRetrieve } from './retrieveRequest' ;
@ -228,21 +227,16 @@ export class SwarmPolling {
namespaces : Array < SnodeNamespaces >
namespaces : Array < SnodeNamespaces >
) {
) {
const polledPubkey = pubkey . key ;
const polledPubkey = pubkey . key ;
let resultsFromAllNamespaces : RetrieveMessagesResultsBatched | null ;
const swarmSnodes = await snodePool . getSwarmFor ( polledPubkey ) ;
const swarmSnodes = await snodePool . getSwarmFor ( polledPubkey ) ;
let toPollFrom : Snode | undefined ;
try {
toPollFrom = sample ( swarmSnodes ) ;
// Select nodes for which we already have lastHashes
const alreadyPolled = swarmSnodes . filter ( ( n : Snode ) = > this . lastHashes [ n . pubkey_ed25519 ] ) ;
let toPollFrom = alreadyPolled . length ? alreadyPolled [ 0 ] : null ;
// If we need more nodes, select randomly from the remaining nodes:
if ( ! toPollFrom ) {
if ( ! toPollFrom ) {
const notPolled = difference ( swarmSnodes , alreadyPolled ) ;
throw new Error ( ` pollOnceForKey: no snode in swarm for ${ ed25519Str ( polledPubkey ) } ` ) ;
toPollFrom = sample ( notPolled ) as Snode ;
}
}
let resultsFromAllNamespaces : RetrieveMessagesResultsBatched | null ;
try {
// Note: always print something so we know if the polling is hanging
// Note: always print something so we know if the polling is hanging
window . log . info (
window . log . info (
` about to pollNodeForKey of ${ ed25519Str ( pubkey . key ) } from snode: ${ ed25519Str ( toPollFrom . pubkey_ed25519 ) } namespaces: ${ namespaces } `
` about to pollNodeForKey of ${ ed25519Str ( pubkey . key ) } from snode: ${ ed25519Str ( toPollFrom . pubkey_ed25519 ) } namespaces: ${ namespaces } `
@ -337,9 +331,10 @@ export class SwarmPolling {
} ) ;
} ) ;
}
}
perfStart ( ` handleSeenMessages- ${ polledPubkey } ` ) ;
const newMessages = await this . handleSeenMessages ( messages ) ;
const newMessages = await this . handleSeenMessages ( messages ) ;
perfEnd ( ` handleSeenMessages- ${ polledPubkey } ` , 'handleSeenMessages' ) ;
window . log . info (
` handleSeenMessages: ${ newMessages . length } out of ${ messages . length } are not seen yet. snode: ${ toPollFrom ? ed25519Str ( toPollFrom . pubkey_ed25519 ) : 'undefined' } `
) ;
// don't handle incoming messages from group swarms when using the userconfig and the group is not one of the tracked group
// don't handle incoming messages from group swarms when using the userconfig and the group is not one of the tracked group
const isUserConfigReleaseLive = await ReleasedFeatures . checkIsUserConfigFeatureReleased ( ) ;
const isUserConfigReleaseLive = await ReleasedFeatures . checkIsUserConfigFeatureReleased ( ) ;