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

Function processClientResponses

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

Source from the content-addressed store, hash-verified

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

Calls 14

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

Tested by

no test coverage detected