mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-31 23:28:34 -04:00
Update to support delete note
This commit is contained in:
parent
68457ed3a2
commit
12d5ed43a7
5 changed files with 77 additions and 1 deletions
lib
|
@ -796,6 +796,35 @@ function connection(socket) {
|
|||
}
|
||||
});
|
||||
|
||||
// delete a note
|
||||
socket.on('delete', function () {
|
||||
//need login to do more actions
|
||||
if (socket.request.user && socket.request.user.logged_in) {
|
||||
var noteId = socket.noteId;
|
||||
if (!noteId || !notes[noteId]) return;
|
||||
var note = notes[noteId];
|
||||
//Only owner can delete note
|
||||
if (note.owner && note.owner == socket.request.user.id) {
|
||||
models.Note.destroy({
|
||||
where: {
|
||||
id: noteId
|
||||
}
|
||||
}).then(function (count) {
|
||||
if (!count) return;
|
||||
for (var i = 0, l = note.socks.length; i < l; i++) {
|
||||
var sock = note.socks[i];
|
||||
if (typeof sock !== 'undefined' && sock) {
|
||||
sock.emit('delete');
|
||||
return sock.disconnect(true);
|
||||
}
|
||||
}
|
||||
}).catch(function (err) {
|
||||
return logger.error('delete note failed: ' + err);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//reveiced when user logout or changed
|
||||
socket.on('user changed', function () {
|
||||
logger.info('user changed');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue