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

Function processClientResponses

keyserver/src/socket/session-utils.js:59–194  ·  view source on GitHub ↗
(
  viewer: Viewer,
  clientResponses: $ReadOnlyArray<ClientResponse>,
)

Source from the content-addressed store, hash-verified

57 activityUpdateResult: ?UpdateActivityResult,
58};
59async function processClientResponses(
60 viewer: Viewer,
61 clientResponses: $ReadOnlyArray<ClientResponse>,
62): Promise<ProcessClientResponsesResult> {
63 let viewerMissingPlatform = !viewer.platform;
64 const { platformDetails } = viewer;
65 let viewerMissingPlatformDetails =
66 !platformDetails ||
67 (isDeviceType(viewer.platform) &&
68 (platformDetails.codeVersion === null ||
69 platformDetails.codeVersion === undefined ||
70 platformDetails.stateVersion === null ||
71 platformDetails.stateVersion === undefined));
72
73 const promises = [];
74 let activityUpdates: Array<ActivityUpdate> = [];
75 let stateCheckStatus = null;
76 const clientSentPlatformDetails = clientResponses.some(
77 response => response.type === serverRequestTypes.PLATFORM_DETAILS,
78 );
79 for (const clientResponse of clientResponses) {
80 if (
81 clientResponse.type === serverRequestTypes.PLATFORM &&
82 !clientSentPlatformDetails
83 ) {
84 promises.push(setCookiePlatform(viewer, clientResponse.platform));
85 viewerMissingPlatform = false;
86 if (!isDeviceType(clientResponse.platform)) {
87 viewerMissingPlatformDetails = false;
88 }
89 } else if (
90 clientResponse.type === serverRequestTypes.THREAD_INCONSISTENCY
91 ) {
92 promises.push(recordThreadInconsistency(viewer, clientResponse));
93 } else if (clientResponse.type === serverRequestTypes.ENTRY_INCONSISTENCY) {
94 promises.push(recordEntryInconsistency(viewer, clientResponse));
95 } else if (clientResponse.type === serverRequestTypes.PLATFORM_DETAILS) {
96 promises.push(
97 setCookiePlatformDetails(viewer, clientResponse.platformDetails),
98 );
99 viewerMissingPlatform = false;
100 viewerMissingPlatformDetails = false;
101 } else if (
102 clientResponse.type === serverRequestTypes.INITIAL_ACTIVITY_UPDATES
103 ) {
104 activityUpdates = [...activityUpdates, ...clientResponse.activityUpdates];
105 } else if (clientResponse.type === serverRequestTypes.CHECK_STATE) {
106 const invalidKeys = [];
107 for (const key in clientResponse.hashResults) {
108 const result = clientResponse.hashResults[key];
109 if (!result) {
110 invalidKeys.push(key);
111 }
112 }
113 stateCheckStatus =
114 invalidKeys.length > 0
115 ? { status: 'state_invalid', invalidKeys }
116 : { status: 'state_validated' };

Calls 13

isDeviceTypeFunction · 0.90
setCookiePlatformFunction · 0.90
setCookiePlatformDetailsFunction · 0.90
getOlmUtilityFunction · 0.90
ignorePromiseRejectionsFunction · 0.90
activityUpdaterFunction · 0.90
promiseAllFunction · 0.90
recordEntryInconsistencyFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected