forked from lichess-org/lila
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeetup-notification.js
58 lines (55 loc) · 1.47 KB
/
meetup-notification.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
var sender = 'lichess';
var threadName = "Lichess meetup in London, November 24th";
var sent = 0;
db.user4.find({
'profile.location':'montreal',
enabled:true,
seenAt:{$gt:new Date(Date.now() - 1000 * 3600 * 24 * 30)}
}).forEach(user => {
if (db.notify.count({
notifies: user._id,
'content.type': 'privateMessage',
'content.thread.name': threadName
})) return;
var threadId = Math.random().toString(36).substring(2, 10);
db.notify.insert({
_id: Math.random().toString(36).substring(2, 10),
notifies: user._id,
content: {
type: 'privateMessage',
senderId: sender,
thread: {
id: threadId,
name: threadName
},
text: threadName
},
read: false,
createdAt: new Date()
});
print(user.username);
db.m_thread.insert({
_id: threadId,
"name": threadName,
"createdAt": new Date(),
"updatedAt": new Date(),
"posts": [
{
"id": Math.random().toString(36).substring(2, 10),
"text": "You are most welcome to join us!\n\nhttps://lichess.org/blog/W-nQzxYAAC8AaUUo/lichess-london-meetup-on-the-24th-november\n\nYou received this message because you connected from the UK, Ireland, France or Belgium.",
"isByCreator": true,
"isRead": false,
"createdAt": new Date()
}
],
"creatorId": sender,
"invitedId": user._id,
"visibleByUserIds": [
"lichess",
user._id
],
"mod": true
});
sent++;
});
print('Sent ' + sent);