mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 01:45:47 +01:00
Chat message soft deletion -- closes #6181
Squashed commit of the following: commit f84c06bdcc45f24ef7ffde6a8f33b48d8f97fc36 Author: Julian Lam <julian@nodebb.org> Date: Mon Dec 18 14:42:47 2017 -0500 added restore handler for chat messages commit 725cd370c6ea1e8f4a28298350f3dc024d4e668e Author: Julian Lam <julian@nodebb.org> Date: Mon Dec 18 14:23:52 2017 -0500 backend logic and testing complete for deletion and restoration of chat messages commit 072da758319cc93fa4c6f8bc0d672a1b716dc06e Author: Julian Lam <julian@nodebb.org> Date: Mon Dec 18 13:52:35 2017 -0500 changing message delete logic to not remove mids, but to filter when retrieving commit 68bf373305ab82737658a7c31dc5549af4d6d69f Author: Julian Lam <julian@nodebb.org> Date: Mon Dec 18 12:37:58 2017 -0500 logic to handle deletion of a deleted chat message -- added some failing tests commit 6899d0d234fa752e227188aa69cfcabd0d0500cc Author: Julian Lam <julian@nodebb.org> Date: Mon Dec 18 11:35:36 2017 -0500 chat message deletion logic
This commit is contained in:
@@ -1,25 +1,30 @@
|
||||
'use strict';
|
||||
|
||||
var async = require('async');
|
||||
var db = require('../database');
|
||||
|
||||
module.exports = function (Messaging) {
|
||||
Messaging.deleteMessage = function (mid, roomId, callback) {
|
||||
async.waterfall([
|
||||
function (next) {
|
||||
Messaging.getUidsInRoom(roomId, 0, -1, next);
|
||||
},
|
||||
function (uids, next) {
|
||||
if (!uids.length) {
|
||||
return next();
|
||||
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
||||
function (deleted, next) {
|
||||
if (parseInt(deleted, 10)) {
|
||||
return next(new Error('[[error:chat-deleted-already]]'));
|
||||
}
|
||||
var keys = uids.map(function (uid) {
|
||||
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
||||
});
|
||||
db.sortedSetsRemove(keys, mid, next);
|
||||
|
||||
Messaging.setMessageField(mid, 'deleted', 1, next);
|
||||
},
|
||||
function (next) {
|
||||
db.delete('message:' + mid, next);
|
||||
], callback);
|
||||
};
|
||||
|
||||
Messaging.restoreMessage = function (mid, roomId, callback) {
|
||||
async.waterfall([
|
||||
async.apply(Messaging.getMessageField, mid, 'deleted'),
|
||||
function (deleted, next) {
|
||||
if (!parseInt(deleted, 10)) {
|
||||
return next(new Error('[[error:chat-restored-already]]'));
|
||||
}
|
||||
|
||||
Messaging.setMessageField(mid, 'deleted', 0, next);
|
||||
},
|
||||
], callback);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user