mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-10 16:05:49 +01:00
friends
This commit is contained in:
@@ -390,6 +390,10 @@ footer.footer {
|
|||||||
margin-bottom:10px;
|
margin-bottom:10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.account-sub-links a{
|
||||||
|
margin-left:10px;
|
||||||
|
}
|
||||||
|
|
||||||
.account-username{
|
.account-username{
|
||||||
font-size:20px;
|
font-size:20px;
|
||||||
font-weight:bold;
|
font-weight:bold;
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ var templates = {};
|
|||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
loadTemplates([
|
loadTemplates([
|
||||||
'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', 'accountedit',
|
'header', 'footer', 'register', 'home', 'topic','account', 'category', 'users', 'accountedit', 'friends',
|
||||||
'login', 'reset', 'reset_code', 'account',
|
'login', 'reset', 'reset_code', 'account',
|
||||||
'confirm', '403',
|
'confirm', '403',
|
||||||
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext',
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
|
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<div class="alert" id="message" style="display:none">
|
|
||||||
<button type="button" class="close" data-dismiss="message">×</button>
|
|
||||||
<strong></strong>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
<div class="account-username-box">
|
<div class="account-username-box">
|
||||||
<span class="account-username"><a href="/users/{username}">{username}</a></span>
|
<span class="account-username">
|
||||||
<span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
|
<a href="/users/{username}">{username}</a>
|
||||||
|
</span>
|
||||||
|
<div class="account-sub-links inline-block pull-right">
|
||||||
|
<span id="friendsLink" class="pull-right"><a href="/users/{username}/friends">friends</a></span>
|
||||||
|
<span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
@@ -60,6 +61,8 @@
|
|||||||
<div id="user-actions" class="container">
|
<div id="user-actions" class="container">
|
||||||
<a id="add-friend-btn" href="#" class="btn">Add Friend</a>
|
<a id="add-friend-btn" href="#" class="btn">Add Friend</a>
|
||||||
</div>
|
</div>
|
||||||
|
<br/>
|
||||||
|
<div id="user-action-alert" class="alert alert-success hide"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
@@ -67,11 +70,7 @@
|
|||||||
var yourid = '{yourid}';
|
var yourid = '{yourid}';
|
||||||
var theirid = '{theirid}';
|
var theirid = '{theirid}';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function addCommas(text) {
|
function addCommas(text) {
|
||||||
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
|
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
|
||||||
@@ -94,14 +93,13 @@ var theirid = '{theirid}';
|
|||||||
addFriendBtn.show();
|
addFriendBtn.show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
addFriendBtn.hide();
|
addFriendBtn.hide();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
addFriendBtn.on('click', function() {
|
addFriendBtn.on('click', function() {
|
||||||
$.post('/users/addfriend', {uid: theirid},
|
$.post('/users/addfriend', {uid: theirid},
|
||||||
function(data) {
|
function(data) {
|
||||||
|
$('#user-action-alert').html('Friend Added!').show();
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -1,11 +1,7 @@
|
|||||||
|
|
||||||
<div class="well">
|
<div class="well">
|
||||||
|
|
||||||
<div class="alert" id="message" style="display:none">
|
|
||||||
<button type="button" class="close" data-dismiss="message">×</button>
|
|
||||||
<strong></strong>
|
|
||||||
<p></p>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Change Picture Modal -->
|
<!-- Change Picture Modal -->
|
||||||
<div id="change-picture-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
<div id="change-picture-modal" class="modal hide" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||||
@@ -65,9 +61,15 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="account-username-box">
|
<div class="account-username-box">
|
||||||
<span class="account-username"><a href="/users/{username}">{username}</a></span>
|
<span class="account-username">
|
||||||
<span class="pull-right"><a href="/users/{username}/edit">edit</a></span>
|
<a href="/users/{username}">{username}</a> >
|
||||||
</div>
|
<a href="/users/{username}/edit">edit</a>
|
||||||
|
</span>
|
||||||
|
<div class="account-sub-links inline-block pull-right">
|
||||||
|
<span id="friendsLink" class="pull-right"><a href="/users/{username}/friends">friends</a></span>
|
||||||
|
<span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="row-fluid">
|
<div class="row-fluid">
|
||||||
<div class="span3" style="text-align: center; margin-bottom:20px;">
|
<div class="span3" style="text-align: center; margin-bottom:20px;">
|
||||||
|
|||||||
@@ -4,6 +4,7 @@
|
|||||||
"admin/categories[^]*": "admin/categories",
|
"admin/categories[^]*": "admin/categories",
|
||||||
"admin/users[^]*": "admin/users",
|
"admin/users[^]*": "admin/users",
|
||||||
"users[^]*edit": "accountedit",
|
"users[^]*edit": "accountedit",
|
||||||
|
"users[^]*friends": "friends",
|
||||||
"users": "account",
|
"users": "account",
|
||||||
"latest": "category",
|
"latest": "category",
|
||||||
"popular": "category",
|
"popular": "category",
|
||||||
|
|||||||
94
public/templates/friends.tpl
Normal file
94
public/templates/friends.tpl
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
|
||||||
|
<div class="well">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<div class="account-username-box">
|
||||||
|
<span class="account-username">
|
||||||
|
<a href="/users/{username}">{username}</a> >
|
||||||
|
<a href="/users/{username}/friends">friends</a>
|
||||||
|
</span>
|
||||||
|
<div class="account-sub-links inline-block pull-right">
|
||||||
|
<span id="friendsLink" class="pull-right"><a href="/users/{username}/friends">friends</a></span>
|
||||||
|
<span id="editLink" class="pull-right"><a href="/users/{username}/edit">edit</a></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<!-- BEGIN friends -->
|
||||||
|
|
||||||
|
<div class="users-box well">
|
||||||
|
<a href="/users/{friends.username}">
|
||||||
|
<img src="{friends.picture}" class="user-8080-picture"/>
|
||||||
|
</a>
|
||||||
|
<br/>
|
||||||
|
<a href="/users/{friends.username}">{friends.username}</a>
|
||||||
|
<br/>
|
||||||
|
<div title="reputation">
|
||||||
|
<span class='reputation'>{friends.reputation}</span>
|
||||||
|
<i class='icon-star'></i>
|
||||||
|
</div>
|
||||||
|
<div title="post count">
|
||||||
|
<span class='postcount'>{friends.postcount}</span>
|
||||||
|
<i class='icon-pencil'></i>
|
||||||
|
</div>
|
||||||
|
<a id="remove-friend-btn" href="#" class="btn remove-friend-btn" friendid="{friends.uid}">Unfriend</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- END friends -->
|
||||||
|
</div>
|
||||||
|
<div id="no-friend-notice" class="alert alert-warning hide">This user doesn't have any friends :(</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
var yourid = '{yourid}';
|
||||||
|
var theirid = '{theirid}';
|
||||||
|
|
||||||
|
var friendCount = '{friendCount}';
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
function addCommas(text) {
|
||||||
|
return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
|
||||||
|
}
|
||||||
|
|
||||||
|
$(document).ready(function() {
|
||||||
|
|
||||||
|
if(parseInt(friendCount, 10) === 0) {
|
||||||
|
$('#no-friend-notice').show();
|
||||||
|
}
|
||||||
|
var editLink = $('#editLink');
|
||||||
|
|
||||||
|
if(yourid !== theirid) {
|
||||||
|
editLink.hide();
|
||||||
|
$('.remove-friend-btn').hide();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$('.remove-friend-btn').on('click',function(){
|
||||||
|
|
||||||
|
var removeBtn = $(this);
|
||||||
|
var friendid = $(this).attr('friendid');
|
||||||
|
|
||||||
|
$.post('/users/removefriend', {uid: friendid},
|
||||||
|
function(data) {
|
||||||
|
button.parent().remove();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
$('.reputation').each(function(index, element) {
|
||||||
|
$(element).html(addCommas($(element).html()));
|
||||||
|
})
|
||||||
|
|
||||||
|
$('.postcount').each(function(index, element) {
|
||||||
|
$(element).html(addCommas($(element).html()));
|
||||||
|
})
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
}());
|
||||||
|
</script>
|
||||||
@@ -34,7 +34,8 @@ var user = require('./../user.js'),
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/users/:username*', function(req, res) {
|
app.get('/users/:username', function(req, res) {
|
||||||
|
|
||||||
if(!req.params.username) {
|
if(!req.params.username) {
|
||||||
res.send("User doesn't exist!");
|
res.send("User doesn't exist!");
|
||||||
return;
|
return;
|
||||||
@@ -189,30 +190,33 @@ var user = require('./../user.js'),
|
|||||||
if(req.user.uid == req.body.uid)
|
if(req.user.uid == req.body.uid)
|
||||||
return res.redirect('/');
|
return res.redirect('/');
|
||||||
|
|
||||||
user.addFriend(req.user.uid, req.body.uid, function(err, data) {
|
user.addFriend(req.user.uid, req.body.uid, function(data) {
|
||||||
if(err)
|
res.send({data:data});
|
||||||
res.send({error:err});
|
});
|
||||||
else
|
});
|
||||||
res.send(data);
|
|
||||||
|
app.post('/users/removefriend', function(req, res){
|
||||||
|
if(!req.user)
|
||||||
|
return res.redirect('/403');
|
||||||
|
|
||||||
|
if(req.user.uid == req.body.uid)
|
||||||
|
return res.redirect('/');
|
||||||
|
|
||||||
|
user.removeFriend(req.user.uid, req.body.uid, function(data) {
|
||||||
|
res.send({data:data});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
app.get('/users/:username/friends', function(req, res){
|
app.get('/users/:username/friends', function(req, res){
|
||||||
|
|
||||||
if(!req.user)
|
if(!req.user)
|
||||||
return res.redirect('/403');
|
return res.redirect('/403');
|
||||||
|
|
||||||
user.get_uid_by_username(req.params.username, function(uid) {
|
res.send(templates['header'] + app.create_route('users/'+req.params.username+'/friends','friends') + templates['footer']);
|
||||||
user.getFriends(uid, function(data) {
|
|
||||||
res.send(JSON.stringify(data, null, 0));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function api_method(req, res) {
|
function api_method(req, res) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var callerUID = req.user?req.user.uid : 0;
|
var callerUID = req.user?req.user.uid : 0;
|
||||||
|
|
||||||
if (!req.params.section && !req.params.username) {
|
if (!req.params.section && !req.params.username) {
|
||||||
@@ -225,6 +229,14 @@ var user = require('./../user.js'),
|
|||||||
}
|
}
|
||||||
else if(String(req.params.section).toLowerCase() === 'friends') {
|
else if(String(req.params.section).toLowerCase() === 'friends') {
|
||||||
|
|
||||||
|
getUserDataByUserName(req.params.username, callerUID, function(userData) {
|
||||||
|
|
||||||
|
user.getFriends(userData.uid, function(friendsData){
|
||||||
|
userData.friends = friendsData;
|
||||||
|
userData.friendCount = friendsData.length;
|
||||||
|
res.send(JSON.stringify(userData));
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
else if (String(req.params.section).toLowerCase() === 'edit') {
|
else if (String(req.params.section).toLowerCase() === 'edit') {
|
||||||
getUserDataByUserName(req.params.username, callerUID, function(userData) {
|
getUserDataByUserName(req.params.username, callerUID, function(userData) {
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ var fs = require('fs');
|
|||||||
|
|
||||||
Templates.init = function() {
|
Templates.init = function() {
|
||||||
loadTemplates([
|
loadTemplates([
|
||||||
'header', 'footer', 'register', 'home', 'topic', 'account',
|
'header', 'footer', 'register', 'home', 'topic', 'account', 'friends',
|
||||||
'login', 'reset', 'reset_code', 'logout',
|
'login', 'reset', 'reset_code', 'logout',
|
||||||
'403',
|
'403',
|
||||||
'admin/header', 'admin/footer', 'admin/index',
|
'admin/header', 'admin/footer', 'admin/index',
|
||||||
|
|||||||
21
src/user.js
21
src/user.js
@@ -64,6 +64,7 @@ var config = require('../config.js'),
|
|||||||
{
|
{
|
||||||
if(data && data['password'])
|
if(data && data['password'])
|
||||||
delete data['password'];
|
delete data['password'];
|
||||||
|
data.uid = uid;
|
||||||
callback(data);
|
callback(data);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -365,8 +366,24 @@ var config = require('../config.js'),
|
|||||||
|
|
||||||
User.getFriends = function(uid, callback) {
|
User.getFriends = function(uid, callback) {
|
||||||
RDB.smembers('user:'+uid+':friends', function(err, data){
|
RDB.smembers('user:'+uid+':friends', function(err, data){
|
||||||
if(err === null)
|
if(err === null){
|
||||||
callback(data);
|
|
||||||
|
var friendsData = [];
|
||||||
|
|
||||||
|
if(data.length === 0) {
|
||||||
|
callback(friendsData);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(var i=0, ii=data.length; i<ii; ++i) {
|
||||||
|
User.getUserData(data[i], function(userData){
|
||||||
|
friendsData.push(userData);
|
||||||
|
console.log(friendsData);
|
||||||
|
if(friendsData.length == data.length)
|
||||||
|
callback(friendsData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user