From 30c4f7fffca09b9d970e3449852d77fb35c46682 Mon Sep 17 00:00:00 2001 From: Greg Price Date: Mon, 8 Jul 2019 17:51:38 -0700 Subject: [PATCH] hidden email: Record our own `email` as returned by `/register`. With the "hidden emails" feature (aka `email_address_visibility`) that's now in beta on the server, the user's "email" as used as an identifier for them in the Zulip API can be an opaque one made up by the server -- different from `auth.email` aka `delivery_email`. So we need to switch our concept of "own email" to use the identifier-email; this is #3196. The server tells us this user's identifier-email in the `/register` response, so one necessary step is to remember it. Do that. In principle we should then update this value on EVENT_USER_UPDATE. But (a) the same is true of several other values here, and more importantly (b) we already don't handle EVENT_USER_UPDATE at all, either in our `users` state-subtree or in the various denormalized spots where we store other users' emails, avatars, etc. So punt. Changing emails is pretty uncommon; and in the particular case where it's happening for all an org's users en masse because hidden-emails was turned on or off, the only near-term-feasible solution will probably be to have the server just invalidate clients' event queues. --- src/boot/store.js | 3 +++ src/realm/realmReducer.js | 4 ++++ src/reduxTypes.js | 2 ++ 3 files changed, 9 insertions(+) diff --git a/src/boot/store.js b/src/boot/store.js index 8800197bd42..da8295df30a 100644 --- a/src/boot/store.js +++ b/src/boot/store.js @@ -104,6 +104,9 @@ const migrations: { [string]: (GlobalState) => GlobalState } = { ackedPushToken: a.ackedPushToken !== undefined ? a.ackedPushToken : null, })), }), + + // $FlowMigrationFudge + '7': dropCache, }; const reduxPersistConfig: Config = { diff --git a/src/realm/realmReducer.js b/src/realm/realmReducer.js index ae1cf61db11..006db46b41a 100644 --- a/src/realm/realmReducer.js +++ b/src/realm/realmReducer.js @@ -14,6 +14,7 @@ import { const initialState = { canCreateStreams: true, crossRealmBots: [], + email: undefined, twentyFourHourTime: false, emoji: {}, filters: [], @@ -41,6 +42,7 @@ export default (state: RealmState = initialState, action: Action): RealmState => ...state, canCreateStreams: action.data.can_create_streams, crossRealmBots: action.data.cross_realm_bots, + email: action.data.email, emoji: convertRealmEmoji(action.data.realm_emoji), filters: action.data.realm_filters, isAdmin: action.data.is_admin, @@ -49,6 +51,8 @@ export default (state: RealmState = initialState, action: Action): RealmState => }; } + // TODO on EVENT_USER_UPDATE for self: update email, isAdmin, etc. + case EVENT_REALM_FILTERS: return { ...state, diff --git a/src/reduxTypes.js b/src/reduxTypes.js index 0cdfcac61a3..c7d626f0cc1 100644 --- a/src/reduxTypes.js +++ b/src/reduxTypes.js @@ -213,6 +213,7 @@ export type PresenceState = {| * @prop emoji * * About the user: + * @prop email * @prop twentyFourHourTime * @prop canCreateStreams * @prop isAdmin @@ -224,6 +225,7 @@ export type RealmState = {| filters: RealmFilter[], emoji: RealmEmojiById, + email: string | void, twentyFourHourTime: boolean, canCreateStreams: boolean, isAdmin: boolean,