recent posts in /users/ page

v1.18.x
Baris Soner Usakli 12 years ago
parent 99465f1ffd
commit c93f8c0530

@ -227,6 +227,15 @@ footer.footer {
width:100px;
}
.user-recent-posts {
div {
color: #333;
margin-bottom: 10px;
}
span {
padding-top: 10px;
}
}
.category-icon {
width: 100%;

@ -25,7 +25,8 @@
</div>
</div>
<div class="span10">
<div class="span5">
<h4>profile</h4>
<div class="inline-block">
<div class="account-bio-block">
<span class="account-bio-label">email</span>
@ -76,6 +77,19 @@
</div>
</div>
</div>
<div class="span5 user-recent-posts">
<h4>recent posts </h4>
<!-- BEGIN posts -->
<a href="/topic/{posts.tid}/{posts.pid}">
<div class="topic-row img-polaroid clearfix">
<span>{posts.content}</span>
<span class="pull-right">{posts.timestamp} ago</span>
</div>
</a>
<!-- END posts -->
</div>
</div>
<br/>

@ -64,7 +64,7 @@ marked.setOptions({
};
Posts.getPostsByPids = function(pids, current_user, callback) {
var content = [], uid = [], timestamp = [], post_rep = [], editor = [], editTime = [], deleted = [];
var content = [], uid = [], timestamp = [], post_rep = [], editor = [], editTime = [], deleted = [], tid = [];
for (var i=0, ii=pids.length; i<ii; i++) {
content.push('pid:' + pids[i] + ':content');
@ -74,6 +74,7 @@ marked.setOptions({
editor.push('pid:' + pids[i] + ':editor');
editTime.push('pid:' + pids[i] + ':edited');
deleted.push('pid:' + pids[i] + ':deleted');
tid.push('pid:' + pids[i] + ':tid');
}
@ -92,6 +93,7 @@ marked.setOptions({
.mget(editor)
.mget(editTime)
.mget(deleted)
.mget(tid)
.exec(function(err, replies) {
post_data = {
pid: pids,
@ -101,7 +103,8 @@ marked.setOptions({
reputation: replies[3],
editor: replies[4],
editTime: replies[5],
deleted: replies[6]
deleted: replies[6],
tid: replies[7]
};
// below, to be deprecated
@ -302,5 +305,31 @@ marked.setOptions({
callback(raw);
});
}
Posts.getPostsByUid = function(uid, callback) {
RDB.lrange('uid:' + uid + ':posts', 0, 10, function(err, pids) {
if(err === null) {
Posts.getPostsByPids(pids, uid, function(posts) {
var returnData = [];
var len = posts.postData.pid.length;
for (var i=0; i < len; ++i) {
returnData.push({
pid: posts.postData.pid[i],
content: posts.postData.content[i],
timestamp: utils.relativeTime(posts.postData.timestamp[i]),
tid: posts.postData.tid[i]
});
};
console.log(returnData);
callback(returnData);
});
}
});
}
}(exports));

@ -1,5 +1,6 @@
var user = require('./../user.js'),
posts = require('./../posts.js'),
fs = require('fs'),
utils = require('./../../public/src/utils.js'),
path = require('path'),
@ -41,13 +42,13 @@ var user = require('./../user.js'),
return;
}
user.getUserData(uid, function(data) {
if(data) {
res.send(app.build_header(res) + app.create_route('users/'+data.userslug, 'account') + templates['footer']);
}
else {
res.redirect('/404');
}
user.getUserData(uid, function(userdata) {
if(userdata) {
res.send(app.build_header(res) + app.create_route('users/'+userdata.userslug, 'account') + templates['footer']);
}
else {
res.redirect('/404');
}
});
});
});
@ -274,11 +275,15 @@ var user = require('./../user.js'),
getUserDataByUserSlug(req.params.userslug, callerUID, function(userData) {
user.isFollowing(callerUID, userData.theirid, function(isFollowing) {
userData.isFollowing = isFollowing;
userData.signature = marked(userData.signature || '');
posts.getPostsByUid(userData.theirid, function(posts) {
userData.posts = posts;
userData.isFollowing = isFollowing;
res.json(userData);
userData.signature = marked(userData.signature || '');
res.json(userData);
});
});
});

Loading…
Cancel
Save