-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathclose.js
More file actions
33 lines (26 loc) · 783 Bytes
/
Copy pathclose.js
File metadata and controls
33 lines (26 loc) · 783 Bytes
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
/** @module */
const CLOSE_COMMANDS = ['close', 'lock', 'thread']
function isClosePost (post) {
return post.command != null && CLOSE_COMMANDS.indexOf(post.command) !== -1
}
/**
* Allows moderators to close comment threads. Looks for the first comment by a
* moderator to issue the "/thread" command, and automatically deletes all
* non-moderator posts after it.
*/
export function attach (emitter, record) {
emitter.on('new', (post, state) => {
if (!post.isMod) {
state.get().then(s => {
if (s.closed) {
emitter.client.del(post.id).then(() => {
record('close-delete', { post })
})
}
})
} else if (isClosePost(post)) {
record('close', { post })
state.update({ closed: true })
}
})
}