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

Function checkState

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

Source from the content-addressed store, hash-verified

311 checkStateRequest?: ServerCheckStateServerRequest,
312};
313async function checkState(
314 viewer: Viewer,
315 status: StateCheckStatus,
316): Promise<StateCheckResult> {
317 if (status.status === 'state_validated') {
318 return { sessionUpdate: { lastValidated: Date.now() } };
319 } else if (status.status === 'state_check') {
320 const promises = Object.fromEntries(
321 values(serverStateSyncSpecs).map(spec => [
322 spec.hashKey,
323 (async () => {
324 if (
325 !hasMinCodeVersion(viewer.platformDetails, {
326 native: 267,
327 web: 32,
328 })
329 ) {
330 const data = await spec.fetch(viewer);
331 return hash(data);
332 }
333 const infosHash = await spec.fetchServerInfosHash(viewer);
334 return infosHash;
335 })(),
336 ]),
337 );
338 const hashesToCheck = await promiseAll(promises);
339 const checkStateRequest = {
340 type: serverRequestTypes.CHECK_STATE,
341 hashesToCheck,
342 };
343 return { checkStateRequest };
344 }
345
346 const invalidKeys = new Set(status.invalidKeys);
347
348 const shouldFetchAll = Object.fromEntries(
349 values(serverStateSyncSpecs).map(spec => [
350 spec.hashKey,
351 invalidKeys.has(spec.hashKey),
352 ]),
353 );
354 const idsToFetch = Object.fromEntries(
355 values(serverStateSyncSpecs)
356 .filter(spec => spec.innerHashSpec?.hashKey)
357 .map(spec => [spec.innerHashSpec?.hashKey, new Set<string>()]),
358 );
359 for (const key of invalidKeys) {
360 const [innerHashKey, id] = key.split('|');
361 if (innerHashKey && id) {
362 idsToFetch[innerHashKey]?.add(id);
363 }
364 }
365
366 const fetchPromises: { [string]: Promise<mixed> } = {};
367 for (const spec of values(serverStateSyncSpecs)) {
368 if (shouldFetchAll[spec.hashKey]) {
369 fetchPromises[spec.hashKey] = spec.fetch(viewer);
370 } 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