Skip to content

Commit 8e383e5

Browse files
committed
presence: Rename type Presence to clearer UserPresence.
There are lots of different types involved in the presence system, and it's not particularly obvious which one the name `Presence` would go to in preference to the others. Be explicit.
1 parent e763ab1 commit 8e383e5

11 files changed

+25
-25
lines changed

src/account-info/AccountDetails.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { PureComponent } from 'react';
33
import { View, Dimensions, StyleSheet } from 'react-native';
44

5-
import type { Dispatch, Presence, User } from '../types';
5+
import type { Dispatch, UserPresence, User } from '../types';
66
import { Avatar, ComponentList, RawLabel, ZulipButton } from '../common';
77
import { IconPrivateChat } from '../common/Icons';
88
import { privateNarrow } from '../utils/narrow';
@@ -26,7 +26,7 @@ const componentStyles = StyleSheet.create({
2626
type Props = {|
2727
dispatch: Dispatch,
2828
user: User,
29-
presence: Presence,
29+
presence: UserPresence,
3030
|};
3131

3232
export default class AccountDetails extends PureComponent<Props, void> {

src/actionTypes.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ import type {
8686
Subscription,
8787
Topic,
8888
PresenceState,
89-
Presence,
89+
UserPresence,
9090
RealmEmojiState,
9191
SettingsState,
9292
CaughtUpState,
@@ -390,7 +390,7 @@ export type EventPresenceAction = {|
390390
...ServerEvent,
391391
type: typeof EVENT_PRESENCE,
392392
email: string,
393-
presence: Presence,
393+
presence: UserPresence,
394394
server_timestamp: number,
395395
|};
396396

src/common/Avatar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
44
import React, { PureComponent } from 'react';
55
import { StyleSheet } from 'react-native';
66

7-
import type { GlobalState, Presence } from '../types';
7+
import type { GlobalState, UserPresence } from '../types';
88
import { nullFunction } from '../nullObjects';
99
import { getCurrentRealm } from '../selectors';
1010
import ImageAvatar from './ImageAvatar';
@@ -26,7 +26,7 @@ type Props = {|
2626
email: string,
2727
name: string,
2828
size: number,
29-
presence?: Presence,
29+
presence?: UserPresence,
3030
realm: string,
3131
shape: 'square' | 'rounded' | 'circle',
3232
onPress?: () => void,

src/common/UserStatusIndicator.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import React, { PureComponent } from 'react';
44
import { StyleSheet, View } from 'react-native';
55

6-
import type { Style, Presence } from '../types';
6+
import type { Style, UserPresence } from '../types';
77
import { statusFromPresence } from '../utils/presence';
88

99
const styles = StyleSheet.create({
@@ -27,7 +27,7 @@ const styles = StyleSheet.create({
2727

2828
type Props = {|
2929
style?: Style,
30-
presence?: Presence,
30+
presence?: UserPresence,
3131
hideIfOffline: boolean,
3232
|};
3333

@@ -38,7 +38,7 @@ type Props = {|
3838
* * gray if 'offline'
3939
*
4040
* @prop [style] - Style object for additional customization.
41-
* @prop [presence] - Presence object used to determine the status from.
41+
* @prop [presence] - UserPresence object used to determine the status from.
4242
* @prop hideIfOffline - Do not render for 'offline' state.
4343
*/
4444
export default class UserStatusIndicator extends PureComponent<Props> {

src/nullObjects.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import type {
33
User,
44
Subscription,
5-
Presence,
5+
UserPresence,
66
PresenceAggregated,
77
CaughtUp,
88
Fetching,
@@ -61,7 +61,7 @@ export const NULL_PRESENCE_AGGREGATED: PresenceAggregated = {
6161
};
6262

6363
/** DEPRECATED; don't add new uses. See block comment above definition. */
64-
export const NULL_PRESENCE: Presence = {
64+
export const NULL_PRESENCE: UserPresence = {
6565
aggregated: NULL_PRESENCE_AGGREGATED,
6666
};
6767

src/title/ActivityText.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import { connect } from 'react-redux';
33

44
import React, { PureComponent } from 'react';
55

6-
import type { Presence, Style } from '../types';
6+
import type { UserPresence, Style } from '../types';
77
import { getPresence } from '../selectors';
88
import { presenceToHumanTime } from '../utils/presence';
99
import { RawLabel } from '../common';
1010

1111
type Props = {
1212
color?: string,
13-
presence: Presence,
13+
presence: UserPresence,
1414
style: Style,
1515
};
1616

src/title/TitlePrivate.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { connect } from 'react-redux';
44
import React, { PureComponent } from 'react';
55
import { Text, View } from 'react-native';
66

7-
import type { Presence, User } from '../types';
7+
import type { UserPresence, User } from '../types';
88
import { Avatar, ViewPlaceholder } from '../common';
99
import ActivityText from './ActivityText';
1010
import { getPresence } from '../directSelectors';
@@ -14,7 +14,7 @@ import styles from '../styles';
1414
type Props = {
1515
user: User,
1616
color: string,
17-
presence: Presence,
17+
presence: UserPresence,
1818
};
1919

2020
class TitlePrivate extends PureComponent<Props> {

src/types.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export type PresenceAggregated = {|
159159
* to display the user's presence status.
160160
* @prop (client) - The information reported by each of the user's clients.
161161
*/
162-
export type Presence = {|
162+
export type UserPresence = {|
163163
aggregated: PresenceAggregated,
164164
[client: string]: ClientPresence,
165165
|};
@@ -399,7 +399,7 @@ export type UserGroupsState = UserGroup[];
399399
* presence status.
400400
*/
401401
export type PresenceState = {|
402-
[email: string]: Presence,
402+
[email: string]: UserPresence,
403403
|};
404404

405405
export type OutboxState = Outbox[];

src/users/UserItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import React, { PureComponent } from 'react';
33
import { StyleSheet, View } from 'react-native';
44

5-
import type { Presence } from '../types';
5+
import type { UserPresence } from '../types';
66
import { Avatar, RawLabel, Touchable, UnreadCount } from '../common';
77
import styles, { BRAND_COLOR } from '../styles';
88

@@ -29,7 +29,7 @@ type Props = {|
2929
email: string,
3030
fullName: string,
3131
avatarUrl: ?string,
32-
presence?: Presence,
32+
presence?: UserPresence,
3333
isSelected: boolean,
3434
showEmail: boolean,
3535
unreadCount?: number,

src/users/userHelpers.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* @flow */
22
import uniqby from 'lodash.uniqby';
33

4-
import type { Presence, User, UserGroup, PresenceState } from '../types';
4+
import type { UserPresence, User, UserGroup, PresenceState } from '../types';
55
import { NULL_USER } from '../nullObjects';
66
import { statusFromPresence } from '../utils/presence';
77

@@ -31,7 +31,7 @@ export const groupUsersByStatus = (users: User[], presences: PresenceState): Obj
3131
{ active: [], idle: [], offline: [] },
3232
);
3333

34-
const statusOrder = (presence: Presence): number => {
34+
const statusOrder = (presence: UserPresence): number => {
3535
const status = statusFromPresence(presence);
3636
switch (status) {
3737
case 'active':

src/utils/presence.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import differenceInSeconds from 'date-fns/difference_in_seconds';
33
import distanceInWordsToNow from 'date-fns/distance_in_words_to_now';
44

5-
import type { PresenceAggregated, Presence, UserStatus } from '../types';
5+
import type { PresenceAggregated, UserPresence, UserStatus } from '../types';
66

77
const OFFLINE_THRESHOLD_SECS = 140;
88

@@ -16,7 +16,7 @@ const OFFLINE_THRESHOLD_SECS = 140;
1616
* This logic should match `status_from_timestamp` in the web app's
1717
* `static/js/presence.js`.
1818
*/
19-
export const getAggregatedPresence = (presence: Presence): PresenceAggregated =>
19+
export const getAggregatedPresence = (presence: UserPresence): PresenceAggregated =>
2020
/* Out of the ClientPresence objects found in `presence`, we consider only
2121
* those with a timestamp newer than OFFLINE_THRESHOLD_SECS; then of
2222
* those, return the one that has the greatest UserStatus, where
@@ -53,7 +53,7 @@ export const getAggregatedPresence = (presence: Presence): PresenceAggregated =>
5353
{ client: '', status: 'offline', timestamp: 0 },
5454
);
5555

56-
export const presenceToHumanTime = (presence: Presence): string => {
56+
export const presenceToHumanTime = (presence: UserPresence): string => {
5757
if (!presence || !presence.aggregated) {
5858
return 'never';
5959
}
@@ -64,7 +64,7 @@ export const presenceToHumanTime = (presence: Presence): string => {
6464
: `${distanceInWordsToNow(lastTimeActive)} ago`;
6565
};
6666

67-
export const statusFromPresence = (presence?: Presence): UserStatus => {
67+
export const statusFromPresence = (presence?: UserPresence): UserStatus => {
6868
if (!presence || !presence.aggregated) {
6969
return 'offline';
7070
}

0 commit comments

Comments
 (0)