v1.18.x
Baris Usakli 12 years ago
parent a95582b382
commit 1e66116e1d

@ -2,19 +2,35 @@
var yourid = templates.get('yourid'),
theirid = templates.get('theirid');
function createMenu() {
var userslug = $('.account-username-box').attr('data-userslug');
var links = $('<div class="account-sub-links inline-block pull-right">\
<span id="settingsLink" class="pull-right"><a href="/users/' + userslug + '/settings">settings</a></span>\
<span id="favouritesLink" class="pull-right"><a href="/users/' + userslug + '/favourites">favourites</a></span>\
<span class="pull-right"><a href="/users/' + userslug + '/followers">followers</a></span>\
<span class="pull-right"><a href="/users/' + userslug + '/following">following</a></span>\
<span id="editLink" class="pull-right"><a href="/users/' + userslug + '/edit">edit</a></span>\
</div>');
$('.account-username-box').append(links);
}
$(document).ready(function() {
createMenu();
var editLink = $('#editLink');
var settingsLink = $('#settingsLink');
var favouritesLink = $('#favouritesLink');
if(yourid === "0") {
editLink.hide();
settingsLink.hide();
}
else if(yourid !== theirid) {
if(yourid === "0" || yourid !== theirid) {
editLink.hide();
settingsLink.hide();
favouritesLink.hide();
}
});
}());

@ -0,0 +1,11 @@
(function() {
$(document).ready(function() {
$('.user-favourite-posts .topic-row').on('click', function() {
ajaxify.go($(this).attr('topic-url'));
});
});
}());

@ -1,21 +1,12 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
<div class="span2 account-block" style="text-align: center; margin-bottom:20px;">
<div class="account-picture-block">

@ -60,17 +60,11 @@
</div>
</div>
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/edit">edit</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
@ -171,4 +165,5 @@
<input type="hidden" template-variable="gravatarpicture" value="{gravatarpicture}" />
<input type="hidden" template-variable="uploadedpicture" value="{uploadedpicture}" />
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountedit.js"></script>

@ -1,17 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/settings">settings</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div class="row-fluid">
@ -31,4 +25,5 @@
</div>
</div>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/accountsettings.js"></script>

@ -25,6 +25,7 @@
"users[^]*following": "following",
"users[^]*followers": "followers",
"users[^]*settings": "accountsettings",
"users[^]*favourites": "favourites",
"users/[^]*": "account",
"recent": "recent",

@ -0,0 +1,34 @@
<div class="well">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a>
</span>
</div>
<div id="no-favourites-notice" class="alert alert-warning {show_nofavourites}">You don't have any favourites, favourite some posts to see them here!</div>
<div class="row-fluid">
<div class="span12 user-favourite-posts">
<!-- BEGIN posts -->
<div class="topic-row img-polaroid clearfix" topic-url="topic/{posts.tid}/#{posts.pid}">
<span><strong>{posts.username}</strong> : </span>
<span>{posts.content}</span>
<div>
<span class="pull-right">{posts.relativeTime} ago</span>
</div>
</div>
<br/>
<!-- END posts -->
</div>
</div>
</div>
<script type="text/javascript" src="{relative_path}/src/forum/accountheader.js"></script>
<script type="text/javascript" src="{relative_path}/src/forum/favourites.js"></script>

@ -1,17 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/followers">followers</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div>
@ -32,7 +26,6 @@
<i class='icon-pencil'></i>
</div>
</div>
<!-- END followers -->
</div>
<div id="no-followers-notice" class="alert alert-warning hide">This user doesn't have any followers :(</div>

@ -1,19 +1,11 @@
<div class="well">
<div class="account-username-box">
<div class="account-username-box" data-userslug="{userslug}">
<span class="account-username">
<a href="/users/{userslug}">{username}</a> <i class="icon-chevron-right"></i>
<a href="/users/{userslug}/following">following</a>
</span>
<div class="account-sub-links inline-block pull-right">
<span id="settingsLink" class="pull-right"><a href="/users/{userslug}/settings">settings</a></span>
<span class="pull-right"><a href="/users/{userslug}/followers">followers</a></span>
<span class="pull-right"><a href="/users/{userslug}/following">following</a></span>
<span id="editLink" class="pull-right"><a href="/users/{userslug}/edit">edit</a></span>
</div>
</div>
<div>

@ -199,7 +199,7 @@ var RDB = require('./redis.js'),
return;
}
posts.getPostSummaryByPids(pids, function(postData) {
posts.getPostSummaryByPids(pids, function(err, postData) {
if(postData.length > count) {
postData = postData.slice(0, count);
}

@ -16,21 +16,23 @@ var RDB = require('./redis.js'),
return;
}
posts.getPostField(pid, 'uid', function(uid_of_poster) {
posts.getPostFields(pid, ['uid', 'timestamp'], function(postData) {
Favourites.hasFavourited(pid, uid, function(hasFavourited) {
if (hasFavourited == false) {
RDB.sadd('pid:' + pid + ':users_favourited', uid);
RDB.zadd('uid:' + uid + ':favourites', postData.timestamp, pid);
RDB.hincrby('post:' + pid, 'reputation', 1);
if (uid !== uid_of_poster) {
user.incrementUserFieldBy(uid_of_poster, 'reputation', 1, function(err, newreputation) {
RDB.zadd('users:reputation', newreputation, uid_of_poster);
if (uid !== postData.uid) {
user.incrementUserFieldBy(postData.uid, 'reputation', 1, function(err, newreputation) {
RDB.zadd('users:reputation', newreputation, postData.uid);
});
}
if (room_id) {
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== uid_of_poster ? uid_of_poster : 0, pid: pid});
io.sockets.in(room_id).emit('event:rep_up', {uid: uid !== postData.uid ? postData.uid : 0, pid: pid});
}
socket.emit('api:posts.favourite', {
@ -60,6 +62,8 @@ var RDB = require('./redis.js'),
if (hasFavourited == true) {
RDB.srem('pid:' + pid + ':users_favourited', uid);
RDB.zrem('uid:' + uid + ':favourites', pid);
RDB.hincrby('post:' + pid, 'reputation', -1);
if (uid !== uid_of_poster) {

@ -22,7 +22,7 @@ var RDB = require('./redis.js'),
RDB.handle(err);
if (pids.length) {
Posts.getPostsByPids(pids, function(posts) {
Posts.getPostsByPids(pids, function(err, posts) {
callback(posts);
});
} else {
@ -70,20 +70,20 @@ var RDB = require('./redis.js'),
if(postData.content)
postData.content = utils.strip_tags(postTools.markdownToHTML(postData.content));
postData.relativeTime = utils.relativeTime(postData.timestamp);
postData.topicSlug = topicSlug;
posts.push(postData);
callback(null);
});
});
});
}
async.eachSeries(pids, getPostSummary, function(err) {
if(!err) {
callback(posts);
callback(null, posts);
} else {
console.log(err);
callback(err, null);
}
});
};
@ -155,9 +155,9 @@ var RDB = require('./redis.js'),
async.eachSeries(pids, iterator, function(err) {
if(!err) {
callback(posts);
callback(null, posts);
} else {
callback([]);
callback(err, null);
}
});
}
@ -370,7 +370,7 @@ var RDB = require('./redis.js'),
if(pids && pids.length) {
Posts.getPostsByPids(pids, function(posts) {
Posts.getPostsByPids(pids, function(err, posts) {
callback(posts);
});
}
@ -418,4 +418,19 @@ var RDB = require('./redis.js'),
});
}
Posts.getFavourites = function(uid, callback) {
RDB.zrevrange('uid:' + uid + ':favourites', 0, -1, function(err, pids) {
if(err)
return callback(err, null);
Posts.getPostSummaryByPids(pids, function(err, posts) {
if(err)
return callback(err, null);
callback(null, posts);
});
});
}
}(exports));

@ -194,7 +194,9 @@ var user = require('./../user.js'),
if(err)
return callback(err, null);
posts.getPostSummaryByPids(pids, function(posts) {
posts.getPostSummaryByPids(pids, function(err, posts) {
if(err)
return callback(err, null);
callback(null, posts);
});
})

@ -224,6 +224,22 @@ var user = require('./../user.js'),
});
});
app.get('/users/:userslug/favourites', function(req, res) {
if(!req.user)
return res.redirect('/403');
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.redirect('/404');
return;
}
app.build_header({ req: req, res: res }, function(err, header) {
res.send(header + app.create_route('users/'+req.params.userslug+'/favourites','favourites') + templates['footer']);
});
});
});
app.get('/api/users/:userslug/following', function(req, res) {
var callerUID = req.user ? req.user.uid : 0;
@ -292,6 +308,36 @@ var user = require('./../user.js'),
});
});
app.get('/api/users/:userslug/favourites', function(req, res, next) {
var callerUID = req.user ? req.user.uid : 0;
user.get_uid_by_userslug(req.params.userslug, function(uid) {
if(!uid) {
res.json(404, { error: 'User not found!' }) ;
return;
}
if(uid !== callerUID || callerUID === "0") {
res.json(403, { error: 'Not allowed!' });
return;
}
user.getUserFields(uid, ['username','userslug'], function(userData) {
if(userData) {
posts.getFavourites(uid, function(err, posts) {
if(err)
return next(err);
userData.posts = posts;
userData.show_nofavourites = posts.length?'hide':'show';
res.json(userData);
});
} else {
res.json(404, { error: 'User not found!' }) ;
}
});
});
});
app.get('/api/users/:userslug', function(req, res) {
var callerUID = req.user ? req.user.uid : 0;

Loading…
Cancel
Save