VRFS-595 session invitations / fix bug with session join notifications arriving twice
This commit is contained in:
parent
6ab0c1383d
commit
70cba2d98d
|
|
@ -28,6 +28,7 @@ message ClientMessage {
|
||||||
MUSICIAN_SESSION_FRESH = 115;
|
MUSICIAN_SESSION_FRESH = 115;
|
||||||
MUSICIAN_SESSION_STALE = 116;
|
MUSICIAN_SESSION_STALE = 116;
|
||||||
HEARTBEAT_ACK = 117;
|
HEARTBEAT_ACK = 117;
|
||||||
|
SESSION_ENDED = 118;
|
||||||
|
|
||||||
TEST_SESSION_MESSAGE = 200;
|
TEST_SESSION_MESSAGE = 200;
|
||||||
|
|
||||||
|
|
@ -72,6 +73,7 @@ message ClientMessage {
|
||||||
optional MusicianSessionFresh musician_session_fresh = 115;
|
optional MusicianSessionFresh musician_session_fresh = 115;
|
||||||
optional MusicianSessionStale musician_session_stale = 116;
|
optional MusicianSessionStale musician_session_stale = 116;
|
||||||
optional HeartbeatAck heartbeat_ack = 117;
|
optional HeartbeatAck heartbeat_ack = 117;
|
||||||
|
optional SessionEnded session_ended = 118;
|
||||||
|
|
||||||
// Client-Session messages (to/from)
|
// Client-Session messages (to/from)
|
||||||
optional TestSessionMessage test_session_message = 200;
|
optional TestSessionMessage test_session_message = 200;
|
||||||
|
|
@ -278,7 +280,7 @@ message FriendUpdate {
|
||||||
// route_to: user:[USER_ID]
|
// route_to: user:[USER_ID]
|
||||||
// let a user know they've been invited to a session
|
// let a user know they've been invited to a session
|
||||||
message SessionInvitation {
|
message SessionInvitation {
|
||||||
optional string sender_id = 1;
|
optional string sender_name = 1;
|
||||||
optional string session_id = 2;
|
optional string session_id = 2;
|
||||||
optional string notification_id = 3;
|
optional string notification_id = 3;
|
||||||
optional string created_at = 4;
|
optional string created_at = 4;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ module NotificationTypes
|
||||||
|
|
||||||
# session notifications
|
# session notifications
|
||||||
SESSION_INVITATION = "SESSION_INVITATION"
|
SESSION_INVITATION = "SESSION_INVITATION"
|
||||||
|
SESSION_ENDED = "SESSION_ENDED" # used to remove session-related notification from sidebar
|
||||||
|
|
||||||
# musician notifications
|
# musician notifications
|
||||||
MUSICIAN_SESSION_JOIN = "MUSICIAN_SESSION_JOIN"
|
MUSICIAN_SESSION_JOIN = "MUSICIAN_SESSION_JOIN"
|
||||||
|
|
|
||||||
|
|
@ -137,8 +137,8 @@
|
||||||
return Jampb::ClientMessage.new(:type => ClientMessage::Type::TEST_SESSION_MESSAGE, :route_to => SESSION_TARGET_PREFIX + session_id, :test_session_message => test)
|
return Jampb::ClientMessage.new(:type => ClientMessage::Type::TEST_SESSION_MESSAGE, :route_to => SESSION_TARGET_PREFIX + session_id, :test_session_message => test)
|
||||||
end
|
end
|
||||||
|
|
||||||
def session_invitation(receiver_id, sender_id, session_id, notification_id, created_at)
|
def session_invitation(receiver_id, sender_name, session_id, notification_id, created_at)
|
||||||
session_invitation = Jampb::SessionInvitation.new(:sender_id => sender_id, :session_id => session_id, :notification_id => notification_id, :created_at => created_at)
|
session_invitation = Jampb::SessionInvitation.new(:sender_name => sender_name, :session_id => session_id, :notification_id => notification_id, :created_at => created_at)
|
||||||
return Jampb::ClientMessage.new(:type => ClientMessage::Type::SESSION_INVITATION, :route_to => USER_TARGET_PREFIX + receiver_id, :session_invitation => session_invitation)
|
return Jampb::ClientMessage.new(:type => ClientMessage::Type::SESSION_INVITATION, :route_to => USER_TARGET_PREFIX + receiver_id, :session_invitation => session_invitation)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -201,18 +201,18 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
################## SESSION INVITATION ##################
|
################## SESSION INVITATION ##################
|
||||||
def send_session_invitation(receiver_id, sender_id, session_id)
|
def send_session_invitation(receiver_id, sender, session_id)
|
||||||
|
|
||||||
# (1) save to database
|
# (1) save to database
|
||||||
notification = Notification.new
|
notification = Notification.new
|
||||||
notification.description = NotificationTypes::SESSION_INVITATION
|
notification.description = NotificationTypes::SESSION_INVITATION
|
||||||
notification.source_user_id = sender_id
|
notification.source_user_id = sender.id
|
||||||
notification.target_user_id = receiver_id
|
notification.target_user_id = receiver_id
|
||||||
notification.session_id = session_id
|
notification.session_id = session_id
|
||||||
notification.save
|
notification.save
|
||||||
|
|
||||||
# (2) create notification
|
# (2) create notification
|
||||||
msg = @@message_factory.session_invitation(receiver_id, sender_id, session_id, notification.id, notification.created_at.to_s)
|
msg = @@message_factory.session_invitation(receiver_id, sender.name, session_id, notification.id, notification.created_at.to_s)
|
||||||
|
|
||||||
# (3) send notification
|
# (3) send notification
|
||||||
@@mq_router.publish_to_user(receiver_id, msg)
|
@@mq_router.publish_to_user(receiver_id, msg)
|
||||||
|
|
@ -224,6 +224,7 @@ module JamRuby
|
||||||
msg = @@message_factory.musician_session_join(music_session.id, user.id, user.name, user.photo_url)
|
msg = @@message_factory.musician_session_join(music_session.id, user.id, user.name, user.photo_url)
|
||||||
|
|
||||||
# (2) send notification
|
# (2) send notification
|
||||||
|
puts "CONNECTION.CLIENT_ID=#{connection.client_id}"
|
||||||
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
|
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,7 +146,6 @@
|
||||||
);
|
);
|
||||||
|
|
||||||
sessionModel.subscribe('sessionScreen', sessionChanged);
|
sessionModel.subscribe('sessionScreen', sessionChanged);
|
||||||
logger.debug("sessionId=" + sessionId);
|
|
||||||
sessionModel.joinSession(sessionId)
|
sessionModel.joinSession(sessionId)
|
||||||
.fail(function(xhr, textStatus, errorMessage) {
|
.fail(function(xhr, textStatus, errorMessage) {
|
||||||
if(xhr.status == 404) {
|
if(xhr.status == 404) {
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,6 @@
|
||||||
context.JK.Sidebar = function(app) {
|
context.JK.Sidebar = function(app) {
|
||||||
var logger = context.JK.logger;
|
var logger = context.JK.logger;
|
||||||
var friends = [];
|
var friends = [];
|
||||||
var notifications = [];
|
|
||||||
var invitationDialog = new context.JK.InvitationDialog(app);
|
var invitationDialog = new context.JK.InvitationDialog(app);
|
||||||
var rest = context.JK.Rest();
|
var rest = context.JK.Rest();
|
||||||
|
|
||||||
|
|
@ -111,8 +110,7 @@
|
||||||
url: url,
|
url: url,
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
|
|
||||||
notifications = response;
|
|
||||||
updateNotificationList(response);
|
updateNotificationList(response);
|
||||||
|
|
||||||
// set notification count
|
// set notification count
|
||||||
|
|
@ -127,8 +125,6 @@
|
||||||
|
|
||||||
$.each(response, function(index, val) {
|
$.each(response, function(index, val) {
|
||||||
|
|
||||||
notifications[val.notification_id] = val;
|
|
||||||
|
|
||||||
// fill in template for Connect pre-click
|
// fill in template for Connect pre-click
|
||||||
var template = $('#template-notification-panel').html();
|
var template = $('#template-notification-panel').html();
|
||||||
var notificationHtml = context.JK.fillTemplate(template, {
|
var notificationHtml = context.JK.fillTemplate(template, {
|
||||||
|
|
@ -146,24 +142,26 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function initializeActions(payload, type) {
|
function initializeActions(payload, type) {
|
||||||
// wire up "x" button to delete notification
|
|
||||||
$('li[notification-id=' + payload.notification_id + ']').find('#img-delete-notification').click(deleteNotificationHandler);
|
|
||||||
|
|
||||||
|
var $notification = $('li[notification-id=' + payload.notification_id + ']');
|
||||||
|
|
||||||
|
// wire up "x" button to delete notification
|
||||||
|
$notification.find('#img-delete-notification').click(deleteNotificationHandler);
|
||||||
if (type === context.JK.MessageType.FRIEND_REQUEST) {
|
if (type === context.JK.MessageType.FRIEND_REQUEST) {
|
||||||
var $action_btn = $('li[notification-id=' + payload.notification_id + ']').find('#btn-notification-action');
|
var $action_btn = .find('#btn-notification-action');
|
||||||
$action_btn.text('ACCEPT');
|
$action_btn.text('ACCEPT');
|
||||||
$action_btn.click(function() {
|
$action_btn.click(function() {
|
||||||
acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id });
|
acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
else if (type === context.JK.MessageType.FRIEND_REQUEST_ACCEPTED) {
|
else if (type === context.JK.MessageType.FRIEND_REQUEST_ACCEPTED) {
|
||||||
$('li[notification-id=' + payload.notification_id + ']').find('#div-actions').hide();
|
$notification.find('#div-actions').hide();
|
||||||
}
|
}
|
||||||
else if (type === context.JK.MessageType.SESSION_INVITATION) {
|
else if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||||
var $action_btn = $('li[notification-id=' + payload.notification_id + ']').find('#btn-notification-action');
|
var $action_btn = $notification.find('#btn-notification-action');
|
||||||
$action_btn.text('JOIN');
|
$action_btn.text('JOIN');
|
||||||
$action_btn.click(function() {
|
$action_btn.click(function() {
|
||||||
joinSession({ "session_id": payload.session_d, "notification_id": payload.notification_id });
|
joinSession({ "session_id": payload.session_id, "notification_id": payload.notification_id });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -183,7 +181,6 @@
|
||||||
url: url,
|
url: url,
|
||||||
processData: false,
|
processData: false,
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
delete notifications[notificationId];
|
|
||||||
$('li[notification-id=' + notificationId + ']').hide();
|
$('li[notification-id=' + notificationId + ']').hide();
|
||||||
decrementNotificationCount();
|
decrementNotificationCount();
|
||||||
},
|
},
|
||||||
|
|
@ -328,33 +325,18 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
function joinSession(args) {
|
function joinSession(args) {
|
||||||
logger.debug("Joining session " + args.session_id);
|
|
||||||
context.location = "#/session/" + args.session_id;
|
context.location = "#/session/" + args.session_id;
|
||||||
|
deleteNotification(args.notification_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// default handler for incoming notification
|
// default handler for incoming notification
|
||||||
function handleNotification(payload, type) {
|
function handleNotification(payload, type) {
|
||||||
var sidebarText;
|
var sidebarText;
|
||||||
if (type === context.JK.MessageType.SESSION_INVITATION) {
|
if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||||
sidebarText = "You have been invited to a session.";
|
sidebarText = payload.sender_name + " has invited you to a session.";
|
||||||
// update notifications panel in sidebar
|
|
||||||
notifications[payload.notification_id] = {
|
|
||||||
"id": payload.notification_id,
|
|
||||||
"session_id": payload.session_id,
|
|
||||||
"formatted_msg": sidebarText,
|
|
||||||
"created_at": context.JK.formatDate(payload.created_at)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sidebarText = payload.msg;
|
sidebarText = payload.msg;
|
||||||
|
|
||||||
// update notifications panel in sidebar
|
|
||||||
notifications[payload.notification_id] = {
|
|
||||||
"id": payload.notification_id,
|
|
||||||
"photo_url": payload.photo_url,
|
|
||||||
"formatted_msg": sidebarText,
|
|
||||||
"created_at": context.JK.formatDate(payload.created_at)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
incrementNotificationCount();
|
incrementNotificationCount();
|
||||||
|
|
@ -541,7 +523,9 @@
|
||||||
participantHtml += "<table><tbody>";
|
participantHtml += "<table><tbody>";
|
||||||
|
|
||||||
$.each(participants, function(index, val) {
|
$.each(participants, function(index, val) {
|
||||||
|
if (index < 4) {
|
||||||
participantHtml += "<tr><td><img class='avatar-small' src='" + val.photo_url + "' /></td><td>" + val.name + "</td></tr>";
|
participantHtml += "<tr><td><img class='avatar-small' src='" + val.photo_url + "' /></td><td>" + val.name + "</td></tr>";
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
participantHtml += "</tbody></table>";
|
participantHtml += "</tbody></table>";
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class ApiInvitationsController < ApiController
|
||||||
User.save_session_settings(current_user, music_session)
|
User.save_session_settings(current_user, music_session)
|
||||||
|
|
||||||
# send notification
|
# send notification
|
||||||
Notification.send_session_invitation(receiver.id, current_user.id, music_session.id)
|
Notification.send_session_invitation(receiver.id, current_user, music_session.id)
|
||||||
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
|
respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation)
|
||||||
|
|
||||||
else
|
else
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,7 @@ MusicSessionManager < BaseManager
|
||||||
|
|
||||||
# auto-join this user into the newly created session
|
# auto-join this user into the newly created session
|
||||||
as_musician = true
|
as_musician = true
|
||||||
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks) do |db_conn, connection|
|
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks)
|
||||||
if as_musician && music_session.musician_access
|
|
||||||
Notification.send_musician_session_join(music_session, connection, user)
|
|
||||||
Notification.send_friend_session_join(db_conn, connection, user)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
unless connection.errors.any?
|
unless connection.errors.any?
|
||||||
return_value = music_session
|
return_value = music_session
|
||||||
|
|
@ -106,8 +101,8 @@ MusicSessionManager < BaseManager
|
||||||
|
|
||||||
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks) do |db_conn, connection|
|
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks) do |db_conn, connection|
|
||||||
if as_musician && music_session.musician_access
|
if as_musician && music_session.musician_access
|
||||||
Notification.send_musician_session_join(music_session, connection, user)
|
|
||||||
Notification.send_friend_session_join(db_conn, connection, user)
|
Notification.send_friend_session_join(db_conn, connection, user)
|
||||||
|
Notification.send_musician_session_join(music_session, connection, user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue