forked from marcelklehr/ep_push2delete
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
51 lines (46 loc) · 1.34 KB
/
index.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
var eejs = require('ep_etherpad-lite/node/eejs')
/*
* Handle incoming delete requests from clients
*/
exports.handleMessage = function(hook_name, context, callback){
var Pad = require('ep_etherpad-lite/node/db/Pad.js').Pad
// Firstly ignore any request that aren't about chat
var isDeleteRequest = false;
if(context) {
if(context.message && context.message){
if(context.message.type === 'COLLABROOM'){
if(context.message.data){
if(context.message.data.type){
if(context.message.data.type === 'ep_push2delete'){
isDeleteRequest = true;
}
}
}
}
}
}
if(!isDeleteRequest){
callback(false);
return false;
}
console.log('DELETION REQUEST!')
var packet = context.message.data;
/***
What's available in a packet?
* action -- The action IE chatPosition
* padId -- The padId of the pad both authors are on
***/
if(packet.action === 'deletePad'){
var pad = new Pad(packet.padId)
pad.remove(function(er) {
if(er) console.warn('ep_push2delete', er)
callback([null]);
})
}
}
exports.eejsBlock_editbarMenuRight = function(hook_name, args, cb) {
if(!args.renderContext.req.url.match(/^\/(p\/r\..{16})/)) {
args.content = eejs.require('ep_push2delete/templates/delete_button.ejs') + args.content;
}
cb();
};