-
Notifications
You must be signed in to change notification settings - Fork 6
/
actions.js
151 lines (130 loc) · 3.65 KB
/
actions.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
import firebase from './firebase'
import * as types from './types'
import { metaTypes } from './types'
export function firebaseListenRequested(ref, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_REQUESTED,
payload: ref,
meta: { type: metaType },
}
}
export function firebaseListenRejected(error, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_REJECTED,
payload: { error },
meta: { type: metaType },
}
}
export function firebaseListenFulfilled(items, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_FULFILLED,
payload: { items },
meta: { type: metaType },
}
}
export function firebaseListenChildAdded(id, value, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_CHILD_ADDED,
payload: { id, value },
meta: { type: metaType },
}
}
export function firebaseListenChildChanged(id, value, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_CHILD_CHANGED,
payload: { id, value },
meta: { type: metaType },
}
}
export function firebaseListenChildRemoved(id, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_CHILD_REMOVED,
payload: { id },
meta: { type: metaType },
}
}
export function firebaseUpdateRequested(payload, metaType) {
return {
type: types.firebase.FIREBASE_UPDATE_REQUESTED,
payload,
meta: { type: metaType },
}
}
export function firebaseUpdateRejected(error, metaType) {
return {
type: types.firebase.FIREBASE_UPDATE_REJECTED,
payload: { error },
meta: { type: metaType },
}
}
export function firebaseUpdateFulfilled(metaType) {
return {
type: types.firebase.FIREBASE_UPDATE_FULFILLED,
payload: {},
meta: { type: metaType },
}
}
export function firebaseRemoveRequested(payload, metaType) {
return {
type: types.firebase.FIREBASE_REMOVE_REQUESTED,
payload,
meta: { type: metaType },
}
}
export function firebaseRemoveRejected(error, metaType) {
return {
type: types.firebase.FIREBASE_REMOVE_REJECTED,
payload: { error },
meta: { type: metaType },
}
}
export function firebaseRemoveFulfilled(metaType) {
return {
type: types.firebase.FIREBASE_REMOVE_FULFILLED,
payload: {},
meta: { type: metaType },
}
}
export function firebaseListenRemoved(clearItems, metaType) {
return {
type: types.firebase.FIREBASE_LISTEN_REMOVED,
payload: { clearItems },
meta: { type: metaType },
}
}
export function firebaseRemoveListenerRequested(clearItems, metaType) {
return {
type: types.firebase.FIREBASE_REMOVE_LISTENER_REQUESTED,
payload: { clearItems },
meta: { type: metaType },
}
}
export function firebaseRemoveAllListenersRequested() {
return {
type: types.firebase.FIREBASE_REMOVE_ALL_LISTENERS_REQUESTED,
payload: { clearItems: true },
}
}
export function listenToMessages() {
const ref = firebase.database().ref('messages')
return firebaseListenRequested(ref, metaTypes.messages)
}
export function listenToUserContacts(uid) {
const ref = firebase.database().ref(`users/${uid}/contacts`)
return firebaseListenRequested(ref, metaTypes.userContacts)
}
export function removeMessagesListenerRequested() {
return firebaseRemoveListenerRequested(false, metaTypes.messages)
}
export function removeUserContactsListenerRequested() {
return firebaseRemoveListenerRequested(false, metaTypes.userContacts)
}
export function updateUserContactsRequested(uid, contactId, name, phone) {
return firebaseUpdateRequested(
{ uid, contactId, name, phone },
metaTypes.userContacts
)
}
export function removeUserContactsRequested(uid, contactId) {
return firebaseRemoveRequested({ uid, contactId }, metaTypes.userContacts)
}