Skip to content

Commit b99f4cf

Browse files
committed
user selectors [nfc]: Refactor 'getUserIsActive' to accept user ID.
We are migrating the codebase from emails to user IDs to identify users, because user IDs are more reliable.
1 parent 21730fd commit b99f4cf

File tree

3 files changed

+7
-15
lines changed

3 files changed

+7
-15
lines changed

src/account-info/AccountDetailsScreen.js

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,5 @@ class AccountDetailsScreen extends PureComponent<Props> {
8989

9090
export default connect<SelectorProps, _, _>((state, props) => ({
9191
user: getAllUsersById(state).get(props.navigation.state.params.userId),
92-
isActive: (() => {
93-
const user = getAllUsersById(state).get(props.navigation.state.params.userId);
94-
if (!user) {
95-
return false;
96-
}
97-
return getUserIsActive(state, user.email);
98-
})(),
92+
isActive: getUserIsActive(state, props.navigation.state.params.userId),
9993
}))(AccountDetailsScreen);

src/users/__tests__/userSelectors-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ describe('getUserIsActive', () => {
137137
});
138138

139139
test('returns false for a user that has been deactivated', () => {
140-
expect(getUserIsActive(state, state.realm.nonActiveUsers[0].email)).toBeFalse();
140+
expect(getUserIsActive(state, state.realm.nonActiveUsers[0].user_id)).toBeFalse();
141141
});
142142

143143
test('returns true for a user that has not been deactivated', () => {
144-
expect(getUserIsActive(state, state.users[0].email)).toBeTrue();
144+
expect(getUserIsActive(state, state.users[0].user_id)).toBeTrue();
145145
});
146146

147147
test('returns true for a cross realm bot', () => {
148-
expect(getUserIsActive(state, state.realm.crossRealmBots[0].email)).toBeTrue();
148+
expect(getUserIsActive(state, state.realm.crossRealmBots[0].user_id)).toBeTrue();
149149
});
150150
});

src/users/userSelectors.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,7 @@ export const getAccountDetailsUserForEmail: Selector<UserOrBot, string> = create
201201
*/
202202
// To understand this implementation, see the comment about `is_active` in
203203
// the `User` type definition.
204-
export const getUserIsActive = (state: GlobalState, email: string): boolean => {
205-
if (!email) {
206-
return false;
207-
}
208-
return getActiveUsersByEmail(state).has(email);
204+
export const getUserIsActive = (state: GlobalState, userId: number): boolean => {
205+
const activeUserIds = [...getUsers(state), ...getCrossRealmBots(state)].map(user => user.user_id);
206+
return activeUserIds.includes(userId);
209207
};

0 commit comments

Comments
 (0)