Fix friend request from profile
This commit is contained in:
parent
61161c034c
commit
36aa07adab
@ -174,37 +174,43 @@ define([
|
|||||||
APP.$friend = $('<button>', {
|
APP.$friend = $('<button>', {
|
||||||
'class': 'btn btn-success cp-app-profile-friend-request',
|
'class': 'btn btn-success cp-app-profile-friend-request',
|
||||||
});
|
});
|
||||||
|
APP.$friend = $(h('div.cp-app-profile-friend-container'));
|
||||||
$container.append(APP.$friend);
|
$container.append(APP.$friend);
|
||||||
};
|
};
|
||||||
var refreshFriendRequest = function (data) {
|
var refreshFriendRequest = function (data) {
|
||||||
if (!APP.$friend) { return; }
|
if (!APP.$friend) { return; }
|
||||||
APP.$friend.off('click');
|
|
||||||
|
|
||||||
var me = common.getMetadataMgr().getUserData().curvePublic;
|
var me = common.getMetadataMgr().getUserData().curvePublic;
|
||||||
if (data.curvePublic === me) {
|
if (data.curvePublic === me) {
|
||||||
APP.$friend.remove();
|
APP.$friend.remove();
|
||||||
}
|
|
||||||
|
|
||||||
var friends = common.getMetadataMgr().getPrivateData().friends;
|
|
||||||
if (friends[data.curvePublic]) {
|
|
||||||
$(h('p.cp-app-profile-friend', Messages._getKey('profile_friend', [data.name]))).insertAfter(APP.$friend);
|
|
||||||
APP.$friend.remove();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
APP.$friend.html('');
|
||||||
|
|
||||||
|
var friends = common.getMetadataMgr().getPrivateData().friends;
|
||||||
|
var $temp;
|
||||||
|
if (friends[data.curvePublic]) {
|
||||||
|
APP.$friend.append(h('p.cp-app-profile-friend', Messages._getKey('profile_friend', [data.name || Messages.anonymous])));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var $button = $('<button>', {
|
||||||
|
'class': 'btn btn-success cp-app-profile-friend-request',
|
||||||
|
}).appendTo(APP.$friend);
|
||||||
|
|
||||||
var pendingFriends = APP.common.getPendingFriends(); // Friend requests sent
|
var pendingFriends = APP.common.getPendingFriends(); // Friend requests sent
|
||||||
if (pendingFriends[data.curvePublic]) {
|
if (pendingFriends[data.curvePublic]) {
|
||||||
APP.$friend.attr('disabled', 'disabled').text();
|
$button.attr('disabled', 'disabled').text(Messages.profile_friendRequestSent);
|
||||||
APP.$friend.text(Messages.profile_friendRequestSent);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
APP.$friend.text(Messages._getKey('userlist_addAsFriendTitle', [data.name || Messages.anonymous]))
|
$button.text(Messages._getKey('userlist_addAsFriendTitle', [data.name || Messages.anonymous]))
|
||||||
.click(function () {
|
.click(function () {
|
||||||
APP.common.sendFriendRequest({
|
APP.common.sendFriendRequest({
|
||||||
curvePublic: data.curvePublic,
|
curvePublic: data.curvePublic,
|
||||||
notifications: data.notifications
|
notifications: data.notifications
|
||||||
}, function () {
|
}, function () {
|
||||||
APP.$friend.attr('disabled', 'disabled').text();
|
$button.attr('disabled', 'disabled').text(Messages.profile_friendRequestSent);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user