From 8c2b6cda69415ea85f6342b38d105f374b4f8565 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 24 May 2013 14:34:55 -0400 Subject: [PATCH] added timestamp to teaser, continuing work on recent replies block --- public/css/style.less | 48 ++++++++++++++++++++++++++++++++++- public/templates/category.tpl | 24 +++++++++++++++--- src/categories.js | 9 ++++--- src/posts.js | 32 ++++++++++++++++++++--- src/topics.js | 9 ++++--- 5 files changed, 109 insertions(+), 13 deletions(-) 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 @@

{topics.teaser_username}: {topics.teaser_text}

+ posted {topics.teaser_timestamp} ago
@@ -48,7 +49,7 @@
Recent Replies
-
+
@@ -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' + + '

' + username + ': ' + posts.content[i] + '

posted ' + utils.relativeTime(posts.timestamp[i]) + ' ago'; + + 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