From 3b0978caa7e15abc7ee75efa8d02e5350e7ab1c8 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 15 May 2013 14:30:03 -0400 Subject: [PATCH] add friend button invisible if user is already friend --- public/templates/account.tpl | 7 ++++++- src/routes/user.js | 7 ++++--- src/user.js | 12 +++++++++++- 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/public/templates/account.tpl b/public/templates/account.tpl index eba82fcc6f..efc5d8099d 100644 --- a/public/templates/account.tpl +++ b/public/templates/account.tpl @@ -72,6 +72,8 @@ var theirid = '{theirid}'; (function() { + var isFriend = {isFriend}; + function addCommas(text) { return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); } @@ -90,7 +92,10 @@ var theirid = '{theirid}'; if( yourid !== theirid) { editLink.hide(); - addFriendBtn.show(); + if(isFriend) + addFriendBtn.hide(); + else + addFriendBtn.show(); } else { addFriendBtn.hide(); diff --git a/src/routes/user.js b/src/routes/user.js index fe92c1913c..cfd82e4038 100644 --- a/src/routes/user.js +++ b/src/routes/user.js @@ -244,7 +244,10 @@ var user = require('./../user.js'), }); } else { getUserDataByUserName(req.params.username, callerUID, function(userData) { - res.send(JSON.stringify(userData)); + user.isFriend(callerUID, userData.theirid, function(isFriend) { + userData.isFriend = isFriend; + res.send(JSON.stringify(userData)); + }); }); } @@ -252,8 +255,6 @@ var user = require('./../user.js'), app.get('/api/users/:username?/:section?', api_method); - - function getUserDataByUserName(username, callerUID, callback) { user.get_uid_by_username(username, function(uid) { diff --git a/src/user.js b/src/user.js index 04d0af9ca0..4af1fc23b0 100644 --- a/src/user.js +++ b/src/user.js @@ -378,7 +378,7 @@ var config = require('../config.js'), for(var i=0, ii=data.length; i