Realtime update of the friendship status in the profile
This commit is contained in:
parent
6370c0eeae
commit
c3e9b51f76
@ -19,7 +19,7 @@ define([
|
||||
// Display the notification
|
||||
$(el).find('.cp-notification-content').addClass("cp-clickable");
|
||||
$(el).find('.cp-notification-content p')
|
||||
.html(Messages._getKey('friendRequest_notification', [msg.content.displayName]))
|
||||
.html(Messages._getKey('friendRequest_notification', [msg.content.displayName || Messages.anonymous]))
|
||||
.click(function () {
|
||||
UIElements.displayFriendRequestModal(common, data);
|
||||
});
|
||||
@ -29,7 +29,7 @@ define([
|
||||
var content = data.content;
|
||||
var msg = content.msg;
|
||||
$(el).find('.cp-notification-content p')
|
||||
.html(Messages._getKey('friendRequest_accepted', [msg.content.name]));
|
||||
.html(Messages._getKey('friendRequest_accepted', [msg.content.name || Messages.anonymous]));
|
||||
$(el).find('.cp-notification-dismiss').css('display', 'flex');
|
||||
};
|
||||
|
||||
@ -37,7 +37,7 @@ define([
|
||||
var content = data.content;
|
||||
var msg = content.msg;
|
||||
$(el).find('.cp-notification-content p')
|
||||
.html(Messages._getKey('friendRequest_declined', [msg.content.name]));
|
||||
.html(Messages._getKey('friendRequest_declined', [msg.content.name || Messages.anonymous]));
|
||||
$(el).find('.cp-notification-dismiss').css('display', 'flex');
|
||||
};
|
||||
|
||||
|
||||
@ -959,6 +959,7 @@ define([
|
||||
channel: msg.content.notifications,
|
||||
curvePublic: msg.content.curvePublic
|
||||
}, function (obj) {
|
||||
broadcast([], "UPDATE_METADATA");
|
||||
cb(obj);
|
||||
});
|
||||
dismiss();
|
||||
|
||||
@ -12,9 +12,12 @@ define([
|
||||
|
||||
// Store the friend request displayed to avoid duplicates
|
||||
var friendRequest = {};
|
||||
handlers['FRIEND_REQUEST'] = function (ctx, data, cb) {
|
||||
handlers['FRIEND_REQUEST'] = function (ctx, box, data, cb) {
|
||||
|
||||
// Check if the request is valid (send by the correct user)
|
||||
if (data.msg.author !== data.msg.content.curvePublic) { return void cb(true); }
|
||||
if (data.msg.author !== data.msg.content.curvePublic) {
|
||||
return void cb(true);
|
||||
}
|
||||
|
||||
// Don't show duplicate friend request: if we already have a friend request
|
||||
// in memory from the same user, dismiss the new one
|
||||
@ -23,7 +26,8 @@ define([
|
||||
friendRequest[data.msg.author] = true;
|
||||
|
||||
// If the user is already in our friend list, automatically accept the request
|
||||
if (Messaging.getFriend(ctx.store.proxy, data.msg.author)) {
|
||||
if (Messaging.getFriend(ctx.store.proxy, data.msg.author) ||
|
||||
ctx.store.proxy.friends_pending[data.msg.author]) {
|
||||
Messaging.acceptFriendRequest(ctx.store, data.msg.content, function (obj) {
|
||||
if (obj && obj.error) {
|
||||
return void cb();
|
||||
@ -36,8 +40,8 @@ define([
|
||||
cb();
|
||||
};
|
||||
removeHandlers['FRIEND_REQUEST'] = function (ctx, box, data) {
|
||||
if (friendRequest[data.curvePublic]) {
|
||||
delete friendRequest[data.curvePublic];
|
||||
if (friendRequest[data.content.curvePublic]) {
|
||||
delete friendRequest[data.content.curvePublic];
|
||||
}
|
||||
};
|
||||
|
||||
@ -51,8 +55,6 @@ define([
|
||||
delete ctx.store.proxy.friends_pending[data.msg.author];
|
||||
ctx.updateMetadata();
|
||||
if (friendRequestDeclined[data.msg.author]) { return; }
|
||||
// If you have a profile page open, update it
|
||||
if (ctx.store.modules['profile']) { ctx.store.modules['profile'].update(); }
|
||||
box.sendMessage({
|
||||
type: 'FRIEND_REQUEST_DECLINED',
|
||||
content: {
|
||||
@ -69,6 +71,7 @@ define([
|
||||
cb(true);
|
||||
};
|
||||
handlers['FRIEND_REQUEST_DECLINED'] = function (ctx, box, data, cb) {
|
||||
ctx.updateMetadata();
|
||||
if (friendRequestDeclined[data.msg.content.user]) { return void cb(true); }
|
||||
friendRequestDeclined[data.msg.content.user] = true;
|
||||
cb();
|
||||
@ -97,9 +100,9 @@ define([
|
||||
ctx.store.messenger.onFriendAdded(data.msg.content);
|
||||
}
|
||||
ctx.updateMetadata();
|
||||
if (friendRequestAccepted[data.msg.author]) { return; }
|
||||
// If you have a profile page open, update it
|
||||
if (ctx.store.modules['profile']) { ctx.store.modules['profile'].update(); }
|
||||
if (friendRequestAccepted[data.msg.author]) { return; }
|
||||
// Display the "accepted" state in the UI
|
||||
box.sendMessage({
|
||||
type: 'FRIEND_REQUEST_ACCEPTED',
|
||||
@ -118,6 +121,7 @@ define([
|
||||
cb(true);
|
||||
};
|
||||
handlers['FRIEND_REQUEST_ACCEPTED'] = function (ctx, box, data, cb) {
|
||||
ctx.updateMetadata();
|
||||
if (friendRequestAccepted[data.msg.content.user]) { return void cb(true); }
|
||||
friendRequestAccepted[data.msg.content.user] = true;
|
||||
cb();
|
||||
@ -131,6 +135,7 @@ define([
|
||||
|
||||
return {
|
||||
add: function (ctx, box, data, cb) {
|
||||
if (!data.msg) { return void cb(true); }
|
||||
var type = data.msg.type;
|
||||
|
||||
if (handlers[type]) {
|
||||
|
||||
@ -135,6 +135,7 @@ define([
|
||||
removeClient(ctx, clientId);
|
||||
};
|
||||
profile.update = function () {
|
||||
if (!ctx.listmap) { return; }
|
||||
ctx.emit('UPDATE', ctx.listmap.proxy, ctx.clients);
|
||||
};
|
||||
profile.execCommand = function (clientId, obj, cb) {
|
||||
|
||||
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user