Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 31 additions & 31 deletions src/api/eventTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,24 @@ export class EventTypes {
static user_status: 'user_status' = 'user_status';
}

type EventCommon = {|
type EventCommon = $ReadOnly<{|
id: number,
|};
|}>;

/** A common supertype of all events, known or unknown. */
export type GeneralEvent = {
export type GeneralEvent = $ReadOnly<{
...EventCommon,
type: string,
// Note this is an inexact object type! There will be more properties.
...
};
}>;

export type HeartbeatEvent = {|
export type HeartbeatEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.heartbeat,
|};
|}>;

export type MessageEvent = {|
export type MessageEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.message,
message: Message,
Expand All @@ -70,32 +70,32 @@ export type MessageEvent = {|
* Otherwise absent.
*/
local_message_id?: number,
|};
|}>;

export type MutedUsersEvent = {|
export type MutedUsersEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.muted_users,
muted_users: MutedUser[],
|};
muted_users: $ReadOnlyArray<MutedUser>,
|}>;

/** A new submessage. See the `Submessage` type for details. */
export type SubmessageEvent = {|
export type SubmessageEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.submessage,
submessage_id: number,
message_id: number,
sender_id: UserId,
msg_type: 'widget',
content: string,
|};
|}>;

export type PresenceEvent = {|
export type PresenceEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.presence,
email: string,
server_timestamp: number,
presence: UserPresence,
|};
|}>;

/**
* Updates the user status for a user
Expand All @@ -109,37 +109,37 @@ export type PresenceEvent = {|
*
* Not providing a property means 'leave this value unchanged'
*/
export type UserStatusEvent = {|
export type UserStatusEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.user_status,
user_id: UserId,
away?: boolean,
status_text?: string,
|};
|}>;

type StreamListEvent = {|
type StreamListEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.stream,
streams: Stream[],
|};
streams: $ReadOnlyArray<Stream>,
|}>;

// prettier-ignore
export type StreamEvent =
| {| ...StreamListEvent, op: 'create', |}
| {| ...StreamListEvent, op: 'delete', |}
| {| ...StreamListEvent, op: 'occupy', |}
| {| ...StreamListEvent, op: 'vacate', |}
| {|
| {| ...StreamListEvent, +op: 'create', |}
| {| ...StreamListEvent, +op: 'delete', |}
| {| ...StreamListEvent, +op: 'occupy', |}
| {| ...StreamListEvent, +op: 'vacate', |}
| $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.stream,
op: 'update',
stream_id: number,
name: string,
property: string,
value: string,
|};
|}>;

export type UpdateMessageFlagsEvent = {|
export type UpdateMessageFlagsEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.update_message_flags,

Expand All @@ -150,11 +150,11 @@ export type UpdateMessageFlagsEvent = {|

flag: empty, // TODO fill in
all: boolean,
messages: number[],
|};
messages: $ReadOnlyArray<number>,
|}>;

// https://zulip.com/api/get-events#restart
export type RestartEvent = {|
export type RestartEvent = $ReadOnly<{|
...EventCommon,
type: typeof EventTypes.restart,

Expand All @@ -170,4 +170,4 @@ export type RestartEvent = {|
// the /server_settings and /register responses.
zulip_version?: string,
zulip_feature_level?: number,
|};
|}>;
38 changes: 19 additions & 19 deletions src/api/initialDataTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type InitialDataBase = $ReadOnly<{|
|}>;

export type InitialDataAlertWords = $ReadOnly<{|
alert_words: string[],
alert_words: $ReadOnlyArray<string>,
|}>;

export type InitialDataMessage = $ReadOnly<{|
Expand All @@ -33,16 +33,16 @@ export type InitialDataMessage = $ReadOnly<{|
export type MuteTuple = [string, string];

export type InitialDataMutedTopics = $ReadOnly<{|
muted_topics: MuteTuple[],
muted_topics: $ReadOnlyArray<MuteTuple>,
|}>;

/** Added in server version 4.0, feature level 48 */
export type InitialDataMutedUsers = $ReadOnly<{|
muted_users?: MutedUser[],
muted_users?: $ReadOnlyArray<MutedUser>,
|}>;

export type InitialDataPresence = $ReadOnly<{|
presences: {| [email: string]: UserPresence |},
presences: {| +[email: string]: UserPresence |},
|}>;

export type AvailableVideoChatProviders = $ReadOnly<{|
Expand Down Expand Up @@ -234,7 +234,7 @@ export type StreamUnreadItem = $ReadOnly<{|
unread_message_ids: $ReadOnlyArray<number>,

/** All distinct senders of these messages; sorted. */
// sender_ids: UserId[],
// sender_ids: $ReadOnlyArray<UserId>,
|}>;

export type HuddlesUnreadItem = $ReadOnly<{|
Expand Down Expand Up @@ -263,7 +263,7 @@ export type PmsUnreadItem = $ReadOnly<{|
|}>;

/** Initial data for `update_message_flags` events. */
export type InitialDataUpdateMessageFlags = {|
export type InitialDataUpdateMessageFlags = $ReadOnly<{|
/**
* A summary of (almost) all unread messages, even those we don't have.
*
Expand All @@ -288,24 +288,24 @@ export type InitialDataUpdateMessageFlags = {|
// This is computed by `aggregate_unread_data` and its helper
// `aggregate_message_dict`, consuming data supplied by
// `get_raw_unread_data`, all found in `zerver/lib/message.py`.
unread_msgs: {|
unread_msgs: $ReadOnly<{|
/**
* Unread stream messages.
*
* NB this includes messages to muted streams and topics.
*/
streams: StreamUnreadItem[],
streams: $ReadOnlyArray<StreamUnreadItem>,

/** Unread group PM messages, i.e. with >=3 participants. */
// "huddle" is the server's internal term for a group PM conversation.
huddles: HuddlesUnreadItem[],
huddles: $ReadOnlyArray<HuddlesUnreadItem>,

/** Unread 1:1 PM messages. */
pms: PmsUnreadItem[],
pms: $ReadOnlyArray<PmsUnreadItem>,

/** Unread @-mentions. */
// Unlike other lists of message IDs here, `mentions` is *not* sorted.
mentions: number[],
mentions: $ReadOnlyArray<number>,

/**
* Total *unmuted* unreads.
Expand All @@ -315,20 +315,20 @@ export type InitialDataUpdateMessageFlags = {|
* messages that are muted.
*/
count: number,
|},
|};
|}>,
|}>;

export type InitialDataUserStatus = {|
export type InitialDataUserStatus = $ReadOnly<{|
/**
* Older servers (through at least 1.9.1) don't send this.
* A missing value is equivalent to empty.
*/
user_status?: UserStatusMapObject,
|};
|}>;

// Initial data snapshot sent in response to a `/register` request,
// after validation and transformation.
export type InitialData = {|
export type InitialData = $ReadOnly<{|
// The server sends different subsets of the full available data,
// depending on what event types the client subscribes to with the
// `fetch_event_types` field of the `/register` request. We name these
Expand All @@ -355,12 +355,12 @@ export type InitialData = {|
...InitialDataUpdateGlobalNotifications,
...InitialDataUpdateMessageFlags,
...InitialDataUserStatus,
|};
|}>;

// Initial data snapshot sent in response to a `/register` request,
// before validation and transformation.
export type RawInitialData = {|
export type RawInitialData = $ReadOnly<{|
...InitialData,
...RawInitialDataRealmUser,
...RawInitialDataRealmFilters,
|};
|}>;
2 changes: 1 addition & 1 deletion src/api/modelTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ export type StreamMessage = $ReadOnly<{|
* `EVENT_NEW_MESSAGE` Redux action for the event;
* * `messages: Message[]` in a `/messages` (our `getMessages`) response,
* and our resulting `MESSAGE_FETCH_COMPLETE` Redux action;
* * `messages: {| [id]: Message |}` in our global Redux state.
* * `messages: Map<number, Message>` in our global Redux state.
*
* References include:
* * the two example events at https://zulip.com/api/get-events
Expand Down
16 changes: 8 additions & 8 deletions src/api/transportTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
* leaves out the secret API key; use `identityOfAuth` to extract one from
* an `Auth`.
*/
export type Auth = {|
export type Auth = $ReadOnly<{|
realm: URL,
apiKey: string,
email: string,
|};
|}>;

/**
* The type shared by all Zulip API responses.
Expand All @@ -30,11 +30,11 @@ export type Auth = {|
* * {@link ApiResponseSuccess}
* * {@link ApiResponseErrorData}
*/
export type ApiResponse = {
export type ApiResponse = $ReadOnly<{
+result: string,
+msg: string,
...
};
}>;

/**
* The type shared by all non-error Zulip API responses.
Expand All @@ -45,11 +45,11 @@ export type ApiResponse = {
* * {@link ApiResponse}
* * {@link ApiResponseErrorData}
*/
export type ApiResponseSuccess = {
export type ApiResponseSuccess = $ReadOnly<{
+result: 'success',
+msg: '',
...
};
}>;

/**
* A list of current error codes can be found at:
Expand Down Expand Up @@ -92,9 +92,9 @@ export type ApiErrorCode = string;
*
* This type is not exact: some error responses may contain additional data.
*/
export type ApiResponseErrorData = {
export type ApiResponseErrorData = $ReadOnly<{
+code: ApiErrorCode,
+msg: string,
+result: 'error',
...
};
}>;
2 changes: 1 addition & 1 deletion src/mute/mutedUsersReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { MutedUser } from '../api/apiTypes';

const initialState: MutedUsersState = Immutable.Map();

function mutedUsersToMap(muted_users: MutedUser[]): Immutable.Map<UserId, number> {
function mutedUsersToMap(muted_users: $ReadOnlyArray<MutedUser>): Immutable.Map<UserId, number> {
return Immutable.Map(muted_users.map(muted_user => [muted_user.id, muted_user.timestamp]));
}

Expand Down