diff --git a/public/src/forum/account.js b/public/src/forum/account.js
index 72f59b0cd8..0e8129bae9 100644
--- a/public/src/forum/account.js
+++ b/public/src/forum/account.js
@@ -1,7 +1,7 @@
(function() {
var yourid = templates.get('yourid'),
theirid = templates.get('theirid'),
- isFriend = templates.get('isFriend');
+ isFollowing = templates.get('isFollowing');
$(document).ready(function() {
@@ -12,25 +12,24 @@
postcount.html(app.addCommas(postcount.html()));
var editLink = $('#editLink');
- var addFriendBtn = $('#add-friend-btn');
-
-
+ var followBtn = $('#follow-btn');
+
if( yourid !== theirid) {
editLink.hide();
- if(isFriend)
- addFriendBtn.hide();
+ if(isFollowing)
+ followBtn.hide();
else
- addFriendBtn.show();
+ followBtn.show();
}
else {
- addFriendBtn.hide();
+ followBtn.hide();
}
- addFriendBtn.on('click', function() {
- $.post('/users/addfriend', {uid: theirid},
+ followBtn.on('click', function() {
+ $.post('/users/follow', {uid: theirid},
function(data) {
- addFriendBtn.remove();
- $('#user-action-alert').html('Friend Added!').show();
+ followBtn.remove();
+ $('#user-action-alert').html('You are now following'+ $('.account-username').text() +'!').show();
}
);
return false;
diff --git a/public/src/forum/followers.js b/public/src/forum/followers.js
new file mode 100644
index 0000000000..ee7e019562
--- /dev/null
+++ b/public/src/forum/followers.js
@@ -0,0 +1,29 @@
+(function() {
+
+ var yourid = templates.get('yourid'),
+ theirid = templates.get('theirid'),
+ followersCount = templates.get('followersCount');
+
+ $(document).ready(function() {
+
+ if(parseInt(followersCount, 10) === 0) {
+ $('#no-followers-notice').show();
+ }
+ var editLink = $('#editLink');
+
+ if(yourid !== theirid) {
+ editLink.hide();
+ }
+
+ $('.reputation').each(function(index, element) {
+ $(element).html(app.addCommas($(element).html()));
+ });
+
+ $('.postcount').each(function(index, element) {
+ $(element).html(app.addCommas($(element).html()));
+ });
+
+ });
+
+
+}());
\ No newline at end of file
diff --git a/public/src/forum/following.js b/public/src/forum/following.js
new file mode 100644
index 0000000000..6e44908119
--- /dev/null
+++ b/public/src/forum/following.js
@@ -0,0 +1,44 @@
+(function() {
+
+ var yourid = templates.get('yourid'),
+ theirid = templates.get('theirid'),
+ followingCount = templates.get('followingCount');
+
+ $(document).ready(function() {
+
+ if(parseInt(followingCount, 10) === 0) {
+ $('#no-following-notice').show();
+ }
+ var editLink = $('#editLink');
+
+ if(yourid !== theirid) {
+ editLink.hide();
+ $('.unfollow-btn').hide();
+ }
+ else {
+ $('.unfollow-btn').on('click',function(){
+
+ var removeBtn = $(this);
+ var followingUid = $(this).attr('followingUid');
+
+ $.post('/users/unfollow', {uid: followingUid},
+ function(data) {
+ removeBtn.parent().remove();
+ }
+ );
+ return false;
+ });
+ }
+
+ $('.reputation').each(function(index, element) {
+ $(element).html(app.addCommas($(element).html()));
+ });
+
+ $('.postcount').each(function(index, element) {
+ $(element).html(app.addCommas($(element).html()));
+ });
+
+ });
+
+
+}());
\ No newline at end of file
diff --git a/public/templates/account.tpl b/public/templates/account.tpl
index 4a288e7bba..a15b9aa9e4 100644
--- a/public/templates/account.tpl
+++ b/public/templates/account.tpl
@@ -8,7 +8,8 @@
{username}
@@ -65,7 +66,7 @@
diff --git a/public/templates/accountedit.tpl b/public/templates/accountedit.tpl
index 878b6fe08b..63efebca48 100644
--- a/public/templates/accountedit.tpl
+++ b/public/templates/accountedit.tpl
@@ -66,7 +66,8 @@
edit
diff --git a/public/templates/config.json b/public/templates/config.json
index d562f3172e..61efdeef50 100644
--- a/public/templates/config.json
+++ b/public/templates/config.json
@@ -16,7 +16,8 @@
"install/social/?": "install/social",
"install/privileges/?": "install/privileges",
"users[^]*edit": "accountedit",
- "users[^]*friends": "friends",
+ "users[^]*following": "following",
+ "users[^]*followers": "followers",
"users/[^]*": "account",
"latest": "category",
"popular": "category",
diff --git a/public/templates/followers.tpl b/public/templates/followers.tpl
new file mode 100644
index 0000000000..6e5b9b0f70
--- /dev/null
+++ b/public/templates/followers.tpl
@@ -0,0 +1,47 @@
+
+
+
+
+
+
+
+
+
This user doesn't have any followers :(
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/public/templates/following.tpl b/public/templates/following.tpl
new file mode 100644
index 0000000000..ac0c3ff4b5
--- /dev/null
+++ b/public/templates/following.tpl
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
+
This user isn't following anyone :(
+
+
+
+
+
+
+
diff --git a/public/templates/friends.tpl b/public/templates/friends.tpl
deleted file mode 100644
index aee731db35..0000000000
--- a/public/templates/friends.tpl
+++ /dev/null
@@ -1,47 +0,0 @@
-
-
-
-
-
-
-
-
-
This user doesn't have any friends :(
-
-
-
-
-
-
-
diff --git a/src/routes/user.js b/src/routes/user.js
index b40660fef1..c657cf0592 100644
--- a/src/routes/user.js
+++ b/src/routes/user.js
@@ -202,36 +202,44 @@ var user = require('./../user.js'),
res.send({});
});
- app.post('/users/addfriend', function(req, res){
+ app.post('/users/follow', function(req, res){
if(!req.user)
return res.redirect('/403');
if(req.user.uid == req.body.uid)
return res.redirect('/');
- user.addFriend(req.user.uid, req.body.uid, function(data) {
+ user.follow(req.user.uid, req.body.uid, function(data) {
res.send({data:data});
});
});
- app.post('/users/removefriend', function(req, res){
+ app.post('/users/unfollow', 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) {
+ user.unfollow(req.user.uid, req.body.uid, function(data) {
res.send({data:data});
});
});
- app.get('/users/:username/friends', function(req, res){
+ app.get('/users/:username/following', function(req, res) {
if(!req.user)
return res.redirect('/403');
- res.send(build_header() + app.create_route('users/'+req.params.username+'/friends','friends') + templates['footer']);
+ res.send(build_header() + app.create_route('users/'+req.params.username+'/following','following') + templates['footer']);
+ });
+
+ app.get('/users/:username/followers', function(req, res) {
+
+ if(!req.user)
+ return res.redirect('/403');
+
+ res.send(build_header() + app.create_route('users/'+req.params.username+'/followers','followers') + templates['footer']);
});
function api_method(req, res) {
@@ -246,13 +254,24 @@ var user = require('./../user.js'),
});
}
- else if(String(req.params.section).toLowerCase() === 'friends') {
+ else if(String(req.params.section).toLowerCase() === 'following') {
+
+ getUserDataByUserName(req.params.username, callerUID, function(userData) {
+
+ user.getFollowing(userData.uid, function(followingData){
+ userData.following = followingData;
+ userData.followingCount = followingData.length;
+ res.send(JSON.stringify(userData));
+ });
+ });
+ }
+ else if(String(req.params.section).toLowerCase() === 'followers') {
getUserDataByUserName(req.params.username, callerUID, function(userData) {
- user.getFriends(userData.uid, function(friendsData){
- userData.friends = friendsData;
- userData.friendCount = friendsData.length;
+ user.getFollowers(userData.uid, function(followersData){
+ userData.followers = followersData;
+ userData.followersCount = followersData.length;
res.send(JSON.stringify(userData));
});
});
@@ -264,8 +283,8 @@ var user = require('./../user.js'),
} else {
getUserDataByUserName(req.params.username, callerUID, function(userData) {
- user.isFriend(callerUID, userData.theirid, function(isFriend) {
- userData.isFriend = isFriend;
+ user.isFollowing(callerUID, userData.theirid, function(isFollowing) {
+ userData.isFollowing = isFollowing;
userData.signature = marked(userData.signature || '');
diff --git a/src/user.js b/src/user.js
index 5c1221ca40..7c1b716bce 100644
--- a/src/user.js
+++ b/src/user.js
@@ -388,54 +388,71 @@ var utils = require('./../public/src/utils.js'),
}
}
- User.addFriend = function(uid, friendid, callback) {
- RDB.sadd('user:'+uid+':friends', friendid, function(err, data){
- if(err === null)
- callback(data);
+ User.follow = function(uid, followid, callback) {
+ RDB.sadd('user:'+uid+':following', followid, function(err, data) {
+ if(err === null) {
+ RDB.sadd('user:'+followid+':followers', uid, function(err, data) {
+ callback(data);
+ });
+ }
else
console.log(err);
- })
+ });
}
- User.getFriends = function(uid, callback) {
- RDB.smembers('user:'+uid+':friends', function(err, data){
- if(err === null){
-
- var friendsData = [];
-
- if(data.length === 0) {
- callback(friendsData);
- return;
- }
-
- for(var i=0, ii=data.length; i