@@ -9,11 +9,12 @@ import {
9
9
reducer as presenceReducer ,
10
10
getAggregatedPresence ,
11
11
statusFromPresence ,
12
- statusFromPresenceAndUserStatus ,
13
12
getUserLastActiveAsRelativeTimeString ,
13
+ getPresenceStatusForUserId ,
14
14
} from '../presenceModel' ;
15
15
import { makePresenceState } from './presence-testlib' ;
16
16
import type { UserPresence , UserStatus } from '../../api/modelTypes' ;
17
+ import type { PerAccountState } from '../../reduxTypes' ;
17
18
18
19
const currentTimestamp = Date . now ( ) / 1000 ;
19
20
@@ -189,23 +190,40 @@ describe('statusFromPresence', () => {
189
190
} ) ;
190
191
} ) ;
191
192
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
+
193
207
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' ) ;
200
216
} ) ;
201
217
202
218
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' ) ;
209
227
} ) ;
210
228
} ) ;
211
229
0 commit comments