MCPcopy Create free account
hub / github.com/CommE2E/comm / checkState

Function checkState

keyserver/src/socket/session-utils.js:297–469  ·  view source on GitHub ↗
(
  viewer: Viewer,
  status: StateCheckStatus,
)

Source from the content-addressed store, hash-verified

295 checkStateRequest?: ServerCheckStateServerRequest,
296};
297async function checkState(
298 viewer: Viewer,
299 status: StateCheckStatus,
300): Promise<StateCheckResult> {
301 if (status.status === 'state_validated') {
302 return { sessionUpdate: { lastValidated: Date.now() } };
303 } else if (status.status === 'state_check') {
304 const promises = Object.fromEntries(
305 values(serverStateSyncSpecs).map(spec => [
306 spec.hashKey,
307 (async () => {
308 if (
309 !hasMinCodeVersion(viewer.platformDetails, {
310 native: 267,
311 web: 32,
312 })
313 ) {
314 const data = await spec.fetch(viewer);
315 return hash(data);
316 }
317 const infosHash = await spec.fetchServerInfosHash(viewer);
318 return infosHash;
319 })(),
320 ]),
321 );
322 const hashesToCheck = await promiseAll(promises);
323 const checkStateRequest = {
324 type: serverRequestTypes.CHECK_STATE,
325 hashesToCheck,
326 };
327 return { checkStateRequest };
328 }
329
330 const invalidKeys = new Set(status.invalidKeys);
331
332 const shouldFetchAll = Object.fromEntries(
333 values(serverStateSyncSpecs).map(spec => [
334 spec.hashKey,
335 invalidKeys.has(spec.hashKey),
336 ]),
337 );
338 const idsToFetch = Object.fromEntries(
339 values(serverStateSyncSpecs)
340 .filter(spec => spec.innerHashSpec?.hashKey)
341 .map(spec => [spec.innerHashSpec?.hashKey, new Set<string>()]),
342 );
343 for (const key of invalidKeys) {
344 const [innerHashKey, id] = key.split('|');
345 if (innerHashKey && id) {
346 idsToFetch[innerHashKey]?.add(id);
347 }
348 }
349
350 const fetchPromises: { [string]: Promise<mixed> } = {};
351 for (const spec of values(serverStateSyncSpecs)) {
352 if (shouldFetchAll[spec.hashKey]) {
353 fetchPromises[spec.hashKey] = spec.fetch(viewer);
354 } else if (idsToFetch[spec.innerHashSpec?.hashKey]?.size > 0) {

Callers 2

SocketClass · 0.90

Calls 8

valuesFunction · 0.90
hasMinCodeVersionFunction · 0.90
hashFunction · 0.90
promiseAllFunction · 0.90
pushMethod · 0.80
hasMethod · 0.65
addMethod · 0.65
keysMethod · 0.65

Tested by

no test coverage detected