From 1ecf27417a4516554b37f0006a90053ee77483d4 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Thu, 5 Nov 2015 11:53:17 -0500 Subject: [PATCH] removed commented out stuff removed topics.enter --- public/src/client/topic.js | 10 ----- src/controllers/topics.js | 12 ++++++ src/controllers/users.js | 78 ------------------------------------- src/routes/index.js | 1 - src/socket.io/categories.js | 5 --- src/socket.io/index.js | 69 ++------------------------------ src/socket.io/meta.js | 11 ------ src/socket.io/posts/edit.js | 7 ++-- src/socket.io/topics.js | 16 -------- src/topics/unread.js | 65 ++++++++++++++----------------- 10 files changed, 47 insertions(+), 227 deletions(-) diff --git a/public/src/client/topic.js b/public/src/client/topic.js index c216943e32..adf4eb0d59 100644 --- a/public/src/client/topic.js +++ b/public/src/client/topic.js @@ -70,16 +70,6 @@ define('forum/topic', [ $(window).on('scroll', updateTopicTitle); - - if (app.user.uid) { - socket.emit('topics.enter', tid, function(err, data) { - if (err) { - return app.alertError(err.message); - } - browsing.onUpdateUsersInRoom(data); - }); - } - handleTopicSearch(); $(window).trigger('action:topic.loaded'); diff --git a/src/controllers/topics.js b/src/controllers/topics.js index 6dbbb79ec5..ab946dab33 100644 --- a/src/controllers/topics.js +++ b/src/controllers/topics.js @@ -265,6 +265,18 @@ topicsController.get = function(req, res, callback) { topics.increaseViewCount(tid); + if (req.uid) { + topics.markAsRead([tid], req.uid, function(err, markedRead) { + if (err) { + return callback(err); + } + if (markedRead) { + topics.pushUnreadCount(req.uid); + topics.markTopicNotificationsRead(tid, req.uid); + } + }); + } + plugins.fireHook('filter:topic.build', {req: req, res: res, templateData: data}, function(err, data) { if (err) { return callback(err); diff --git a/src/controllers/users.js b/src/controllers/users.js index 0c8e03f2c0..0087232255 100644 --- a/src/controllers/users.js +++ b/src/controllers/users.js @@ -149,84 +149,6 @@ usersController.getUsersForSearch = function(req, res, next) { }); }; -usersController.getMap = function(req, res, next) { - var socketIO = require('../socket.io'); - var rooms = require('../socket.io/rooms'); - - var roomNames = ['user_list', 'categories', 'unread_topics', 'recent_topics', 'popular_topics', 'tags']; - var links = { - user_list: '/users', - categories: '/categories', - unread_topics: '/unread', - recent_topics: '/recent', - popular_topics: '/popular', - tags: '/tags' - }; - - var keys = Object.keys(rooms.roomClients()); - - keys = keys.filter(function(key) { - return key.startsWith('topic_') || key.startsWith('category_'); - }); - - roomNames = roomNames.concat(keys); - - async.map(roomNames, function(roomName, next) { - socketIO.getUsersInRoom(0, roomName, 0, 39, function(err, data) { - if (err) { - return next(err); - } - - if (roomName.startsWith('category_')) { - var cid = roomName.split('_')[1]; - categories.getCategoryFields(cid, ['slug', 'name'], function(err, categoryData) { - if (err) { - return next(err); - } - data.room = validator.escape(categoryData.name); - data.link = '/category/' + categoryData.slug; - data.core = false; - next(null, data); - }); - } else if (roomName.startsWith('topic_')) { - var tid = roomName.split('_')[1]; - topics.getTopicFields(tid, ['slug', 'title'], function(err, topicData) { - if (err) { - return next(err); - } - data.room = validator.escape(topicData.title); - data.link = '/topic/' + topicData.slug; - data.core = false; - next(null, data); - }); - } else { - data.core = true; - next(null, data); - } - }); - }, function(err, data) { - if (err) { - return next(err); - } - data.sort(function(a, b) { - return b.users.length - a.users.length; - }); - - data.forEach(function(room) { - if (!room.link) { - room.link = links[room.room]; - } - }); - - res.render('usersMap', { - rooms: data, - 'reputation:disabled': parseInt(meta.config['reputation:disabled'], 10) === 1, - title: '[[pages:users/map]]', - breadcrumbs: helpers.buildBreadcrumbs([{text: '[[global:users]]', url: '/users'}, {text: '[[global:map]]'}]) - }); - }); -}; - function render(req, res, data, next) { plugins.fireHook('filter:users.build', {req: req, res: res, templateData: data}, function(err, data) { if (err) { diff --git a/src/routes/index.js b/src/routes/index.js index f5f57f688b..0dfa0303ba 100644 --- a/src/routes/index.js +++ b/src/routes/index.js @@ -62,7 +62,6 @@ function userRoutes(app, middleware, controllers) { setupPageRoute(app, '/users/sort-posts', middleware, middlewares, controllers.users.getUsersSortedByPosts); setupPageRoute(app, '/users/sort-reputation', middleware, middlewares, controllers.users.getUsersSortedByReputation); setupPageRoute(app, '/users/search', middleware, middlewares, controllers.users.getUsersForSearch); - setupPageRoute(app, '/users/map', middleware, middlewares, controllers.users.getMap); } diff --git a/src/socket.io/categories.js b/src/socket.io/categories.js index d43d0c8171..967f51afd1 100644 --- a/src/socket.io/categories.js +++ b/src/socket.io/categories.js @@ -137,11 +137,6 @@ SocketCategories.getTopicCount = function(socket, cid, callback) { categories.getCategoryField(cid, 'topic_count', callback); }; -SocketCategories.getUsersInCategory = function(socket, cid, callback) { - var uids = websockets.getUidsInRoom('category_' + cid); - user.getUsersFields(uids, ['uid', 'userslug', 'username', 'picture'], callback); -}; - SocketCategories.getCategoriesByPrivilege = function(socket, privilege, callback) { categories.getCategoriesByPrivilege('categories:cid', socket.uid, privilege, callback); }; diff --git a/src/socket.io/index.js b/src/socket.io/index.js index 6594e201c4..a4f2500d7a 100644 --- a/src/socket.io/index.js +++ b/src/socket.io/index.js @@ -86,13 +86,6 @@ function onDisconnect(socket, data) { if (socketCount <= 1) { socket.broadcast.emit('event:user_status_change', {uid: socket.uid, status: 'offline'}); } - - // see https://github.com/Automattic/socket.io/issues/1814 - // data.rooms.forEach(function(roomName) { - // if (roomName.startsWith('topic')) { - // io.in(roomName).emit('event:user_leave', socket.uid); - // } - // }); } rooms.leaveAll(socket, data.rooms); } @@ -264,6 +257,7 @@ Sockets.isUsersOnline = function(uids, callback) { }; Sockets.getUsersInRoom = function (uid, roomName, start, stop, callback) { + winston.warn('[deprecated] Sockets.getUsersInRoom') callback(null, { users: [], room: roomName, @@ -271,69 +265,12 @@ Sockets.getUsersInRoom = function (uid, roomName, start, stop, callback) { hidden: 0 }); return; - - if (!roomName) { - return; - } - - var uids = Sockets.getUidsInRoom(roomName); - var total = uids.length; - if (stop !== -1) { - uids = uids.slice(start, stop); - } - - if (uid && uids.indexOf(uid.toString()) === -1) { - uids = [uid].concat(uids); - } - - if (!uids.length) { - return callback(null, {users: [], total: 0 , room: roomName}); - } - user.getUsersFields(uids, ['uid', 'username', 'userslug', 'picture', 'status'], function(err, users) { - if (err) { - return callback(err); - } - - users = users.filter(function(user) { - return user && user.status !== 'offline'; - }); - - callback(null, { - users: users, - room: roomName, - total: users.length ? total : 0, - hidden: Math.max(0, total - uids.length) - }); - }); }; Sockets.getUidsInRoom = function(roomName, callback) { + winston.warn('[deprecated] Sockets.getUidsInRoom') callback = callback || function() {}; - - var uids = []; - - var socketids = rooms.clients(roomName); - if (!Array.isArray(socketids) || !socketids.length) { - callback(null, []); - return []; - } - - for(var i=0; i