Skip to content

Commit d4e934a

Browse files
committed
presence [nfc]: Unexport statusFromPresenceAndUserStatus
Next we'll fuse this into its caller getPresenceStatusForUserId, which will enable further simplification.
1 parent f3903bd commit d4e934a

File tree

2 files changed

+33
-15
lines changed

2 files changed

+33
-15
lines changed

src/presence/__tests__/presenceModel-test.js

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
reducer as presenceReducer,
1010
getAggregatedPresence,
1111
statusFromPresence,
12-
statusFromPresenceAndUserStatus,
1312
getUserLastActiveAsRelativeTimeString,
13+
getPresenceStatusForUserId,
1414
} from '../presenceModel';
1515
import { makePresenceState } from './presence-testlib';
1616
import type { UserPresence, UserStatus } from '../../api/modelTypes';
17+
import type { PerAccountState } from '../../reduxTypes';
1718

1819
const currentTimestamp = Date.now() / 1000;
1920

@@ -189,23 +190,40 @@ describe('statusFromPresence', () => {
189190
});
190191
});
191192

192-
describe('statusFromPresenceAndUserStatus', () => {
193+
describe('getPresenceStatusForUserId, server < FL 148', () => {
194+
function makeState(args: {
195+
userPresence: UserPresence,
196+
userStatus: UserStatus,
197+
zulipFeatureLevel?: number,
198+
}): PerAccountState {
199+
const { userPresence, userStatus, zulipFeatureLevel = eg.recentZulipFeatureLevel } = args;
200+
return eg.reduxStatePlus({
201+
presence: makePresenceState([[eg.otherUser, userPresence]]),
202+
userStatuses: Immutable.Map([[eg.otherUser.user_id, userStatus]]),
203+
accounts: [{ ...eg.plusReduxState.accounts[0], zulipFeatureLevel }],
204+
});
205+
}
206+
193207
test('if `userPresence` is provided but `away` is false do not change', () => {
194-
expect(
195-
statusFromPresenceAndUserStatus(
196-
{ aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 } },
197-
{ away: false, status_text: 'Hello, world!', status_emoji: null },
198-
),
199-
).toBe('active');
208+
const state = makeState({
209+
userPresence: {
210+
aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 },
211+
},
212+
userStatus: { away: false, status_text: 'Hello, world!', status_emoji: null },
213+
zulipFeatureLevel: 147,
214+
});
215+
expect(getPresenceStatusForUserId(state, eg.otherUser.user_id)).toBe('active');
200216
});
201217

202218
test('if `userPresence` is provided and `away` is `true` override status with "unavailable"', () => {
203-
expect(
204-
statusFromPresenceAndUserStatus(
205-
{ aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 } },
206-
{ away: true, status_text: null, status_emoji: null },
207-
),
208-
).toBe('unavailable');
219+
const state = makeState({
220+
userPresence: {
221+
aggregated: { client: 'website', status: 'active', timestamp: currentTimestamp - 100 },
222+
},
223+
userStatus: { away: true, status_text: null, status_emoji: null },
224+
zulipFeatureLevel: 147,
225+
});
226+
expect(getPresenceStatusForUserId(state, eg.otherUser.user_id)).toBe('unavailable');
209227
});
210228
});
211229

src/presence/presenceModel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const statusFromPresence = (presence: UserPresence | void): PresenceStatu
164164
};
165165

166166
// TODO(server-6.0): Remove; UserStatus['away'] was deprecated at FL 148.
167-
export const statusFromPresenceAndUserStatus = (
167+
const statusFromPresenceAndUserStatus = (
168168
presence: UserPresence | void,
169169
userStatus: UserStatus,
170170
): PresenceStatus | 'unavailable' =>

0 commit comments

Comments
 (0)