Realtime update of the friendship status in the profile

This commit is contained in:
yflory
2019-05-27 17:51:55 +02:00
parent 6370c0eeae
commit c3e9b51f76
5 changed files with 41 additions and 11 deletions

View File

@@ -7,6 +7,7 @@ define([
'/common/sframe-common.js',
'/common/common-util.js',
'/common/common-interface.js',
'/common/common-ui-elements.js',
'/common/common-realtime.js',
'/common/hyperscript.js',
'/customize/messages.js',
@@ -33,6 +34,7 @@ define([
SFCommon,
Util,
UI,
UIElements,
Realtime,
h,
Messages,
@@ -199,6 +201,16 @@ define([
'class': 'btn btn-success cp-app-profile-friend-request',
}).appendTo(APP.$friend);
// If this curve has sent us a friend request, we should not be able to sent it to them
var friendRequests = common.getFriendRequests();
if (friendRequests[data.curvePublic]) {
$button.html(Messages._getKey('friendRequest_received', [data.name || Messages.anonymous]))
.click(function () {
UIElements.displayFriendRequestModal(common, friendRequests[data.curvePublic]);
});
return;
}
var pendingFriends = APP.common.getPendingFriends(); // Friend requests sent
if (pendingFriends[data.curvePublic]) {
$button.attr('disabled', 'disabled').text(Messages.profile_friendRequestSent);
@@ -548,8 +560,19 @@ define([
lm.proxy.on('ready', function () {
updateValues(lm.proxy);
UI.removeLoadingScreen();
common.mailbox.subscribe({
onMessage: function () {
refreshFriendRequest(lm.proxy);
},
onViewed: function () {
refreshFriendRequest(lm.proxy);
},
});
}).on('change', [], function () {
updateValues(lm.proxy);
});
metadataMgr.onChange(function () {
updateValues(lm.proxy);
});
});
});