Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3550938
D10490.id35099.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
6 KB
Referenced Files
None
Subscribers
None
D10490.id35099.diff
View Options
diff --git a/lib/actions/user-actions.js b/lib/actions/user-actions.js
--- a/lib/actions/user-actions.js
+++ b/lib/actions/user-actions.js
@@ -15,6 +15,8 @@
ClaimUsernameResponse,
LogInResponse,
LogInRequest,
+ OlmAuthInfo,
+ OlmAuthRequest,
} from '../types/account-types.js';
import type {
UpdateUserAvatarRequest,
@@ -274,6 +276,118 @@
return identityRegister;
}
+const olmAuthActionTypes = Object.freeze({
+ started: 'OLM_AUTH_STARTED',
+ success: 'OLM_AUTH_SUCCESS',
+ failed: 'OLM_AUTH_FAILED',
+});
+const olmAuthCallServerEndpointOptions = { timeout: 60000 };
+const olmAuth =
+ (
+ callKeyserverEndpoint: CallKeyserverEndpoint,
+ ): ((input: OlmAuthInfo) => Promise<LogInResult>) =>
+ async olmAuthInfo => {
+ const watchedIDs = threadWatcher.getWatchedIDs();
+
+ const {
+ logInActionSource,
+ calendarQuery,
+ keyserverData,
+ ...restLogInInfo
+ } = olmAuthInfo;
+
+ const keyserverIDs = Object.keys(keyserverData);
+
+ const watchedIDsPerKeyserver = sortThreadIDsPerKeyserver(watchedIDs);
+ const calendarQueryPerKeyserver = sortCalendarQueryPerKeyserver(
+ calendarQuery,
+ keyserverIDs,
+ );
+
+ const requests: { [string]: OlmAuthRequest } = {};
+ for (const keyserverID of keyserverIDs) {
+ requests[keyserverID] = {
+ ...restLogInInfo,
+ deviceTokenUpdateRequest:
+ olmAuthInfo.deviceTokenUpdateRequest[keyserverID],
+ watchedIDs: watchedIDsPerKeyserver[keyserverID] ?? [],
+ calendarQuery: calendarQueryPerKeyserver[keyserverID],
+ platformDetails: getConfig().platformDetails,
+ initialContentEncryptedMessage:
+ keyserverData[keyserverID].initialContentEncryptedMessage,
+ initialNotificationsEncryptedMessage:
+ keyserverData[keyserverID].initialNotificationsEncryptedMessage,
+ };
+ }
+
+ const responses: { +[string]: LogInResponse } = await callKeyserverEndpoint(
+ 'olm_auth',
+ requests,
+ olmAuthCallServerEndpointOptions,
+ );
+
+ const userInfosArrays = [];
+
+ let threadInfos: RawThreadInfos = {};
+ const calendarResult: WritableCalendarResult = {
+ calendarQuery: olmAuthInfo.calendarQuery,
+ rawEntryInfos: [],
+ };
+ const messagesResult: WritableGenericMessagesResult = {
+ messageInfos: [],
+ truncationStatus: {},
+ watchedIDsAtRequestTime: watchedIDs,
+ currentAsOf: {},
+ };
+ let updatesCurrentAsOf: { +[string]: number } = {};
+ for (const keyserverID in responses) {
+ threadInfos = {
+ ...responses[keyserverID].cookieChange.threadInfos,
+ ...threadInfos,
+ };
+ if (responses[keyserverID].rawEntryInfos) {
+ calendarResult.rawEntryInfos = calendarResult.rawEntryInfos.concat(
+ responses[keyserverID].rawEntryInfos,
+ );
+ }
+ messagesResult.messageInfos = messagesResult.messageInfos.concat(
+ responses[keyserverID].rawMessageInfos,
+ );
+ messagesResult.truncationStatus = {
+ ...messagesResult.truncationStatus,
+ ...responses[keyserverID].truncationStatuses,
+ };
+ messagesResult.currentAsOf = {
+ ...messagesResult.currentAsOf,
+ [keyserverID]: responses[keyserverID].serverTime,
+ };
+ updatesCurrentAsOf = {
+ ...updatesCurrentAsOf,
+ [keyserverID]: responses[keyserverID].serverTime,
+ };
+ userInfosArrays.push(responses[keyserverID].userInfos);
+ userInfosArrays.push(responses[keyserverID].cookieChange.userInfos);
+ }
+
+ const userInfos = mergeUserInfos(...userInfosArrays);
+
+ return {
+ threadInfos,
+ currentUserInfo: responses[ashoatKeyserverID].currentUserInfo,
+ calendarResult,
+ messagesResult,
+ userInfos,
+ updatesCurrentAsOf,
+ logInActionSource: olmAuthInfo.logInActionSource,
+ notAcknowledgedPolicies:
+ responses[ashoatKeyserverID].notAcknowledgedPolicies,
+ };
+ };
+
+function useOlmAuth(): (input: OlmAuthInfo) => Promise<LogInResult> {
+ return useKeyserverCall(olmAuth);
+}
+
function mergeUserInfos(
...userInfoArrays: Array<$ReadOnlyArray<UserInfo>>
): UserInfo[] {
@@ -617,4 +731,6 @@
useDeleteIdentityAccount,
identityRegisterActionTypes,
useIdentityRegister,
+ olmAuthActionTypes,
+ useOlmAuth,
};
diff --git a/lib/types/account-types.js b/lib/types/account-types.js
--- a/lib/types/account-types.js
+++ b/lib/types/account-types.js
@@ -96,6 +96,8 @@
logInFromNativeSIWE: 'LOG_IN_FROM_NATIVE_SIWE',
corruptedDatabaseDeletion: 'CORRUPTED_DATABASE_DELETION',
refetchUserDataAfterAcknowledgment: 'REFETCH_USER_DATA_AFTER_ACKNOWLEDGMENT',
+ logInFromNativeOlm: 'LOG_IN_FROM_NATIVE_OLM',
+ logInFromWebOlm: 'LOG_IN_FROM_WEB_OLM',
});
export type LogInActionSource = $Values<typeof logInActionSources>;
@@ -159,6 +161,39 @@
+notAcknowledgedPolicies?: $ReadOnlyArray<PolicyType>,
};
+export type UserIdentifier = {
+ +userID: string,
+ +username: string,
+ +walletAddress?: string,
+};
+
+type KeyserverRequestData = {
+ initialContentEncryptedMessage: string,
+ initialNotificationsEncryptedMessage: string,
+};
+
+export type OlmAuthInfo = {
+ +identifier: UserIdentifier,
+ +deviceID: string,
+ +doNotRegister: boolean,
+ +calendarQuery: CalendarQuery,
+ +deviceTokenUpdateRequest: DeviceTokenUpdateInput,
+ +logInActionSource: LogInActionSource,
+ +keyserverData: { +[keyserverID: string]: KeyserverRequestData },
+};
+
+export type OlmAuthRequest = {
+ +identifier: UserIdentifier,
+ +deviceID: string,
+ +doNotRegister: boolean,
+ +calendarQuery: CalendarQuery,
+ +deviceTokenUpdateRequest?: ?DeviceTokenUpdateRequest,
+ +initialContentEncryptedMessage: string,
+ +initialNotificationsEncryptedMessage: string,
+ +watchedIDs: $ReadOnlyArray<string>,
+ +platformDetails: PlatformDetails,
+};
+
export type UpdatePasswordRequest = {
code: string,
password: string,
diff --git a/lib/types/endpoints.js b/lib/types/endpoints.js
--- a/lib/types/endpoints.js
+++ b/lib/types/endpoints.js
@@ -25,6 +25,7 @@
LOG_IN: 'log_in',
UPDATE_PASSWORD: 'update_password',
POLICY_ACKNOWLEDGMENT: 'policy_acknowledgment',
+ OLM_AUTH: 'olm_auth',
});
type SessionChangingEndpoint = $Values<typeof sessionChangingEndpoints>;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 27, 7:05 PM (5 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2718121
Default Alt Text
D10490.id35099.diff (6 KB)
Attached To
Mode
D10490: [lib] add olm auth action
Attached
Detach File
Event Timeline
Log In to Comment