mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-01 03:26:04 +01:00
add friend button invisible if user is already friend
This commit is contained in:
@@ -72,6 +72,8 @@ var theirid = '{theirid}';
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
var isFriend = {isFriend};
|
||||||
|
|
||||||
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,");
|
||||||
}
|
}
|
||||||
@@ -90,6 +92,9 @@ var theirid = '{theirid}';
|
|||||||
|
|
||||||
if( yourid !== theirid) {
|
if( yourid !== theirid) {
|
||||||
editLink.hide();
|
editLink.hide();
|
||||||
|
if(isFriend)
|
||||||
|
addFriendBtn.hide();
|
||||||
|
else
|
||||||
addFriendBtn.show();
|
addFriendBtn.show();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -244,16 +244,17 @@ var user = require('./../user.js'),
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
getUserDataByUserName(req.params.username, callerUID, function(userData) {
|
getUserDataByUserName(req.params.username, callerUID, function(userData) {
|
||||||
|
user.isFriend(callerUID, userData.theirid, function(isFriend) {
|
||||||
|
userData.isFriend = isFriend;
|
||||||
res.send(JSON.stringify(userData));
|
res.send(JSON.stringify(userData));
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
app.get('/api/users/:username?/:section?', api_method);
|
app.get('/api/users/:username?/:section?', api_method);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function getUserDataByUserName(username, callerUID, callback) {
|
function getUserDataByUserName(username, callerUID, callback) {
|
||||||
|
|
||||||
user.get_uid_by_username(username, function(uid) {
|
user.get_uid_by_username(username, function(uid) {
|
||||||
|
|||||||
12
src/user.js
12
src/user.js
@@ -378,7 +378,7 @@ var config = require('../config.js'),
|
|||||||
for(var i=0, ii=data.length; i<ii; ++i) {
|
for(var i=0, ii=data.length; i<ii; ++i) {
|
||||||
User.getUserData(data[i], function(userData){
|
User.getUserData(data[i], function(userData){
|
||||||
friendsData.push(userData);
|
friendsData.push(userData);
|
||||||
console.log(friendsData);
|
|
||||||
if(friendsData.length == data.length)
|
if(friendsData.length == data.length)
|
||||||
callback(friendsData);
|
callback(friendsData);
|
||||||
});
|
});
|
||||||
@@ -398,6 +398,16 @@ var config = require('../config.js'),
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
User.isFriend = function(uid, friendid, callback) {
|
||||||
|
RDB.sismember('user:'+uid+':friends', friendid, function(err, data){
|
||||||
|
if(err === null){
|
||||||
|
callback(data === 1);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
User.exists = function(username, callback) {
|
User.exists = function(username, callback) {
|
||||||
User.get_uid_by_username(username, function(exists) {
|
User.get_uid_by_username(username, function(exists) {
|
||||||
exists = !!exists;
|
exists = !!exists;
|
||||||
|
|||||||
Reference in New Issue
Block a user