forked from zulip/zulip-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactionTypes.js
639 lines (553 loc) · 13.6 KB
/
actionTypes.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
/* @flow */
import type { NavigationNavigateAction } from 'react-navigation';
import {
REHYDRATE,
APP_ONLINE,
APP_STATE,
DEAD_QUEUE,
INIT_SAFE_AREA_INSETS,
APP_ORIENTATION,
START_EDIT_MESSAGE,
CANCEL_EDIT_MESSAGE,
DEBUG_FLAG_TOGGLE,
ACCOUNT_SWITCH,
REALM_ADD,
ACCOUNT_REMOVE,
LOGIN_SUCCESS,
LOGOUT,
REALM_INIT,
GOT_PUSH_TOKEN,
UNACK_PUSH_TOKEN,
ACK_PUSH_TOKEN,
MESSAGE_FETCH_START,
MESSAGE_FETCH_COMPLETE,
MARK_MESSAGES_READ,
INITIAL_FETCH_START,
INITIAL_FETCH_COMPLETE,
INIT_REALM_EMOJI,
INIT_REALM_FILTER,
SETTINGS_CHANGE,
DRAFT_UPDATE,
DO_NARROW,
PRESENCE_RESPONSE,
MESSAGE_SEND_START,
MESSAGE_SEND_COMPLETE,
DELETE_OUTBOX_MESSAGE,
TOGGLE_OUTBOX_SENDING,
EVENT_MESSAGE_DELETE,
EVENT_USER_GROUP_ADD,
EVENT_USER_GROUP_REMOVE,
EVENT_USER_GROUP_UPDATE,
EVENT_USER_GROUP_ADD_MEMBERS,
EVENT_USER_GROUP_REMOVE_MEMBERS,
EVENT_TYPING_START,
EVENT_TYPING_STOP,
EVENT_NEW_MESSAGE,
EVENT_REACTION_ADD,
EVENT_REACTION_REMOVE,
EVENT_PRESENCE,
EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
EVENT_UPDATE_MESSAGE,
EVENT_UPDATE_MESSAGE_FLAGS,
EVENT_USER_ADD,
CLEAR_TYPING,
INIT_ALERT_WORDS,
INIT_STREAMS,
INIT_TOPICS,
INIT_SUBSCRIPTIONS,
EVENT_MUTED_TOPICS,
EVENT_REALM_FILTERS,
EVENT_USER_REMOVE,
EVENT_USER_UPDATE,
EVENT_REALM_EMOJI_UPDATE,
EVENT_UPDATE_DISPLAY_SETTINGS,
EVENT_SUBSCRIPTION,
EVENT,
} from './actionConstants';
import type { MessageEvent, PresenceEvent, StreamEvent } from './api/eventTypes';
import type {
Dimensions,
Orientation,
GlobalState,
Message,
MessagesState,
Outbox,
Narrow,
Reaction,
Identity,
User,
UserGroup,
InitialData,
RealmFilter,
Stream,
Subscription,
Topic,
PresenceState,
RealmEmojiState,
SettingsState,
CaughtUpState,
MuteState,
AlertWordsState,
} from './types';
/**
* Dispatched by redux-persist when the stored state is loaded.
*
* It can be very convenient to pass `payload` to selectors, but beware it's
* incomplete. At a minimum, reducers should always separately handle the
* case where the state is empty or has `null` properties before passing the
* object to any selector.
*
* @prop payload A version of the global Redux state, as persisted by the
* app's previous runs. This will be empty on first startup or if the
* persisted store is just missing keys, and will have `null` at each
* key where an error was encountered in reading the persisted store.
* In any case it will only contain the keys we configure to be persisted.
* @prop error
*/
type RehydrateAction = {|
type: typeof REHYDRATE,
payload: GlobalState | { accounts: null } | {||} | void,
error: ?Object,
|};
type AppOnlineAction = {|
type: typeof APP_ONLINE,
isOnline: boolean,
|};
type AppStateAction = {|
type: typeof APP_STATE,
isActive: boolean,
|};
type DeadQueueAction = {|
type: typeof DEAD_QUEUE,
|};
type InitSafeAreaInsetsAction = {|
type: typeof INIT_SAFE_AREA_INSETS,
safeAreaInsets: Dimensions,
|};
type AppOrientationAction = {|
type: typeof APP_ORIENTATION,
orientation: Orientation,
|};
type StartEditMessageAction = {|
type: typeof START_EDIT_MESSAGE,
messageId: number,
message: string,
topic: string,
|};
type CancelEditMessageAction = {|
type: typeof CANCEL_EDIT_MESSAGE,
|};
type DebugFlagToggleAction = {|
type: typeof DEBUG_FLAG_TOGGLE,
key: string,
value: string,
|};
export type NavigateAction = NavigationNavigateAction;
type AccountSwitchAction = {|
type: typeof ACCOUNT_SWITCH,
index: number,
|};
type RealmAddAction = {|
type: typeof REALM_ADD,
realm: string,
|};
type AccountRemoveAction = {|
type: typeof ACCOUNT_REMOVE,
index: number,
|};
type LoginSuccessAction = {|
type: typeof LOGIN_SUCCESS,
realm: string,
email: string,
apiKey: string,
|};
type LogoutAction = {|
type: typeof LOGOUT,
|};
type RealmInitAction = {|
type: typeof REALM_INIT,
data: InitialData,
|};
/** We learned the device token from the system. See `SessionState`. */
type GotPushTokenAction = {|
type: typeof GOT_PUSH_TOKEN,
pushToken: string,
|};
/** We're about to tell the server to forget our device token. */
type UnackPushTokenAction = {|
type: typeof UNACK_PUSH_TOKEN,
identity: Identity,
|};
/** The server acknowledged our device token. */
type AckPushTokenAction = {|
type: typeof ACK_PUSH_TOKEN,
identity: Identity,
pushToken: string,
|};
type MessageFetchStartAction = {|
type: typeof MESSAGE_FETCH_START,
narrow: Narrow,
numBefore: number,
numAfter: number,
|};
type MessageFetchCompleteAction = {|
type: typeof MESSAGE_FETCH_COMPLETE,
messages: Message[],
narrow: Narrow,
anchor: number,
numBefore: number,
numAfter: number,
|};
type MarkMessagesReadAction = {|
type: typeof MARK_MESSAGES_READ,
messageIds: number[],
|};
type InitialFetchStartAction = {|
type: typeof INITIAL_FETCH_START,
|};
type InitialFetchCompleteAction = {|
type: typeof INITIAL_FETCH_COMPLETE,
|};
type ServerEvent = {|
id: number,
|};
type EventAlertWordsAction = {|
type: typeof INIT_ALERT_WORDS,
alertWords: AlertWordsState,
|};
type EventRealmFiltersAction = {|
type: typeof EVENT_REALM_FILTERS,
[string]: any,
|};
type EventUpdateGlobalNotificationsSettingsAction = {|
...ServerEvent,
type: typeof EVENT_UPDATE_GLOBAL_NOTIFICATIONS_SETTINGS,
notification_name: | 'enable_offline_push_notiications'
| 'enable_online_push_notiications'
| 'enable_stream_push_notifiations',
setting: boolean,
|};
type EventSubscriptionAddAction = {|
...ServerEvent,
type: typeof EVENT_SUBSCRIPTION,
op: 'add',
subscriptions: Subscription[],
|};
type EventSubscriptionRemoveAction = {|
...ServerEvent,
type: typeof EVENT_SUBSCRIPTION,
op: 'remove',
subscriptions: Array<{
name: string,
stream_id: number,
}>,
|};
type EventSubscriptionUpdateAction = {|
...ServerEvent,
type: typeof EVENT_SUBSCRIPTION,
op: 'update',
email: string,
name: string,
property: string,
stream_id: number,
value: boolean | number | string,
|};
type EventSubscriptionPeerAddAction = {|
...ServerEvent,
type: typeof EVENT_SUBSCRIPTION,
op: 'peer_add',
subscriptions: string[],
user_id: number,
|};
type EventSubscriptionPeerRemoveAction = {|
...ServerEvent,
type: typeof EVENT_SUBSCRIPTION,
op: 'peer_remove',
subscriptions: string[],
user_id: number,
|};
type GenericEventAction = {|
type: typeof EVENT,
event: StreamEvent,
|};
type EventNewMessageAction = {|
...$Diff<MessageEvent, { flags: mixed }>,
type: typeof EVENT_NEW_MESSAGE,
caughtUp: CaughtUpState,
ownEmail: string,
|};
type EventMessageDeleteAction = {|
type: typeof EVENT_MESSAGE_DELETE,
messageId: number,
|};
type EventUpdateMessageAction = {|
...ServerEvent,
type: typeof EVENT_UPDATE_MESSAGE,
edit_timestamp: number,
message_id: number,
orig_content: string,
orig_subject?: string,
orig_rendered_content: string,
prev_rendered_content_version: number,
rendered_content: string,
subject_links: string[],
subject: string,
user_id: number,
|};
type EventReactionCommon = {|
...ServerEvent,
...$Exact<Reaction>,
message_id: number,
|};
type EventReactionAddAction = {|
...ServerEvent,
...EventReactionCommon,
type: typeof EVENT_REACTION_ADD,
|};
type EventReactionRemoveAction = {|
...ServerEvent,
...EventReactionCommon,
type: typeof EVENT_REACTION_REMOVE,
|};
type EventPresenceAction = {|
...PresenceEvent,
type: typeof EVENT_PRESENCE,
|};
type EventTypingCommon = {|
...ServerEvent,
ownEmail: string,
recipients: Array<{
user_id: number,
email: string,
}>,
sender: {
user_id: number,
email: string,
},
time: number,
|};
type EventTypingStartAction = {|
...EventTypingCommon,
type: typeof EVENT_TYPING_START,
op: 'start',
|};
type EventTypingStopAction = {|
...EventTypingCommon,
type: typeof EVENT_TYPING_STOP,
op: 'stop',
|};
type EventUpdateMessageFlagsAction = {|
...ServerEvent,
type: typeof EVENT_UPDATE_MESSAGE_FLAGS,
all: boolean,
allMessages: MessagesState,
flag: string,
messages: number[],
operation: 'add' | 'remove',
|};
type EventUserAddAction = {|
...ServerEvent,
type: typeof EVENT_USER_ADD,
person: User,
|};
type EventUserRemoveAction = {|
type: typeof EVENT_USER_REMOVE,
// In reality there's more -- but this will prevent accidentally using
// the type before going and adding those other properties here properly.
|};
type EventUserUpdateAction = {|
type: typeof EVENT_USER_UPDATE,
// In reality there's more -- but this will prevent accidentally using
// the type before going and adding those other properties here properly.
|};
type EventMutedTopicsAction = {|
...ServerEvent,
type: typeof EVENT_MUTED_TOPICS,
muted_topics: MuteState,
|};
type EventUserGroupAddAction = {|
...ServerEvent,
type: typeof EVENT_USER_GROUP_ADD,
op: 'add',
group: UserGroup,
|};
type EventUserGroupRemoveAction = {|
...ServerEvent,
type: typeof EVENT_USER_GROUP_REMOVE,
op: 'remove',
group_id: number,
|};
type EventUserGroupUpdateAction = {|
...ServerEvent,
type: typeof EVENT_USER_GROUP_UPDATE,
op: 'update',
group_id: number,
data: { description?: string, name?: string },
|};
type EventUserGroupAddMembersAction = {|
...ServerEvent,
type: typeof EVENT_USER_GROUP_ADD_MEMBERS,
op: 'add_members',
group_id: number,
user_ids: number[],
|};
type EventUserGroupRemoveMembersAction = {|
...ServerEvent,
type: typeof EVENT_USER_GROUP_REMOVE_MEMBERS,
op: 'remove_members',
group_id: number,
user_ids: number[],
|};
type EventRealmEmojiUpdateAction = {|
type: typeof EVENT_REALM_EMOJI_UPDATE,
[string]: any,
|};
type EventUpdateDisplaySettingsAction = {|
type: typeof EVENT_UPDATE_DISPLAY_SETTINGS,
[string]: any,
|};
type EventReactionAction = EventReactionAddAction | EventReactionRemoveAction;
type EventSubscriptionAction =
| EventSubscriptionAddAction
| EventSubscriptionRemoveAction
| EventSubscriptionUpdateAction
| EventSubscriptionPeerAddAction
| EventSubscriptionPeerRemoveAction;
type EventTypingAction = EventTypingStartAction | EventTypingStopAction;
type EventUserAction = EventUserAddAction | EventUserRemoveAction | EventUserUpdateAction;
type EventUserGroupAction =
| EventUserGroupAddAction
| EventUserGroupRemoveAction
| EventUserGroupUpdateAction
| EventUserGroupAddMembersAction
| EventUserGroupRemoveMembersAction;
/** Covers all actions we make from server events. */
export type EventAction =
| GenericEventAction
// Specific actions.
| EventAlertWordsAction
| EventMessageDeleteAction
| EventMutedTopicsAction
| EventNewMessageAction
| EventPresenceAction
| EventRealmEmojiUpdateAction
| EventRealmFiltersAction
| EventUpdateGlobalNotificationsSettingsAction
| EventUpdateDisplaySettingsAction
| EventUpdateMessageAction
| EventUpdateMessageFlagsAction
// Unions, found just above.
| EventReactionAction
| EventSubscriptionAction
| EventTypingAction
| EventUserAction
| EventUserGroupAction
// Dummy actions.
| {| type: 'ignore' |}
| {| type: 'unknown', event: {} |};
type InitRealmEmojiAction = {|
type: typeof INIT_REALM_EMOJI,
emojis: RealmEmojiState,
|};
type InitRealmFilterAction = {|
type: typeof INIT_REALM_FILTER,
filters: RealmFilter[],
|};
type SettingsChangeAction = {|
type: typeof SETTINGS_CHANGE,
update: $Shape<SettingsState>,
|};
type DraftUpdateAction = {|
type: typeof DRAFT_UPDATE,
narrow: Narrow,
content: string,
|};
type DoNarrowAction = {|
type: typeof DO_NARROW,
narrow: Narrow,
|};
type PresenceResponseAction = {|
type: typeof PRESENCE_RESPONSE,
presence: PresenceState,
serverTimestamp: number,
|};
type MessageSendStartAction = {|
type: typeof MESSAGE_SEND_START,
outbox: Outbox,
|};
type MessageSendCompleteAction = {|
type: typeof MESSAGE_SEND_COMPLETE,
local_message_id: number,
|};
type DeleteOutboxMessageAction = {|
type: typeof DELETE_OUTBOX_MESSAGE,
local_message_id: number,
|};
type ToggleOutboxSendingAction = {|
type: typeof TOGGLE_OUTBOX_SENDING,
sending: boolean,
|};
type ClearTypingAction = {|
type: typeof CLEAR_TYPING,
outdatedNotifications: string[],
|};
type InitStreamsAction = {|
type: typeof INIT_STREAMS,
streams: Stream[],
|};
type InitTopicsAction = {|
type: typeof INIT_TOPICS,
topics: Topic[],
streamId: number,
|};
type InitSubscriptionsAction = {|
type: typeof INIT_SUBSCRIPTIONS,
subscriptions: Subscription[],
|};
//
// The `Action` union type.
//
type AccountAction =
| AccountSwitchAction
| RealmAddAction
| AccountRemoveAction
| LoginSuccessAction
| LogoutAction;
type LoadingAction = DeadQueueAction | InitialFetchStartAction | InitialFetchCompleteAction;
type MessageAction = MarkMessagesReadAction | MessageFetchStartAction | MessageFetchCompleteAction;
type OutboxAction = MessageSendStartAction | MessageSendCompleteAction | DeleteOutboxMessageAction;
type RealmAction =
| RealmInitAction
| UnackPushTokenAction
| AckPushTokenAction
| InitRealmEmojiAction
| InitRealmFilterAction;
type SessionAction =
| RehydrateAction
| AppStateAction
| AppOnlineAction
| InitSafeAreaInsetsAction
| AppOrientationAction
| DoNarrowAction
| GotPushTokenAction
| StartEditMessageAction
| CancelEditMessageAction
| DebugFlagToggleAction
| ToggleOutboxSendingAction;
/** Covers all actions we ever `dispatch`. */
// The grouping here is completely arbitrary; don't worry about it.
export type Action =
| EventAction
| AccountAction
| LoadingAction
| MessageAction
| OutboxAction
| RealmAction
| SessionAction
| DraftUpdateAction
| PresenceResponseAction
| SettingsChangeAction
| InitStreamsAction
| InitSubscriptionsAction
| InitTopicsAction
| ClearTypingAction;