diff --git a/keyserver/src/session/cookies.js b/keyserver/src/session/cookies.js --- a/keyserver/src/session/cookies.js +++ b/keyserver/src/session/cookies.js @@ -823,6 +823,26 @@ ); } +async function isCookieMissingOlmNotificationsSession( + viewer: Viewer, +): Promise { + if ( + !viewer.platformDetails || + viewer.platformDetails.platform !== 'ios' || + !viewer.platformDetails.codeVersion || + viewer.platformDetails.codeVersion < 1000 + ) { + return false; + } + const query = SQL` + SELECT * + FROM olm_sessions + WHERE cookie_id = ${viewer.cookieID} AND is_content = FALSE; + `; + const [queryResult] = await dbQuery(query); + return queryResult.length === 0; +} + async function setCookiePlatform( viewer: Viewer, platform: Platform, @@ -874,4 +894,5 @@ isCookieMissingSignedIdentityKeysBlob, setCookiePlatform, setCookiePlatformDetails, + isCookieMissingOlmNotificationsSession, }; diff --git a/keyserver/src/socket/socket.js b/keyserver/src/socket/socket.js --- a/keyserver/src/socket/socket.js +++ b/keyserver/src/socket/socket.js @@ -80,6 +80,7 @@ extendCookieLifespan, createNewAnonymousCookie, isCookieMissingSignedIdentityKeysBlob, + isCookieMissingOlmNotificationsSession, } from '../session/cookies.js'; import { Viewer } from '../session/viewer.js'; import { commitSessionUpdate } from '../updaters/session-updaters.js'; @@ -479,6 +480,9 @@ const isCookieMissingSignedIdentityKeysBlobPromise = isCookieMissingSignedIdentityKeysBlob(viewer.cookieID); + const isCookieMissingOlmNotificationsSessionPromise = + isCookieMissingOlmNotificationsSession(viewer); + if (!sessionInitializationResult.sessionContinued) { const [threadsResult, entriesResult, currentUserInfo, knownUserInfos] = await Promise.all([ @@ -555,8 +559,11 @@ }); } - const signedIdentityKeysBlobMissing = - await isCookieMissingSignedIdentityKeysBlobPromise; + const [signedIdentityKeysBlobMissing, olmNotificationsSessionMissing] = + await Promise.all([ + isCookieMissingSignedIdentityKeysBlobPromise, + isCookieMissingOlmNotificationsSessionPromise, + ]); if (signedIdentityKeysBlobMissing) { serverRequests.push({ @@ -564,6 +571,12 @@ }); } + if (olmNotificationsSessionMissing) { + serverRequests.push({ + type: serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE, + }); + } + if (serverRequests.length > 0 || clientResponses.length > 0) { // We send this message first since the STATE_SYNC triggers the client's // connection status to shift to "connected", and we want to make sure the