Skip to content

Node.js based forum software built for the modern web

added timestamp to teaser, continuing work on recent replies block

psychobunny8c2b6cda6941
diff --git a/public/css/style.less b/public/css/style.less
index 6a93c9c4de..ad98ce009b 100644
--- a/public/css/style.less
+++ b/public/css/style.less
@@ -278,7 +278,53 @@ footer.footer {
width: 70%;
margin-left: 10px;
overflow: hidden;
- height: 50px;
+ height: 32px;
+ }
+ span {
+ display: block;
+ float: left;
+ width: 70%;
+ margin-left: 10px;
+ overflow: hidden;
+ height: 16px;
+ margin-top: -10px;
+ color: #666;
+ }
+ }
+ }
+
+ .recent-replies {
+ overflow-y: auto;
+ overflow-x: hidden;
+
+ ul {
+ width: 100%;
+ height: 50px;
+ line-height: 16px;
+ margin-left: 1px;
+ padding: 5px;
+
+ img {
+ display: block;
+ float: left;
+ }
+ p {
+ display: block;
+ float: left;
+ width: 70%;
+ margin-left: 10px;
+ overflow: hidden;
+ height: 32px;
+ }
+ span {
+ display: block;
+ float: left;
+ width: 70%;
+ margin-left: 10px;
+ overflow: hidden;
+ height: 16px;
+ margin-top: -10px;
+ color: #666;
}
}
}
diff --git a/public/templates/category.tpl b/public/templates/category.tpl
index ecec8a2688..846f1895b1 100644
--- a/public/templates/category.tpl
+++ b/public/templates/category.tpl
@@ -27,6 +27,7 @@
<div class="pull-right">
<img style="width: 48px; height: 48px; /*temporary*/" src="/graph/users/{topics.teaser_username}/picture" />
<p><strong>{topics.teaser_username}</strong>: {topics.teaser_text}</p>
+ <span>posted {topics.teaser_timestamp} ago</span>
</div>
</div>
<div>
@@ -48,7 +49,7 @@
<div class="block-header">
Recent Replies
</div>
- <div class="block-content" id="category_recent_replies">
+ <div class="block-content recent-replies" id="category_recent_replies">
</div>
</div>
@@ -132,8 +133,25 @@
socket.emit('api:categories.getRecentReplies', cid);
socket.on('api:categories.getRecentReplies', function(replies) {
- console.log(replies);
- jQuery('#category_recent_replies')
+ var users = replies.users,
+ posts = replies.posts,
+ recent_replies = document.getElementById('category_recent_replies');
+
+ recent_replies.innerHTML = '';
+ for (var i=0, ii=posts.pids.length; i<ii; i++) {
+ var a = document.createElement('a'),
+ ul = document.createElement('ul'),
+ username = users[posts.uid[i]].username,
+ picture = users[posts.uid[i]].picture;
+
+ //temp until design finalized
+ ul.innerHTML = '<li><img title="' + username + '" style="width: 48px; height: 48px; /*temporary*/" src="' + picture + '" class="" />'
+ + '<p><strong>' + username + '</strong>: ' + posts.content[i] + '</p><span>posted ' + utils.relativeTime(posts.timestamp[i]) + ' ago</span></li>';
+
+ a.appendChild(ul);
+ recent_replies.appendChild(a);
+ }
+
});
})();
diff --git a/src/categories.js b/src/categories.js
index 3d8014aaec..0e324dc250 100644
--- a/src/categories.js
+++ b/src/categories.js
@@ -180,7 +180,8 @@ var RDB = require('./redis.js'),
'pin-icon': pinned[i] === '1' ? 'icon-pushpin' : 'none',
'badgeclass' : (hasReadTopics[i] && current_user !=0) ? '' : 'badge-important',
'teaser_text': teaserInfo[i].text,
- 'teaser_username': teaserInfo[i].username
+ 'teaser_username': teaserInfo[i].username,
+ 'teaser_timestamp': utils.relativeTime(teaserInfo[i].timestamp)
});
}
}
@@ -260,8 +261,10 @@ var RDB = require('./redis.js'),
}
Categories.getRecentReplies = function(cid, callback) {
- RDB.zrange('categories:recent_posts:cid:' + cid, 0, -1, function(err, replies) {
- callback(replies);
+ RDB.zrange('categories:recent_posts:cid:' + cid, 0, -1, function(err, pids) {
+ posts.getPostSummaryByPids(pids, function(posts) {
+ callback(posts);
+ });
});
}
diff --git a/src/posts.js b/src/posts.js
index 07c9e1884c..58bdce5d36 100644
--- a/src/posts.js
+++ b/src/posts.js
@@ -33,10 +33,36 @@ marked.setOptions({
});
}
- // todo, getPostsByPids has duplicated stuff, have that call this fn.
+ // todo, getPostsByPids has duplicated stuff, have that call this fn - after userinfo calls are pulled out.
Posts.getPostSummaryByPids = function(pids, callback) {
var content = [], uid = [], timestamp = [];
+ for (var i=0, ii=pids.length; i<ii; i++) {
+ content.push('pid:' + pids[i] + ':content');
+ uid.push('pid:' + pids[i] + ':uid');
+ timestamp.push('pid:' + pids[i] + ':timestamp');
+ }
+ RDB.multi()
+ .mget(content)
+ .mget(uid)
+ .mget(timestamp)
+ .exec(function(err, replies) {
+ post_data = {
+ pids: pids,
+ content: replies[0],
+ uid: replies[1],
+ timestamp: replies[2]
+ }
+
+ // below, to be deprecated
+ user.getMultipleUserFields(post_data.uid, ['username','reputation','picture'], function(user_details) {
+ callback({
+ users: user_details,
+ posts: post_data
+ });
+ });
+ // above, to be deprecated
+ });
};
Posts.getPostsByPids = function(pids, current_user, callback) {
@@ -157,12 +183,12 @@ 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');
+ RDB.zadd('categories:recent_posts:cid:' + cid, (new Date()).getTime(), pid);
});
- RDB.zadd('topics:recent_posts:tid:' + tid, (new Date()).getTime(), pid);
-
// Re-add the poster, so he/she does not get an "unread" flag on this topic
topics.markAsRead(tid, uid);
// this will duplicate once we enter the thread, which is where we should be going
diff --git a/src/topics.js b/src/topics.js
index fe56df07dc..bed9ac2416 100644
--- a/src/topics.js
+++ b/src/topics.js
@@ -257,15 +257,18 @@ marked.setOptions({
if (pid !== null) {
RDB.mget([
'pid:' + pid + ':content',
- 'pid:' + pid + ':uid'
+ 'pid:' + pid + ':uid',
+ 'pid:' + pid + ':timestamp'
], function(err, content) {
user.getUserField(content[1], 'username', function(username) {
- var stripped = content[0];
+ var stripped = content[0],
+ timestamp = content[2];
if(content[0])
stripped = utils.strip_tags(marked(content[0]));
callback({
"text": stripped,
- "username": username
+ "username": username,
+ "timestamp" : timestamp
});
});
});