Skip to content

Commit a7e58f5

Browse files
committed
notif: Move action creators to new module notificationActions.
1 parent 580670c commit a7e58f5

File tree

4 files changed

+37
-41
lines changed

4 files changed

+37
-41
lines changed

src/actions.js

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export * from './nav/navActions';
55
export * from './drafts/draftsActions';
66
export * from './message/fetchActions';
77
export * from './message/messagesActions';
8+
export * from './notification/notificationActions';
89
export * from './realm/realmActions';
910
export * from './outbox/outboxActions';
1011
export * from './session/sessionActions';

src/message/fetchActions.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,9 @@ import timing from '../utils/timing';
3333
import { ALL_PRIVATE_NARROW } from '../utils/narrow';
3434
import { tryUntilSuccessful } from '../utils/async';
3535
import { getFetchedMessagesForNarrow } from '../chat/narrowsSelectors';
36+
import { initNotifications } from '../notification/notificationActions';
3637
import { addToOutbox, trySendMessages } from '../outbox/outboxActions';
37-
import { initNotifications, realmInit } from '../realm/realmActions';
38+
import { realmInit } from '../realm/realmActions';
3839
import { initStreams } from '../streams/streamsActions';
3940
import { reportPresence } from '../users/usersActions';
4041
import { startEventPolling } from '../events/eventActions';
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* @flow strict-local */
2+
import type { Dispatch, GetState, DeleteTokenPushAction, SaveTokenPushAction } from '../types';
3+
import {
4+
getNotificationToken,
5+
tryStopNotifications as innerStopNotifications,
6+
} from '../notification';
7+
import { getAuth, getPushToken } from '../selectors';
8+
import { SAVE_TOKEN_PUSH, DELETE_TOKEN_PUSH } from '../actionConstants';
9+
10+
export const deleteTokenPush = (): DeleteTokenPushAction => ({
11+
type: DELETE_TOKEN_PUSH,
12+
});
13+
14+
export const saveTokenPush = (pushToken: string): SaveTokenPushAction => ({
15+
type: SAVE_TOKEN_PUSH,
16+
pushToken,
17+
});
18+
19+
export const initNotifications = () => (dispatch: Dispatch, getState: GetState) => {
20+
const auth = getAuth(getState());
21+
const pushToken = getPushToken(getState());
22+
getNotificationToken(auth, pushToken, token => {
23+
dispatch(saveTokenPush(token));
24+
});
25+
};
26+
27+
export const tryStopNotifications = () => async (dispatch: Dispatch, getState: GetState) => {
28+
const auth = getAuth(getState());
29+
const pushToken = getPushToken(getState());
30+
innerStopNotifications(auth, pushToken, () => {
31+
dispatch(deleteTokenPush());
32+
});
33+
};

src/realm/realmActions.js

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,22 @@
11
/* @flow strict-local */
22
import type {
33
Auth,
4-
GetState,
54
Dispatch,
65
RealmFilter,
76
InitialData,
87
RealmEmojiState,
98
RealmInitAction,
10-
DeleteTokenPushAction,
11-
SaveTokenPushAction,
129
InitRealmEmojiAction,
1310
InitRealmFilterAction,
1411
} from '../types';
15-
import {
16-
getNotificationToken,
17-
tryStopNotifications as innerStopNotifications,
18-
} from '../notification';
19-
import { getAuth, getPushToken } from '../selectors';
2012
import { getRealmEmojis, getRealmFilters } from '../api';
21-
import {
22-
REALM_INIT,
23-
SAVE_TOKEN_PUSH,
24-
DELETE_TOKEN_PUSH,
25-
INIT_REALM_EMOJI,
26-
INIT_REALM_FILTER,
27-
} from '../actionConstants';
13+
import { REALM_INIT, INIT_REALM_EMOJI, INIT_REALM_FILTER } from '../actionConstants';
2814

2915
export const realmInit = (data: InitialData): RealmInitAction => ({
3016
type: REALM_INIT,
3117
data,
3218
});
3319

34-
export const deleteTokenPush = (): DeleteTokenPushAction => ({
35-
type: DELETE_TOKEN_PUSH,
36-
});
37-
38-
export const saveTokenPush = (pushToken: string): SaveTokenPushAction => ({
39-
type: SAVE_TOKEN_PUSH,
40-
pushToken,
41-
});
42-
43-
export const initNotifications = () => (dispatch: Dispatch, getState: GetState) => {
44-
const auth = getAuth(getState());
45-
const pushToken = getPushToken(getState());
46-
getNotificationToken(auth, pushToken, token => {
47-
dispatch(saveTokenPush(token));
48-
});
49-
};
50-
51-
export const tryStopNotifications = () => async (dispatch: Dispatch, getState: GetState) => {
52-
const auth = getAuth(getState());
53-
const pushToken = getPushToken(getState());
54-
innerStopNotifications(auth, pushToken, () => {
55-
dispatch(deleteTokenPush());
56-
});
57-
};
58-
5920
export const initRealmEmojis = (emojis: RealmEmojiState): InitRealmEmojiAction => ({
6021
type: INIT_REALM_EMOJI,
6122
emojis,

0 commit comments

Comments
 (0)