2015-12-15 14:10:32 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var async = require('async');
|
|
|
|
|
var db = require('../database');
|
|
|
|
|
|
2016-10-13 11:43:39 +02:00
|
|
|
module.exports = function (Messaging) {
|
|
|
|
|
Messaging.deleteMessage = function (mid, roomId, callback) {
|
2015-12-15 14:10:32 +02:00
|
|
|
async.waterfall([
|
|
|
|
|
function (next) {
|
|
|
|
|
Messaging.getUidsInRoom(roomId, 0, -1, next);
|
|
|
|
|
},
|
|
|
|
|
function (uids, next) {
|
|
|
|
|
if (!uids.length) {
|
|
|
|
|
return next();
|
|
|
|
|
}
|
2016-10-13 11:43:39 +02:00
|
|
|
var keys = uids.map(function (uid) {
|
2017-08-21 16:39:24 -04:00
|
|
|
return 'uid:' + uid + ':chat:room:' + roomId + ':mids';
|
2015-12-15 14:10:32 +02:00
|
|
|
});
|
|
|
|
|
db.sortedSetsRemove(keys, roomId, next);
|
|
|
|
|
},
|
2016-10-13 11:43:39 +02:00
|
|
|
function (next) {
|
2015-12-15 14:10:32 +02:00
|
|
|
db.delete('message:' + mid, next);
|
2017-02-17 19:31:21 -07:00
|
|
|
},
|
2015-12-15 14:10:32 +02:00
|
|
|
], callback);
|
|
|
|
|
};
|
2017-02-18 02:30:48 -07:00
|
|
|
};
|