removed commented out stuff removed topics.enter

v1.18.x
barisusakli 9 years ago
parent 491a6d0234
commit 1ecf27417a

@ -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');

@ -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);

@ -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) {

@ -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);
}

@ -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);
};

@ -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<socketids.length; ++i) {
var socketRooms = rooms.clientRooms(socketids[i]);
if (Array.isArray(socketRooms)) {
socketRooms.forEach(function(roomName) {
if (roomName.startsWith('uid_')) {
var uid = roomName.split('_')[1];
if (uids.indexOf(uid) === -1) {
uids.push(uid);
}
}
});
}
}
callback(null, uids);
return uids;
callback(null, []);
};

@ -52,14 +52,6 @@ SocketMeta.rooms.enter = function(socket, data, callback) {
if (data.enter) {
rooms.enter(socket, data.enter);
socket.currentRoom = data.enter;
// if (data.enter.indexOf('topic') !== -1) {
// data.uid = socket.uid;
// data.picture = validator.escape(data.picture);
// data.username = validator.escape(data.username);
// data.userslug = validator.escape(data.userslug);
// websockets.in(data.enter).emit('event:user_enter', data);
// }
}
callback();
};
@ -75,9 +67,6 @@ SocketMeta.rooms.leaveCurrent = function(socket, data, callback) {
function leaveCurrentRoom(socket) {
if (socket.currentRoom) {
rooms.leave(socket, socket.currentRoom);
// if (socket.currentRoom.indexOf('topic') !== -1) {
// websockets.in(socket.currentRoom).emit('event:user_leave', socket.uid);
// }
socket.currentRoom = '';
}
}

@ -63,15 +63,14 @@ module.exports = function(SocketPosts) {
async.parallel({
admins: async.apply(groups.getMembers, 'administrators', 0, -1),
moderators: async.apply(groups.getMembers, 'cid:' + result.topic.cid + ':privileges:mods', 0, -1),
uidsInTopic: async.apply(websockets.getUidsInRoom, 'topic_' + result.topic.tid)
moderators: async.apply(groups.getMembers, 'cid:' + result.topic.cid + ':privileges:mods', 0, -1)
}, function(err, results) {
if (err) {
return winston.error(err);
}
var uids = results.uidsInTopic.filter(function(uid) {
return (results.admins.indexOf(uid) !== -1 || results.moderators.indexOf(uid) !== -1) && parseInt(uid, 10) !== socket.uid;
var uids = results.admins.concat(results.moderators).filter(function(uid, index, array) {
return uid && array.indexOf(uid) === index;
});
uids.forEach(function(uid) {

@ -74,22 +74,6 @@ SocketTopics.post = function(socket, data, callback) {
});
};
SocketTopics.enter = function(socket, tid, callback) {
if (!parseInt(tid, 10) || !socket.uid) {
return;
}
async.parallel({
markAsRead: function(next) {
SocketTopics.markAsRead(socket, [tid], next);
},
users: function(next) {
websockets.getUsersInRoom(socket.uid, 'topic_' + tid, 0, 9, next);
}
}, function(err, result) {
callback(err, result ? result.users : null);
});
};
SocketTopics.postcount = function(socket, tid, callback) {
topics.getTopicField(tid, 'postcount', callback);
};

@ -161,52 +161,45 @@ module.exports = function(Topics) {
return callback();
}
async.parallel({
topicScores: function(next) {
db.sortedSetScores('topics:recent', tids, next);
async.waterfall([
function (next) {
async.parallel({
topicScores: async.apply(db.sortedSetScores, 'topics:recent', tids),
userScores: async.apply(db.sortedSetScores, 'uid:' + uid + ':tids_read', tids)
}, next);
},
userScores: function(next) {
db.sortedSetScores('uid:' + uid + ':tids_read', tids, next);
}
}, function(err, results) {
if (err) {
return callback(err);
}
tids = tids.filter(function(tid, index) {
return results.topicScores[index] && (!results.userScores[index] || results.userScores[index] < results.topicScores[index]);
});
if (!tids.length) {
return callback();
}
var now = Date.now();
var scores = tids.map(function() {
return now;
});
function (results, next) {
tids = tids.filter(function(tid, index) {
return results.topicScores[index] && (!results.userScores[index] || results.userScores[index] < results.topicScores[index]);
});
async.parallel({
markRead: function(next) {
db.sortedSetAdd('uid:' + uid + ':tids_read', scores, tids, next);
},
topicData: function(next) {
Topics.getTopicsFields(tids, ['cid'], next);
}
}, function(err, results) {
if (err) {
return callback(err);
if (!tids.length) {
return callback();
}
var now = Date.now();
var scores = tids.map(function() {
return now;
});
async.parallel({
markRead: async.apply(db.sortedSetAdd, 'uid:' + uid + ':tids_read', scores, tids),
topicData: async.apply( Topics.getTopicsFields, tids, ['cid'])
}, next);
},
function (results, next) {
var cids = results.topicData.map(function(topic) {
return topic && topic.cid;
}).filter(function(topic, index, array) {
return topic && array.indexOf(topic) === index;
});
categories.markAsRead(cids, uid, callback);
});
});
categories.markAsRead(cids, uid, next);
},
function (next) {
next(null, true);
}
], callback);
};
Topics.markTopicNotificationsRead = function(tid, uid) {

Loading…
Cancel
Save