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_STALE = 116;
|
||||
HEARTBEAT_ACK = 117;
|
||||
SESSION_ENDED = 118;
|
||||
|
||||
TEST_SESSION_MESSAGE = 200;
|
||||
|
||||
|
|
@ -72,6 +73,7 @@ message ClientMessage {
|
|||
optional MusicianSessionFresh musician_session_fresh = 115;
|
||||
optional MusicianSessionStale musician_session_stale = 116;
|
||||
optional HeartbeatAck heartbeat_ack = 117;
|
||||
optional SessionEnded session_ended = 118;
|
||||
|
||||
// Client-Session messages (to/from)
|
||||
optional TestSessionMessage test_session_message = 200;
|
||||
|
|
@ -278,7 +280,7 @@ message FriendUpdate {
|
|||
// route_to: user:[USER_ID]
|
||||
// let a user know they've been invited to a session
|
||||
message SessionInvitation {
|
||||
optional string sender_id = 1;
|
||||
optional string sender_name = 1;
|
||||
optional string session_id = 2;
|
||||
optional string notification_id = 3;
|
||||
optional string created_at = 4;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ module NotificationTypes
|
|||
|
||||
# session notifications
|
||||
SESSION_INVITATION = "SESSION_INVITATION"
|
||||
SESSION_ENDED = "SESSION_ENDED" # used to remove session-related notification from sidebar
|
||||
|
||||
# musician notifications
|
||||
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)
|
||||
end
|
||||
|
||||
def session_invitation(receiver_id, sender_id, 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)
|
||||
def session_invitation(receiver_id, sender_name, session_id, notification_id, 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)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -201,18 +201,18 @@ module JamRuby
|
|||
end
|
||||
|
||||
################## 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
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::SESSION_INVITATION
|
||||
notification.source_user_id = sender_id
|
||||
notification.source_user_id = sender.id
|
||||
notification.target_user_id = receiver_id
|
||||
notification.session_id = session_id
|
||||
notification.save
|
||||
|
||||
# (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
|
||||
@@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)
|
||||
|
||||
# (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})
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -146,7 +146,6 @@
|
|||
);
|
||||
|
||||
sessionModel.subscribe('sessionScreen', sessionChanged);
|
||||
logger.debug("sessionId=" + sessionId);
|
||||
sessionModel.joinSession(sessionId)
|
||||
.fail(function(xhr, textStatus, errorMessage) {
|
||||
if(xhr.status == 404) {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
context.JK.Sidebar = function(app) {
|
||||
var logger = context.JK.logger;
|
||||
var friends = [];
|
||||
var notifications = [];
|
||||
var invitationDialog = new context.JK.InvitationDialog(app);
|
||||
var rest = context.JK.Rest();
|
||||
|
||||
|
|
@ -111,8 +110,7 @@
|
|||
url: url,
|
||||
processData: false,
|
||||
success: function(response) {
|
||||
|
||||
notifications = response;
|
||||
|
||||
updateNotificationList(response);
|
||||
|
||||
// set notification count
|
||||
|
|
@ -127,8 +125,6 @@
|
|||
|
||||
$.each(response, function(index, val) {
|
||||
|
||||
notifications[val.notification_id] = val;
|
||||
|
||||
// fill in template for Connect pre-click
|
||||
var template = $('#template-notification-panel').html();
|
||||
var notificationHtml = context.JK.fillTemplate(template, {
|
||||
|
|
@ -146,24 +142,26 @@
|
|||
}
|
||||
|
||||
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) {
|
||||
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.click(function() {
|
||||
acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id });
|
||||
});
|
||||
}
|
||||
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) {
|
||||
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.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,
|
||||
processData: false,
|
||||
success: function(response) {
|
||||
delete notifications[notificationId];
|
||||
$('li[notification-id=' + notificationId + ']').hide();
|
||||
decrementNotificationCount();
|
||||
},
|
||||
|
|
@ -328,33 +325,18 @@
|
|||
}
|
||||
|
||||
function joinSession(args) {
|
||||
logger.debug("Joining session " + args.session_id);
|
||||
context.location = "#/session/" + args.session_id;
|
||||
deleteNotification(args.notification_id);
|
||||
}
|
||||
|
||||
// default handler for incoming notification
|
||||
function handleNotification(payload, type) {
|
||||
var sidebarText;
|
||||
if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||
sidebarText = "You have been invited 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)
|
||||
};
|
||||
sidebarText = payload.sender_name + " has invited you to a session.";
|
||||
}
|
||||
else {
|
||||
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();
|
||||
|
|
@ -541,7 +523,9 @@
|
|||
participantHtml += "<table><tbody>";
|
||||
|
||||
$.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 += "</tbody></table>";
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class ApiInvitationsController < ApiController
|
|||
User.save_session_settings(current_user, music_session)
|
||||
|
||||
# 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)
|
||||
|
||||
else
|
||||
|
|
|
|||
|
|
@ -45,12 +45,7 @@ MusicSessionManager < BaseManager
|
|||
|
||||
# auto-join this user into the newly created session
|
||||
as_musician = true
|
||||
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
|
||||
Notification.send_musician_session_join(music_session, connection, user)
|
||||
Notification.send_friend_session_join(db_conn, connection, user)
|
||||
end
|
||||
end
|
||||
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks)
|
||||
|
||||
unless connection.errors.any?
|
||||
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|
|
||||
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_musician_session_join(music_session, connection, user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue