diff --git a/lib/shared/notifications-session-creator-context.js b/lib/shared/notifications-session-creator-context.js new file mode 100644 --- /dev/null +++ b/lib/shared/notifications-session-creator-context.js @@ -0,0 +1,20 @@ +// @flow + +import * as React from 'react'; + +import type { OLMIdentityKeys } from '../types/crypto-types.js'; +import type { OlmSessionInitializationInfo } from '../types/request-types.js'; + +export type NotificationsSessionCreatorContextType = { + +notificationsSessionCreator: ( + cookie: ?string, + notificationsIdentityKeys: OLMIdentityKeys, + notificationsInitializationInfo: OlmSessionInitializationInfo, + keyserverID: string, + ) => Promise, +}; + +const NotificationsSessionCreatorContext: React.Context = + React.createContext(null); + +export { NotificationsSessionCreatorContext }; diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js --- a/lib/types/crypto-types.js +++ b/lib/types/crypto-types.js @@ -2,7 +2,6 @@ import t, { type TInterface } from 'tcomb'; -import type { OlmSessionInitializationInfo } from '../types/request-types.js'; import { tShape } from '../utils/validation-utils.js'; export type OLMIdentityKeys = { @@ -37,15 +36,6 @@ +getInitializedCryptoStore: () => Promise, }; -export type NotificationsSessionCreatorContextType = { - +notificationsSessionCreator: ( - cookie: ?string, - notificationsIdentityKeys: OLMIdentityKeys, - notificationsInitializationInfo: OlmSessionInitializationInfo, - keyserverID: string, - ) => Promise, -}; - export type NotificationsOlmDataType = { +mainSession: string, +picklingKey: string, diff --git a/native/account/account-hooks.js b/native/account/account-hooks.js new file mode 100644 --- /dev/null +++ b/native/account/account-hooks.js @@ -0,0 +1,41 @@ +// @flow + +import * as React from 'react'; + +import { NotificationsSessionCreatorContext } from 'lib/shared/notifications-session-creator-context.js'; +import type { OLMIdentityKeys } from 'lib/types/crypto-types.js'; +import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; + +import { nativeNotificationsSessionCreator } from '../utils/crypto-utils.js'; + +type Props = { + +children: React.Node, +}; + +function notificationsSessionCreator( + cookie: ?string, + notificationsIdentityKeys: OLMIdentityKeys, + notificationsInitializationInfo: OlmSessionInitializationInfo, + keyserverID: string, +) { + return nativeNotificationsSessionCreator( + notificationsIdentityKeys, + notificationsInitializationInfo, + keyserverID, + ); +} + +const contextValue = { + notificationsSessionCreator, +}; + +function NotificationsSessionCreatorProvider(props: Props): React.Node { + const { children } = props; + return ( + + {children} + + ); +} + +export { NotificationsSessionCreatorProvider }; diff --git a/native/root.react.js b/native/root.react.js --- a/native/root.react.js +++ b/native/root.react.js @@ -33,6 +33,7 @@ import { TunnelbrokerProvider } from 'lib/tunnelbroker/tunnelbroker-context.js'; import { actionLogger } from 'lib/utils/action-logger.js'; +import { NotificationsSessionCreatorProvider } from './account/account-hooks.js'; import { RegistrationContextProvider } from './account/registration/registration-context-provider.react.js'; import NativeEditThreadAvatarProvider from './avatars/native-edit-thread-avatar-provider.react.js'; import BackupHandler from './backup/backup-handler.js'; @@ -300,60 +301,64 @@ - - - - - - - - - - - - - - - - - - - - {gated} - - - - - - {navigation} - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + {gated} + + + + + + {navigation} + + + + + + + + + + + + + + + + + diff --git a/web/account/account-hooks.js b/web/account/account-hooks.js --- a/web/account/account-hooks.js +++ b/web/account/account-hooks.js @@ -11,13 +11,13 @@ getOneTimeKeyValuesFromBlob, getPrekeyValueFromBlob, } from 'lib/shared/crypto-utils.js'; +import { NotificationsSessionCreatorContext } from 'lib/shared/notifications-session-creator-context.js'; import type { SignedIdentityKeysBlob, CryptoStore, IdentityKeysBlob, CryptoStoreContextType, OLMIdentityKeys, - NotificationsSessionCreatorContextType, NotificationsOlmDataType, } from 'lib/types/crypto-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; @@ -40,9 +40,6 @@ const CryptoStoreContext: React.Context = React.createContext(null); -const WebNotificationsSessionCreatorContext: React.Context = - React.createContext(null); - type Props = { +children: React.Node, }; @@ -177,7 +174,7 @@ }, [getOrCreateCryptoStore]); } -function WebNotificationsSessionCreatorProvider(props: Props): React.Node { +function NotificationsSessionCreatorProvider(props: Props): React.Node { const getOrCreateCryptoStore = useGetOrCreateCryptoStore(); const currentCryptoStore = useSelector(state => state.cryptoStore); @@ -310,9 +307,9 @@ ); return ( - + {props.children} - + ); } @@ -322,7 +319,7 @@ notificationsInitializationInfo: OlmSessionInitializationInfo, keyserverID: string, ) => Promise { - const context = React.useContext(WebNotificationsSessionCreatorContext); + const context = React.useContext(NotificationsSessionCreatorContext); invariant(context, 'WebNotificationsSessionCreator not found.'); return context.notificationsSessionCreator; @@ -331,7 +328,7 @@ export { useGetSignedIdentityKeysBlob, useGetOrCreateCryptoStore, - WebNotificationsSessionCreatorProvider, + NotificationsSessionCreatorProvider, useWebNotificationsSessionCreator, GetOrCreateCryptoStoreProvider, }; diff --git a/web/root.js b/web/root.js --- a/web/root.js +++ b/web/root.js @@ -16,7 +16,7 @@ import { GetOrCreateCryptoStoreProvider, - WebNotificationsSessionCreatorProvider, + NotificationsSessionCreatorProvider, } from './account/account-hooks.js'; import App from './app.react.js'; import { SQLiteDataHandler } from './database/sqlite-data-handler.js'; @@ -47,14 +47,14 @@ - + - +