@ -1,4 +1,4 @@
import { isArray , omit , sortBy } from 'lodash' ;
import { isArray , omit } from 'lodash' ;
import { Snode } from '../../../data/data' ;
import { Snode } from '../../../data/data' ;
import { updateIsOnline } from '../../../state/ducks/onion' ;
import { updateIsOnline } from '../../../state/ducks/onion' ;
import { doSnodeBatchRequest } from './batchRequest' ;
import { doSnodeBatchRequest } from './batchRequest' ;
@ -124,7 +124,7 @@ async function retrieveNextMessages(
) ;
) ;
// let exceptions bubble up
// let exceptions bubble up
// no retry for this one as this a call we do every few seconds while polling for messages
// no retry for this one as this a call we do every few seconds while polling for messages
const timeOutMs = 10 * 1000 ; // yes this is a long timeout for just messages, but 4s timeout way to often...
const timeOutMs = 10 * 1000 ; // yes this is a long timeout for just messages, but 4s timeout s way to often...
const timeoutPromise = async ( ) = > sleepFor ( timeOutMs ) ;
const timeoutPromise = async ( ) = > sleepFor ( timeOutMs ) ;
const fetchPromise = async ( ) = >
const fetchPromise = async ( ) = >
doSnodeBatchRequest ( retrieveRequestsParams , targetNode , timeOutMs , associatedWith ) ;
doSnodeBatchRequest ( retrieveRequestsParams , targetNode , timeOutMs , associatedWith ) ;
@ -166,19 +166,13 @@ async function retrieveNextMessages(
GetNetworkTime . handleTimestampOffsetFromNetwork ( 'retrieve' , bodyFirstResult . t ) ;
GetNetworkTime . handleTimestampOffsetFromNetwork ( 'retrieve' , bodyFirstResult . t ) ;
// merge results with their corresponding namespaces
// NOTE: We don't want to sort messages here because the ordering depends on the snode and when it received each messages.
return results . map ( ( result , index ) = > {
// The last_hash for that snode has to be the last one we've received from that same snode, othwerwise we end up fetching the same messages over and over again.
const messages = result . body as RetrieveMessagesResultsContent ;
return results . map ( ( result , index ) = > ( {
// Not sure if that makes sense, but we probably want those messages sorted.
code : result.code ,
const sortedMessages = sortBy ( messages . messages , m = > m . timestamp ) ;
messages : result.body as RetrieveMessagesResultsContent ,
messages . messages = sortedMessages ;
namespace : namespaces [ index ] ,
} ) ) ;
return {
code : result.code ,
messages ,
namespace : namespaces [ index ] ,
} ;
} ) ;
} catch ( e ) {
} catch ( e ) {
window ? . log ? . warn ( 'exception while parsing json of nextMessage:' , e ) ;
window ? . log ? . warn ( 'exception while parsing json of nextMessage:' , e ) ;
if ( ! window . inboxStore ? . getState ( ) . onionPaths . isOnline ) {
if ( ! window . inboxStore ? . getState ( ) . onionPaths . isOnline ) {