Skip to content

Commit

Permalink
hidden email: Start getting own-email from /register , not auth.
Browse files Browse the repository at this point in the history
In previous commits in recent days, we've fixed a number of
spots where we were getting the user's own email directly from
`auth.email` or equivalent, in favor of going through this
common `getOwnEmail` selector.  Now switch the selector to get
it from the proper source, where we've recorded the `email`
returned by `/register`.

Fixes #3196.  Modulo (a) any yet-unspotted bugs, of course, and
(b) handling the transition when the hidden-emails setting (aka
`email_address_visibility`) is turned on or off.  The latter is
expected to be a server-side change.
  • Loading branch information
gnprice committed Jul 17, 2019
1 parent bf030f1 commit c5b9370
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion src/__tests__/exampleData.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import deepFreeze from 'deep-freeze';
import { createStore } from 'redux';

import type { CrossRealmBot, Message, PmRecipientUser, Stream, User } from '../api/modelTypes';
import type { GlobalState } from '../reduxTypes';
import type { GlobalState, RealmState } from '../reduxTypes';
import type { Account } from '../types';
import rootReducer from '../boot/reducers';

Expand Down Expand Up @@ -189,6 +189,12 @@ const reduxState = (extra?: $Rest<GlobalState, {}>): GlobalState =>
...extra,
});

const realmState = (extra?: $Rest<RealmState, {}>): RealmState =>
deepFreeze({
...baseReduxState.realm,
...extra,
});

export const eg = {
makeUser,
makeCrossRealmBot,
Expand All @@ -203,4 +209,5 @@ export const eg = {

baseReduxState,
reduxState,
realmState,
};
8 changes: 7 additions & 1 deletion src/account/accountsSelectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,13 @@ export const getActiveAccount = (state: GlobalState): Account => {
};

/** The user's own email in the active account; throws if none. */
export const getOwnEmail = (state: GlobalState): string => getActiveAccount(state).email;
export const getOwnEmail = (state: GlobalState): string => {
const { email } = state.realm;
if (email === undefined) {
throw new Error('No server data found');
}
return email;
};

/** The realm of the active account; throws if none. */
export const getCurrentRealm = (state: GlobalState) => getActiveAccount(state).realm;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ALL_PRIVATE_NARROW_STR } from '../../utils/narrow';
describe('getRecentConversations', () => {
test('when no messages, return no conversations', () => {
const state = deepFreeze({
accounts: [{ email: 'me@example.com' }],
realm: { email: 'me@example.com' },
narrows: {
[ALL_PRIVATE_NARROW_STR]: [],
},
Expand All @@ -23,7 +23,7 @@ describe('getRecentConversations', () => {

test('returns unique list of recipients, includes conversations with self', () => {
const state = deepFreeze({
accounts: [{ email: 'me@example.com' }],
realm: { email: 'me@example.com' },
narrows: {
[ALL_PRIVATE_NARROW_STR]: [0, 1, 2, 3, 4],
},
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('getRecentConversations', () => {

test('returns recipients sorted by last activity', () => {
const state = deepFreeze({
accounts: [{ email: 'me@example.com' }],
realm: { email: 'me@example.com' },
narrows: {
[ALL_PRIVATE_NARROW_STR]: [1, 2, 3, 4, 5, 6],
},
Expand Down
5 changes: 4 additions & 1 deletion src/users/__tests__/userSelectors-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ describe('getUsersById', () => {

describe('getUsersSansMe', () => {
test('returns all users except current user', () => {
const state = eg.reduxState({ users: [eg.selfUser, eg.otherUser], accounts: [eg.selfAccount] });
const state = eg.reduxState({
users: [eg.selfUser, eg.otherUser],
realm: eg.realmState({ email: eg.selfUser.email }),
});
expect(getUsersSansMe(state)).toEqual([eg.otherUser]);
});
});

0 comments on commit c5b9370

Please sign in to comment.