-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathdatastore.js
207 lines (201 loc) · 3.61 KB
/
datastore.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
let user = {
id: 0,
name: "Anish",
number: "+91 91231 40293",
pic: "images/asdsd12f34ASd231.png"
};
let contactList = [
{
id: 0,
name: "Anish",
number: "+91 91231 40293",
pic: "images/asdsd12f34ASd231.png",
lastSeen: "Apr 29 2018 17:58:02"
},
{
id: 1,
name: "Nitin",
number: "+91 98232 37261",
pic: "images/Ass09123asdj9dk0qw.jpg",
lastSeen: "Apr 28 2018 22:18:21"
},
{
id: 2,
name: "Sanjay",
number: "+91 72631 2937",
pic: "images/asd1232ASdas123a.png",
lastSeen: "Apr 28 2018 19:23:16"
},
{
id: 3,
name: "Suvro Mobile",
number: "+91 98232 63547",
pic: "images/Alsdk120asdj913jk.jpg",
lastSeen: "Apr 29 2018 11:16:42"
},
{
id: 4,
name: "Dee",
number: "+91 72781 38213",
pic: "images/dsaad212312aGEA12ew.png",
lastSeen: "Apr 27 2018 17:28:10"
}
];
let groupList = [
{
id: 1,
name: "Programmers",
members: [0, 1, 3],
pic: "images/0923102932_aPRkoW.jpg"
},
{
id: 2,
name: "Web Developers",
members: [0, 2],
pic: "images/1921231232_Ag1asE.png"
},
{
id: 3,
name: "notes",
members: [0],
pic: "images/8230192232_asdEWq2.png"
}
];
// message status - 0:sent, 1:delivered, 2:read
let messages = [
{
id: 0,
sender: 2,
body: "where are you, buddy?",
time: "April 25, 2018 13:21:03",
status: 2,
recvId: 0,
recvIsGroup: false
},
{
id: 1,
sender: 0,
body: "at home",
time: "April 25, 2018 13:22:03",
status: 2,
recvId: 2,
recvIsGroup: false
},
{
id: 2,
sender: 0,
body: "how you doin'?",
time: "April 25, 2018 18:15:23",
status: 2,
recvId: 3,
recvIsGroup: false
},
{
id: 3,
sender: 3,
body: "i'm fine...wat abt u?",
time: "April 25, 2018 21:05:11",
status: 2,
recvId: 0,
recvIsGroup: false
},
{
id: 4,
sender: 0,
body: "i'm good too",
time: "April 26, 2018 09:17:03",
status: 1,
recvId: 3,
recvIsGroup: false
},
{
id: 5,
sender: 3,
body: "anyone online?",
time: "April 27, 2018 18:20:11",
status: 0,
recvId: 1,
recvIsGroup: true
},
{
id: 6,
sender: 1,
body: "have you seen infinity war?",
time: "April 27, 2018 17:23:01",
status: 1,
recvId: 0,
recvIsGroup: false
},
{
id: 7,
sender: 0,
body: "are you going to the party tonight?",
time: "April 27, 2018 08:11:21",
status: 2,
recvId: 2,
recvIsGroup: false
},
{
id: 8,
sender: 2,
body: "no, i've some work to do..are you?",
time: "April 27, 2018 08:22:12",
status: 2,
recvId: 0,
recvIsGroup: false
},
{
id: 9,
sender: 0,
body: "yup",
time: "April 27, 2018 08:31:23",
status: 1,
recvId: 2,
recvIsGroup: false
},
{
id: 10,
sender: 0,
body: "if you go to the movie, then give me a call",
time: "April 27, 2018 22:41:55",
status: 2,
recvId: 4,
recvIsGroup: false
},
{
id: 11,
sender: 1,
body: "yeah, i'm online",
time: "April 28 2018 17:10:21",
status: 0,
recvId: 1,
recvIsGroup: true
}
];
let MessageUtils = {
getByGroupId: (groupId) => {
return messages.filter(msg => msg.recvIsGroup && msg.recvId === groupId);
},
getByContactId: (contactId) => {
return messages.filter(msg => {
return !msg.recvIsGroup && ((msg.sender === user.id && msg.recvId === contactId) || (msg.sender === contactId && msg.recvId === user.id));
});
},
getMessages: () => {
return messages;
},
changeStatusById: (options) => {
messages = messages.map((msg) => {
if (options.isGroup) {
if (msg.recvIsGroup && msg.recvId === options.id) msg.status = 2;
} else {
if (!msg.recvIsGroup && msg.sender === options.id && msg.recvId === user.id) msg.status = 2;
}
return msg;
});
},
addMessage: (msg) => {
msg.id = messages.length + 1;
messages.push(msg);
}
};