Merge remote-tracking branch 'origin'

v1.18.x
Julian Lam 12 years ago
commit 74c13ba299

@ -722,4 +722,15 @@ body .navbar .nodebb-inline-block {
max-width:200px;
max-height:60px;
}
}
.username-field {
.icon-circle {
font-size: 12px;
color: green;
}
.icon-circle-blank {
font-size: 12px;
color: red;
}
}

@ -56,6 +56,8 @@ var ajaxify = {};
callback();
}
app.process_page();
jQuery('#content, #footer').fadeIn(200);
}, url, template);

@ -277,6 +277,35 @@ var socket,
app.current_room = room;
};
app.process_page = function() {
function populate_online_users() {
var uids = [];
jQuery('.post-row').each(function() {
uids.push(this.getAttribute('data-uid'));
});
socket.emit('api:user.get_online_users', uids);
}
populate_online_users();
}
socket.on('api:user.get_online_users', function(users) {
jQuery('.username-field').each(function() {
var uid = jQuery(this).parents('li').attr('data-uid');
if (uid && jQuery.inArray(uid, users) !== -1) {
jQuery(this).prepend('<i class="icon-circle"></i>');
} else {
jQuery(this).prepend('<i class="icon-circle-blank"></i>');
}
});
});
jQuery('document').ready(function() {
app.enter_room('global');

@ -5,12 +5,16 @@
<div id="category_active_users"></div>
</ul>
</div>
<div class="alert alert-warning hide" id="category-no-topics">
<strong>There are no topics in this category.</strong><br />
Why don't you try posting one?
</div>
<div class="category row">
<div class="span9">
<ul id="topics-container">
<!-- BEGIN topics -->
<a href="../../topic/{topics.slug}"><li class="{topics.deleted-class}">
<a href="../../topic/{topics.slug}"><li class="category-item {topics.deleted-class}">
<div class="row-fluid">
<div class="span1 thread-rating hidden-phone hidden-tablet">
<span>
@ -90,6 +94,11 @@
'event:new_topic'
]);
if (jQuery('.category-item').length == 0) {
jQuery('.category.row').hide();
jQuery('#category-no-topics').show();
}
socket.on('event:new_topic', function(data) {
var html = templates.prepare(templates['category'].blocks['topics']).parse({ topics: [data] }),
topic = document.createElement('div'),

@ -12,7 +12,7 @@
<!-- BEGIN categories -->
<div class="span3">
<a href="category/{categories.slug}">
<h4>{categories.name} <span class="badge badge-important">3</span></h4>
<h4>{categories.name} <span class="badge {categories.badgeclass}">{categories.topic_count}</span></h4>
<!-- {categories.description} -->
<div class="category-icon {categories.blockclass}">
<i class="{categories.icon} icon-4x"></i>

@ -12,7 +12,7 @@
<!-- BEGIN main_posts -->
<li class="row main-post" data-pid="{main_posts.pid}" data-deleted="{main_posts.deleted}">
<li class="row post-row main-post" data-pid="{main_posts.pid}" data-uid="{main_posts.uid}" data-deleted="{main_posts.deleted}">
<div class="span12">
<div class="post-block">
<a class="main-avatar" href="/users/{main_posts.username}">
@ -37,7 +37,7 @@
<hr />
<small>
posted {main_posts.relativeTime} ago by <strong><a href="/users/{main_posts.username}">{main_posts.username}</a></strong>
posted {main_posts.relativeTime} ago by <strong><a href="/users/{main_posts.username}" class="username-field">{main_posts.username}</a></strong>
<span class="{main_posts.edited-class}"><i class="icon-edit" title="edited by {main_posts.editor} {main_posts.relativeEditTime} ago"></i></span>
</small>
@ -52,7 +52,7 @@
<!-- END main_posts -->
<!-- BEGIN posts -->
<li class="row" data-pid="{posts.pid}" data-uid="{posts.uid}" data-deleted="{posts.deleted}">
<li class="row post-row" data-pid="{posts.pid}" data-uid="{posts.uid}" data-deleted="{posts.deleted}">
<div class="span1 profile-image-block visible-desktop">
<!--<i class="icon-spinner icon-spin icon-2x pull-left"></i>-->
<a href="/users/{posts.username}">
@ -72,7 +72,7 @@
<div id="favs_{posts.pid}_{posts.uid}" class="favourite hidden-phone"><span class="post_rep_{posts.pid}">{posts.post_rep}</span><i class="{posts.fav_star_class}"></i></div>
<div class="post_reply"><i class="icon-reply"></i></div>
</span>
<img class="hidden-desktop" src="{posts.gravatar}?s=10" align="left" /> posted by <strong><a href="/users/{posts.username}">{posts.username}</a></strong> {posts.relativeTime} ago
<img class="hidden-desktop" src="{posts.gravatar}?s=10" align="left" /> posted by <strong><a class="username-field" href="/users/{posts.username}">{posts.username}</a></strong> {posts.relativeTime} ago
<span class="{posts.edited-class} hidden-phone">| last edited by <strong><a href="/users/{posts.editor}">{posts.editor}</a></strong> {posts.relativeEditTime} ago</span>
<span class="{posts.edited-class}"><i class="icon-edit visible-phone" title="edited by {posts.editor} {posts.relativeEditTime} ago"></i></span>
</div>
@ -272,6 +272,7 @@
}
});
$('.post-container').delegate('.edit', 'click', function(e) {
var pid = ($(this).attr('id') || $(this.parentNode).attr('id')).split('_')[1];
app.open_post_window('edit', "{topic_id}", "{topic_name}", pid);
@ -297,6 +298,7 @@
'event:topic_moved', 'event:post_edited', 'event:post_deleted', 'event:post_restored',
'api:posts.favourite'
]);
socket.on('api:get_users_in_room', function(users) {
var anonymous = users.anonymous,
usernames = users.usernames,
@ -337,6 +339,8 @@
.fadeIn('slow');
set_up_posts(uniqueid);
addCommasToNumbers();
});
socket.on('event:topic_deleted', function(data) {

@ -56,10 +56,10 @@ var RDB = require('./redis.js'),
// just a reminder to self that name + slugs are stored into topics data as well.
};
Categories.get = function(callback) {
Categories.get = function(callback, current_user) {
RDB.lrange('categories:cid', 0, -1, function(err, cids) {
RDB.handle(err);
Categories.get_category(cids, callback);
Categories.get_category(cids, callback, current_user);
});
}
@ -79,12 +79,29 @@ var RDB = require('./redis.js'),
});
}
Categories.get_category = function(cids, callback) {
Categories.hasReadCategories = function(cids, uid, callback) {
var batch = RDB.multi();
for (var i=0, ii=cids.length; i<ii; i++) {
batch.sismember('cid:' + cids[i] + ':read_by_uid', uid);
}
batch.exec(function(err, hasRead) {
callback(hasRead);
});
}
Categories.get_category = function(cids, callback, current_user) {
var name = [],
description = [],
icon = [],
blockclass = [],
slug = [];
slug = [],
topic_count = [],
has_read = {};
for (var i=0, ii=cids.length; i<ii; i++) {
name.push('cid:' + cids[i] + ':name');
@ -92,6 +109,7 @@ var RDB = require('./redis.js'),
icon.push('cid:' + cids[i] + ':icon');
blockclass.push('cid:' + cids[i] + ':blockclass');
slug.push('cid:' + cids[i] + ':slug');
topic_count.push('cid:' + cids[i] + ':topiccount');
}
if (cids.length > 0) {
@ -101,26 +119,39 @@ var RDB = require('./redis.js'),
.mget(icon)
.mget(blockclass)
.mget(slug)
.mget(topic_count)
.exec(function(err, replies) {
name = replies[0];
description = replies[1];
icon = replies[2];
blockclass = replies[3];
slug = replies[4];
topic_count = replies[5];
var categories = [];
for (var i=0, ii=cids.length; i<ii; i++) {
categories.push({
'name' : name[i],
'cid' : cids[i],
'slug' : slug[i],
'description' : description[i],
'blockclass' : blockclass[i],
'icon' : icon[i]
});
function generateCategories() {
var categories = [];
for (var i=0, ii=cids.length; i<ii; i++) {
categories.push({
'name' : name[i],
'cid' : cids[i],
'slug' : slug[i],
'description' : description[i],
'blockclass' : blockclass[i],
'icon' : icon[i],
'badgeclass' : (!topic_count[i] || (has_read[i] && current_user !=0)) ? '' : 'badge-important',
'topic_count' : topic_count[i] || 0
});
}
callback({'categories': categories});
}
callback({'categories': categories});
Categories.hasReadCategories(cids, current_user, function(read_data) {
has_read = read_data;
generateCategories();
});
});
} else callback({'categories' : []});
};

@ -196,7 +196,7 @@ marked.setOptions({
}
Posts.get_cid_by_pid = function(pid, callback) {
Posts.get_tid(pid, function(tid) {
Posts.get_tid_by_pid(pid, function(tid) {
if (tid) topics.get_cid_by_tid(tid, function(cid) {
if (cid) callback(cid);
else callback(false);
@ -220,6 +220,9 @@ marked.setOptions({
RDB.rpush('tid:' + tid + ':posts', pid);
RDB.del('tid:' + tid + ':read_by_uid'); // let everybody know there is an unread post
Posts.get_cid_by_pid(pid, function(cid) {
RDB.del('cid:' + cid + ':read_by_uid');
});
// Re-add the poster, so he/she does not get an "unread" flag on this topic
topics.markAsRead(tid, uid);

@ -3,7 +3,8 @@
ERROR_LOGS = true,
redis = require('redis'),
config = require('../config.js');
config = require('../config.js'),
utils = require('./utils.js');
RedisDB.exports = redis.createClient(config.redis.port, config.redis.host, config.redis.options);
@ -22,4 +23,18 @@
}
}
/*
* A possibly more efficient way of doing multiple sismember calls
*/
RedisDB.exports.sismembers = function(key, needles, callback) {
var tempkey = key + ':temp:' + utils.generateUUID();
RedisDB.exports.sadd(tempkey, needles, function() {
RedisDB.exports.sinter(key, tempkey, function(err, data) {
RedisDB.exports.del(tempkey);
callback(err, data);
});
});
};
}(module));

@ -72,9 +72,19 @@ marked.setOptions({
callback(false);
return;
}
active_usernames = replies[1];
var topics = [];
if (tids.length == 0) {
callback({
'category_name' : category_id ? category_name : 'Recent',
'show_topic_button' : category_id ? 'show' : 'hidden',
'category_id': category_id || 0,
'topics' : []
});
}
title = replies[2];
uid = replies[3];
timestamp = replies[4];
@ -252,7 +262,11 @@ marked.setOptions({
}
Topics.markAsRead = function(tid, uid) {
// there is an issue with this fn. if you read a topic that is previously read you will mark the category as read anyways - there is no check
RDB.sadd('tid:' + tid + ':read_by_uid', uid);
Topics.get_cid_by_tid(tid, function(cid) {
RDB.sadd('cid:' + cid + ':read_by_uid', uid);
});
}
Topics.hasReadTopics = function(tids, uid, callback) {
@ -391,6 +405,9 @@ marked.setOptions({
timeout: 2000
});
// let everyone know that there is an unread topic in this category
RDB.del('cid:' + category_id + ':read_by_uid');
// in future it may be possible to add topics to several categories, so leaving the door open here.
RDB.sadd('categories:' + category_id + ':tid', tid);
RDB.set('tid:' + tid + ':cid', category_id);
@ -399,6 +416,7 @@ marked.setOptions({
RDB.set('tid:' + tid + ':category_slug', data.categories[0].slug);
});
RDB.incr('cid:' + category_id + ':topiccount');
});
};

@ -660,7 +660,22 @@ var config = require('../config.js'),
}
});
}
}
};
User.get_online_users = function(socket, uids) {
RDB.sismembers('users:online', uids, function(err, data) {
socket.emit('api:user.get_online_users', data);
});
};
User.go_online = function(uid) {
RDB.sadd('users:online', uid);
};
User.go_offline = function(uid) {
RDB.srem('users:online', uid);
};
User.active = {
get_record : function(socket) {

@ -116,7 +116,7 @@ var express = require('express'),
case 'home' :
categories.get(function(data) {
res.send(JSON.stringify(data));
});
}, (req.user) ? req.user.uid : 0);
break;
case 'login' :
var data = {},

@ -48,6 +48,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
var hs = socket.handshake;
var uid = users[hs.sessionID];
user.go_online(uid);
/*process.on('uncaughtException', function(err) {
@ -59,6 +60,7 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
socket.emit('event:connect', {status: 1});
socket.on('disconnect', function() {
user.go_offline(uid);
delete users[hs.sessionID];
});
@ -154,6 +156,10 @@ var SocketIO = require('socket.io').listen(global.server,{log:false}),
user.reset.commit(socket, data.code, data.password);
});
socket.on('api:user.get_online_users', function(data) {
user.get_online_users(socket, data);
});
socket.on('api:topics.post', function(data) {
topics.post(socket, uid, data.title, data.content, data.category_id);
});

Loading…
Cancel
Save