-
Notifications
You must be signed in to change notification settings - Fork 0
/
meetings.js
84 lines (76 loc) · 3.18 KB
/
meetings.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
// @TODO: Change this file to be dynamic based on an argument
const data = require('./exports-temp/2019-04-18.json');
const usersExport = require('./exports-temp/users.json');
// Load all users into memory.
const users = {};
const contributors = {};
usersExport.forEach(user => {
users[user.id] = user.profile.display_name_normalized ? user.profile.display_name_normalized : user.profile.real_name_normalized;
});
// Load all messages into memory.
const messages = {};
data.forEach(message => {
if (message.type === 'message') {
let parsedMessage = message;
parsedMessage.text = parsedMessage.text.replace(/<@(U.+?)>/g, (match, p1) => {
return `@${users[p1]}`;
});
parsedMessage.text = parsedMessage.text.replace(':zero:', '0️⃣');
parsedMessage.text = parsedMessage.text.replace(':one:', '1️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':two:', '2️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':three:', '3️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':four:', '4️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':five:', '5️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':six:', '6️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':seven:', '7️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':eight:', '8️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':nine:', '9️⃣ ');
parsedMessage.text = parsedMessage.text.replace(':ten:', '🔟 ');
messages[message.ts] = parsedMessage;
}
});
// Reconstruct threads.
let meetingStart = 0;
let moderator = '';
let threads = data
.filter(message => message.type === 'message')
.map((message, i) => {
let reconstructedMessage = message;
if (message.replies && message.replies.length) {
reconstructedMessage.replies = message.replies
.filter(reply => messages[reply.ts])
.map(reply => {
const replyMessage = messages[reply.ts];
replyMessage.text = `<td>${users[reply.user]}</td><td>${replyMessage.text}</td>\n`;
// Contributors
if (!message.text.includes('0️⃣')) {
contributors[reply.user] = users[reply.user];
}
return replyMessage;
});
}
if (message.text.includes('Inclusion meeting!')) {
meetingStart = i;
moderator = users[message.user];
}
return reconstructedMessage;
})
.filter(message => !message.parent_user_id);
//threads = threads.slice(meetingStart);
if (!moderator.length) {
console.log('No meeting found!');
}
else {
let output = `<h3>Moderated By: ${moderator}</h3>\n`;
threads.forEach(thread => {
output += `<h2>${thread.text}</h2>\n`;
if (thread.replies && thread.replies.length) {
output += '<table>\n';
thread.replies.forEach(reply => {
output += `<tr>${reply.text}</tr>\n`;
});
output += '</table>\n';
}
});
console.log(output, '\n\n\n', Object.keys(contributors).map(id => users[id]));
}