Node.js based forum software built for the modern web
leaveRoom method, small fixes
barisusakli8fab270852df
diff --git a/public/src/app.js b/public/src/app.jsindex 10e192ba63..2f6e759609 100644--- a/public/src/app.js+++ b/public/src/app.js@@ -261,6 +261,13 @@ app.cacheBuster = null;});};+ app.newChat = function (touid) {+ if (!app.user.uid) {+ return app.alertError('[[error:not-logged-in]]');+ }++ };+var titleObj = {active: false,interval: undefined,diff --git a/src/controllers/accounts/chats.js b/src/controllers/accounts/chats.jsindex f0e3bcf8f7..30c73fcce1 100644--- a/src/controllers/accounts/chats.js+++ b/src/controllers/accounts/chats.js@@ -46,7 +46,7 @@ chatsController.get = function(req, res, callback) {since: 'recent',isNew: false}),- allowed: async.apply(messaging.canMessage, req.user.uid, req.params.roomid)+ allowed: async.apply(messaging.canMessageRoom, req.user.uid, req.params.roomid)}, next);}], function(err, data) {diff --git a/src/messaging.js b/src/messaging.jsindex 5cfbca1318..a71000854f 100644--- a/src/messaging.js+++ b/src/messaging.js@@ -23,8 +23,6 @@ var async = require('async'),require('./messaging/unread')(Messaging);require('./messaging/notifications')(Messaging);- Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser-var terms = {day: 86400000,week: 604800000,diff --git a/src/messaging/notifications.js b/src/messaging/notifications.jsindex b1b8564659..046c07c88e 100644--- a/src/messaging/notifications.js+++ b/src/messaging/notifications.js@@ -12,6 +12,8 @@ var sockets = require('../socket.io');module.exports = function(Messaging) {+ Messaging.notifyQueue = {}; // Only used to notify a user of a new chat message, see Messaging.notifyUser+Messaging.notifyUsersInRoom = function(fromUid, roomId, messageObj) {Messaging.getUidsInRoom(roomId, 0, -1, function(err, uids) {if (err) {diff --git a/src/messaging/rooms.js b/src/messaging/rooms.jsindex 73a9885562..c9612a9e75 100644--- a/src/messaging/rooms.js+++ b/src/messaging/rooms.js@@ -45,6 +45,17 @@ module.exports = function(Messaging) {], callback);};+ Messaging.leaveRoom = function(uid, roomId, callback) {+ async.waterfall([+ function (next) {+ db.sortedSetRemove('chat:room:' + roomId + ':uids', uid, next);+ },+ function (next) {+ db.sortedSetRemove('uid:' + uid + ':chat:rooms', roomId, next);+ }+ ], callback);+ };+Messaging.getUidsInRoom = function(roomId, start, stop, callback) {db.getSortedSetRange('chat:room:' + roomId + ':uids', start, stop, callback);};diff --git a/src/socket.io/modules.js b/src/socket.io/modules.jsindex bb0de7b268..c22f48fef0 100644--- a/src/socket.io/modules.js+++ b/src/socket.io/modules.js@@ -128,7 +128,7 @@ SocketModules.chats.delete = function(socket, data, callback) {};SocketModules.chats.canMessage = function(socket, roomId, callback) {- Messaging.canMessage(socket.uid, roomId, function(err, allowed) {+ Messaging.canMessageRoom(socket.uid, roomId, function(err, allowed) {callback(!allowed ? new Error('[[error:chat-restricted]]') : undefined);});};