forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypes.js
724 lines (631 loc) · 17.9 KB
/
types.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
/* @flow strict-local */
import type { Node } from 'react';
import type { IntlShape } from 'react-intl';
import type { InputSelector } from 'reselect';
import type { DangerouslyImpreciseStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';
import type { Action, NavigateAction } from './actionTypes';
import type {
Auth,
Topic,
Message,
Reaction,
RealmEmojiState,
RealmFilter,
Narrow,
Stream,
Subscription,
User,
UserPresence,
} from './api/apiTypes';
import type { AppStyles } from './styles/theme';
import type { SessionState } from './session/sessionReducers';
export type { ChildrenArray } from 'react';
export type React$Node = Node; // eslint-disable-line flowtype/type-id-match
export type * from './actionTypes';
export type * from './api/apiTypes';
/*
* TODO as the name suggests, this should be broken down more specifically.
* Each use should be one of ViewStyleProp, TextStyleProp, ImageStyleProp.
*/
export type Style = DangerouslyImpreciseStyleProp;
export type Orientation = 'LANDSCAPE' | 'PORTRAIT';
export type Dimensions = {|
bottom: number,
left: number,
right: number,
top: number,
|};
export type InputSelectionType = {|
start: number,
end: number,
|};
/**
* An `Identity`, a secret, and some other per-identity information.
*
* At present this consists of just the information the API client library
* needs in order to talk to the server on the user's behalf, aka `Auth`.
* NB in particular this includes an API key.
*
* In the future this might contain other metadata, if useful.
*
* See also `Identity`, which should be used instead where an API key is
* not required.
* TODO: move more code that way.
*/
export type Account = {|
...Auth,
/**
* The last device token value the server has definitely heard from us.
*
* This is `null` until we make a successful request to the server to
* tell it the token.
*
* See the `pushToken` property in `SessionState`, and docs linked there.
*/
ackedPushToken: string | null,
|};
/**
* An identity belonging to this user in some Zulip org, with no secrets.
*
* This should be used in preference to `Auth` or `Account` in code that
* doesn't need to make (authenticated) requests to the server and only
* needs to pick their own email or ID out of a list, use the org's base URL
* to make a relative URL absolute, etc.
*/
export type Identity = $Diff<Auth, { apiKey: string }>;
/** An aggregate of all the reactions with one emoji to one message. */
export type AggregatedReaction = {|
code: string,
count: number,
name: string,
selfReacted: boolean,
type: string,
|};
/** A user, as seen in the `display_recipient` of a PM `Message`. */
export type PmRecipientUser = {|
email: string,
full_name: string,
id: number,
is_mirror_dummy: boolean,
short_name: string,
|};
/**
* An index on `MessagesState`, listing messages in each narrow.
*
* Keys are `JSON.stringify`-encoded `Narrow` objects.
* Values are sorted lists of message IDs.
*
* See also `MessagesState`, which stores the message data indexed by ID.
*/
export type NarrowsState = {
[narrow: string]: number[],
};
/**
* A map with all messages we've stored locally, indexed by ID.
*
* See also `NarrowsState`, which is an index on this data that identifies
* messages belonging to a given narrow.
*/
export type MessagesState = {|
[id: number]: $Exact<Message>,
|};
export type UserIdMap = {
[userId: string]: User,
};
export type UserGroup = {|
description: string,
id: number,
members: number[],
name: string,
|};
/**
* Info about how complete our knowledge is of the messages in some narrow.
*
* @prop older - true just if in some fetch we reached the oldest message
* in the narrow. No need to fetch more in that direction.
* @prop newer - true just if in some fetch we reached the newest message in
* the narrow. Of course their may always be new messages, but we should
* learn about them through events; so again, no need to fetch more.
*/
export type CaughtUp = {|
older: boolean,
newer: boolean,
|};
export type Fetching = {|
older: boolean,
newer: boolean,
|};
export type StreamsState = Stream[];
export type SubscriptionsState = Subscription[];
export type EditMessage = {|
id: number,
content: string,
topic: string,
|};
export type AccountsState = Account[];
export type Debug = {|
highlightUnreadMessages: boolean,
doNotMarkMessagesAsRead: boolean,
|};
/**
* Info about how completely we know the messages in each narrow of
* MessagesState.
*/
export type CaughtUpState = {|
[narrow: string]: CaughtUp,
|};
export type FetchingState = {
[narrow: string]: Fetching,
};
export type FlagsState = {|
read: { [messageId: number]: boolean },
starred: { [messageId: number]: boolean },
collapsed: { [messageId: number]: boolean },
mentions: { [messageId: number]: boolean },
wildcard_mentions: { [messageId: number]: boolean },
summarize_in_home: { [messageId: number]: boolean },
summarize_in_stream: { [messageId: number]: boolean },
force_expand: { [messageId: number]: boolean },
force_collapse: { [messageId: number]: boolean },
has_alert_word: { [messageId: number]: boolean },
historical: { [messageId: number]: boolean },
is_me_message: { [messageId: number]: boolean },
|};
export type FlagName = $Keys<FlagsState>;
export type MigrationsState = {|
version?: string,
|};
export type LoadingState = {|
presence: boolean,
subscriptions: boolean,
streams: boolean,
unread: boolean,
users: boolean,
|};
export type MuteTuple = [string, string];
export type MuteState = MuteTuple[];
export type NavigationState = {|
index: number,
isTransitioning: boolean,
key: string,
routes: Array<{
key: string,
title: string,
routeName: string,
/** The fields in `params` vary by route; see `navActions.js`. */
params: {
narrow?: Narrow,
},
}>,
|};
export type RealmBot = {|
email: string,
full_name: string,
is_admin: boolean,
is_bot: true,
user_id: number,
|};
/**
* State with general info about a Zulip organization; our state subtree `realm`.
*
* @prop twentyFourHourTime
* @prop canCreateStreams
* @prop crossRealmBots - The server's cross-realm bots; e.g., Welcome Bot.
* Cross-realm bots should be treated like normal bots.
* @prop nonActiveUsers - All users in the organization with `is_active`
* false; for normal users, this means they or an admin deactivated their
* account. See `User` and the linked documentation.
* @prop filters
* @prop emoji
* @prop isAdmin
*/
export type RealmState = {|
twentyFourHourTime: boolean,
canCreateStreams: boolean,
crossRealmBots: RealmBot[],
nonActiveUsers: User[],
filters: RealmFilter[],
emoji: RealmEmojiState,
isAdmin: boolean,
|};
export type TopicExtended = {|
...$Exact<Topic>,
isMuted: boolean,
unreadCount: number,
|};
export type TopicsState = {|
[number]: Topic[],
|};
export type ThemeName = 'default' | 'night';
export type Context = {|
styles: AppStyles,
|};
export type SettingsState = {|
locale: string,
theme: ThemeName,
offlineNotification: boolean,
onlineNotification: boolean,
experimentalFeaturesEnabled: boolean,
streamNotification: boolean,
|};
export type TypingState = {|
[normalizedRecipients: string]: {
time: number,
userIds: number[],
},
|};
/**
* A message we're in the process of sending.
*
* See also `Message`.
*/
export type Outbox = {|
isOutbox: true,
isSent: boolean,
markdownContent: string,
narrow: Narrow,
// These fields are modeled on `Message`.
avatar_url: ?string,
content: string,
display_recipient: $FlowFixMe, // `string` for type stream, else PmRecipientUser[].
id: number,
reactions: Reaction[],
sender_email: string,
sender_full_name: string,
subject: string,
timestamp: number,
type: 'stream' | 'private',
// These fields are always absent here, but can appear in `Message`. We
// mention them here only to reassure Flow that they'll never be something
// more interesting than `undefined`, in order to type-check accesses on
// values of type `Message | Outbox`.
last_edit_timestamp?: void,
match_content?: void,
|};
export type StreamUnreadItem = {|
stream_id: number,
topic: string,
unread_message_ids: number[],
|};
export type HuddlesUnreadItem = {|
user_ids_string: string,
unread_message_ids: number[],
|};
export type PmsUnreadItem = {|
sender_id: number,
unread_message_ids: number[],
|};
export type UnreadStreamsState = StreamUnreadItem[];
export type UnreadHuddlesState = HuddlesUnreadItem[];
export type UnreadPmsState = PmsUnreadItem[];
export type UnreadMentionsState = number[];
export type AlertWordsState = string[];
export type DraftsState = {|
[narrow: string]: string,
|};
/**
* A collection of (almost) all users in the Zulip org; our `users` state subtree.
*
* This contains all users except deactivated users and cross-realm bots.
* For those, see RealmState.
*/
export type UsersState = User[];
export type UserGroupsState = UserGroup[];
/**
* The `presence` subtree of our Redux state.
*
* @prop (email) - Indexes over all users for which the app has received a
* presence status.
*/
export type PresenceState = {|
[email: string]: UserPresence,
|};
export type OutboxState = Outbox[];
export type UnreadState = {|
streams: UnreadStreamsState,
huddles: UnreadHuddlesState,
pms: UnreadPmsState,
mentions: UnreadMentionsState,
|};
/**
* Our complete Redux state tree.
*
* Each property is a subtree maintained by its own reducer function.
*/
export type GlobalState = {|
accounts: AccountsState,
alertWords: AlertWordsState,
caughtUp: CaughtUpState,
drafts: DraftsState,
fetching: FetchingState,
flags: FlagsState,
migrations: MigrationsState,
loading: LoadingState,
messages: MessagesState,
mute: MuteState,
narrows: NarrowsState,
nav: NavigationState,
outbox: OutboxState,
presence: PresenceState,
realm: RealmState,
session: SessionState,
settings: SettingsState,
streams: StreamsState,
subscriptions: SubscriptionsState,
topics: TopicsState,
typing: TypingState,
unread: UnreadState,
userGroups: UserGroupsState,
users: UsersState,
|};
/** A selector returning TResult. */
// Seems like this should be OutputSelector... but for whatever reason,
// putting that on a selector doesn't cause the result type to propagate to
// the corresponding parameter when used in `createSelector`, and this does.
export type Selector<TResult> = InputSelector<GlobalState, void, TResult>;
export type GetState = () => GlobalState;
export type PlainDispatch = <A: Action | NavigateAction>(action: A) => A;
export interface Dispatch {
<A: Action | NavigateAction>(action: A): A;
<T>((Dispatch, GetState) => T): T;
}
export type LocalizableText = string | { text: string, values?: { [string]: string } };
/**
* Usually called `_`, and invoked like `_('Message')` -> `'Nachricht'`.
*
* To use, put these two lines at the top of a React component's body:
*
* static contextType = TranslationContext;
* context: GetText;
*
* and then in methods, say `const _ = this.context`.
*
* Alternatively, for when `context` is already in use: use `withGetText`
* and then say `const { _ } = this.props`.
*
* @prop intl - The full react-intl API, for more complex situations.
*/
export type GetText = {
(string): string,
intl: IntlShape,
};
export type RenderedTimeDescriptor = {|
type: 'time',
key: number | string,
timestamp: number,
firstMessage: Message | Outbox,
|};
export type RenderedMessageDescriptor = {|
type: 'message',
key: number | string,
message: Message | Outbox,
isBrief: boolean,
|};
export type RenderedSectionDescriptor = {|
key: string | number,
message: Message | Outbox | {||},
data: $ReadOnlyArray<RenderedMessageDescriptor | RenderedTimeDescriptor>,
|};
export type DraftState = {|
[narrow: string]: string,
|};
export type TimingItemType = {|
text: string,
startMs: number,
endMs: number,
|};
export type UnreadTopic = {|
isMuted: boolean,
key: string,
topic: string,
unread: number,
|};
export type UnreadStream = {|
color: string,
data: UnreadTopic[],
isMuted: boolean,
isPrivate: boolean,
key: string,
streamName: string,
unread: number,
|};
export type NotificationCommon = {|
alert: string,
content: string,
content_truncated: string, // boolean
'google.message_id': string,
'google.sent_time': number,
'google.ttl': number,
event: 'message',
realm_id: string, // string
sender_avatar_url: string,
sender_email: string, // email
sender_full_name: string,
sender_id: string,
server: string,
time: string,
user: string,
zulip_message_id: string,
|};
export type NotificationPrivate = {|
...$Exact<NotificationCommon>,
recipient_type: 'private',
|};
export type NotificationGroup = {|
...$Exact<NotificationCommon>,
pm_users: string, // comma separated ids
recipient_type: 'private',
|};
export type NotificationStream = {|
...$Exact<NotificationCommon>,
recipient_type: 'stream',
stream: string,
topic: string,
|};
export type Notification = NotificationPrivate | NotificationGroup | NotificationStream;
export type NamedUser = {|
id: number,
email: string,
full_name: string,
|};
export type TabNavigationOptionsPropsType = {|
isFocussed: boolean,
tintColor: string,
|};
export type NeverSubscribedStream = {|
description: string,
invite_only: boolean,
is_old_stream: boolean,
name: string,
stream_id: number,
|};
/**
* Summary of a PM conversation (either 1:1 or group PMs).
*/
export type PmConversationData = {|
ids: string,
msgId: number,
recipients: string,
timestamp: number,
unread: number,
|};
export type InitialDataBase = {|
last_event_id: number,
msg: string,
queue_id: number,
|};
export type InitialDataAlertWords = {|
alert_words: string[],
|};
export type InitialDataMessage = {|
max_message_id: number,
|};
export type InitialDataMutedTopics = {|
muted_topics: MuteTuple[],
|};
export type InitialDataPresence = {|
presences: PresenceState,
|};
export type InitialDataRealm = {|
max_icon_file_size: number,
realm_add_emoji_by_admins_only: boolean,
realm_allow_community_topic_editing: boolean,
realm_allow_edit_history: boolean,
realm_allow_message_deleting: boolean,
realm_allow_message_editing: boolean,
realm_authentication_methods: { GitHub: true, Email: true, Google: true },
realm_available_video_chat_providers: string[],
realm_bot_creation_policy: number,
realm_bot_domain: string,
realm_create_stream_by_admins_only: boolean,
realm_default_language: string,
realm_default_twenty_four_hour_time: boolean,
realm_description: string,
realm_disallow_disposable_email_addresses: boolean,
realm_email_auth_enabled: boolean,
realm_email_changes_disabled: boolean,
realm_google_hangouts_domain: string,
realm_icon_source: string,
realm_icon_url: string,
realm_inline_image_preview: boolean,
realm_inline_url_embed_preview: boolean,
realm_invite_by_admins_only: boolean,
realm_invite_required: boolean,
realm_is_zephyr_mirror_realm: boolean,
realm_mandatory_topics: boolean,
realm_message_content_delete_limit_seconds: number,
realm_message_content_edit_limit_seconds: number,
realm_message_retention_days: ?number,
realm_name: string,
realm_name_changes_disabled: boolean,
realm_notifications_stream_id: number,
realm_password_auth_enabled: boolean,
realm_presence_disabled: boolean,
realm_restricted_to_domain: boolean,
realm_send_welcome_emails: boolean,
realm_show_digest_email: boolean,
realm_signup_notifications_stream_id: number,
realm_uri: string,
realm_video_chat_provider: string,
realm_waiting_period_threshold: number,
|};
export type InitialDataRealmEmoji = {|
realm_emoji: RealmEmojiState,
|};
export type InitialDataRealmFilters = {|
realm_filters: RealmFilter[],
|};
export type InitialDataRealmUser = {|
avatar_source: 'G',
avatar_url: string,
avatar_url_medium: string,
can_create_streams: boolean,
cross_realm_bots: RealmBot[],
email: string,
enter_sends: boolean,
full_name: string,
is_admin: boolean,
realm_non_active_users: User[],
realm_users: User[],
user_id: number,
|};
export type InitialDataRealmUserGroups = {|
realm_user_groups: UserGroup[],
|};
export type InitialDataSubscription = {|
never_subscribed: NeverSubscribedStream[],
subscriptions: Subscription[],
unsubscribed: Subscription[],
|};
export type InitialDataUpdateDisplaySettings = {|
default_language: string,
emojiset: string,
emojiset_choices: { [string]: string },
high_contrast_mode: boolean,
left_side_userlist: boolean,
night_mode: boolean,
timezone: string,
translate_emoticons: boolean,
twenty_four_hour_time: boolean,
|};
export type InitialDataUpdateGlobalNotifications = {|
default_desktop_notifications: boolean,
enable_desktop_notifications: boolean,
enable_digest_emails: boolean,
enable_offline_email_notifications: boolean,
enable_offline_push_notifications: boolean,
enable_online_push_notifications: boolean,
enable_sounds: boolean,
enable_stream_desktop_notifications: boolean,
enable_stream_email_notifications: boolean,
enable_stream_push_notifications: boolean,
enable_stream_sounds: boolean,
message_content_in_email_notifications: boolean,
pm_content_in_desktop_notifications: boolean,
realm_name_in_notifications: boolean,
|};
export type InitialDataUpdateMessageFlags = {|
unread_msgs: {
streams: UnreadStreamsState,
huddles: UnreadHuddlesState,
count: number,
pms: UnreadPmsState,
mentions: UnreadMentionsState,
},
|};
export type InitialData = {|
...InitialDataBase,
...InitialDataAlertWords,
...InitialDataMessage,
...InitialDataMutedTopics,
...InitialDataPresence,
...InitialDataRealm,
...InitialDataRealmEmoji,
...InitialDataRealmFilters,
...InitialDataRealmUser,
...InitialDataRealmUserGroups,
...InitialDataSubscription,
...InitialDataUpdateDisplaySettings,
...InitialDataUpdateGlobalNotifications,
...InitialDataUpdateMessageFlags,
|};