all files / src/messaging/ delete.js

33.33% Statements 4/12
0% Branches 0/2
16.67% Functions 1/6
33.33% Lines 4/12
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                                             
'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();
				}
				var keys = uids.map(function(uid) {
					return 'uid:' + uid + ':chat:room:' + roomId + 'mids';
				});
				db.sortedSetsRemove(keys, roomId, next);
			},
			function(next) {
				db.delete('message:' + mid, next);
			}
		], callback);
	};
};