VRFS-759 VRFS-1221 delete session notifications when session ends in db and sidebar, fix listen button for sessions and recordings
This commit is contained in:
parent
0a2da28ae4
commit
83b4260b91
|
|
@ -252,7 +252,7 @@ message SessionInvitation {
|
|||
}
|
||||
|
||||
message SessionEnded {
|
||||
|
||||
optional string session_id = 1;
|
||||
}
|
||||
|
||||
message JoinRequest {
|
||||
|
|
|
|||
|
|
@ -300,6 +300,18 @@ module JamRuby
|
|||
)
|
||||
end
|
||||
|
||||
def session_ended(receiver_id, session_id)
|
||||
session_ended = Jampb::SessionEnded.new(
|
||||
:session_id => session_id
|
||||
)
|
||||
|
||||
Jampb::ClientMessage.new(
|
||||
:type => ClientMessage::Type::SESSION_ENDED,
|
||||
:route_to => USER_TARGET_PREFIX + receiver_id,
|
||||
:session_ended => session_ended
|
||||
)
|
||||
end
|
||||
|
||||
# create a join request session message
|
||||
def join_request(join_request_id, session_id, photo_url, msg, notification_id, created_at)
|
||||
req = Jampb::JoinRequest.new(
|
||||
|
|
|
|||
|
|
@ -172,6 +172,10 @@ module JamRuby
|
|||
.first
|
||||
|
||||
hist.end_history if hist
|
||||
|
||||
puts "**************NOTIFICATION SESSION ENDED**************"
|
||||
|
||||
Notification.send_session_ended(session_id)
|
||||
end
|
||||
|
||||
def remove_non_alpha_num(token)
|
||||
|
|
|
|||
|
|
@ -47,10 +47,6 @@ module JamRuby
|
|||
@@mq_router = MQRouter.new
|
||||
@@message_factory = MessageFactory.new
|
||||
|
||||
def delete_all(session_id)
|
||||
Notification.delete_all "(session_id = '#{session_id}')"
|
||||
end
|
||||
|
||||
################### HELPERS ###################
|
||||
def retrieve_friends(connection, user_id)
|
||||
friend_ids = []
|
||||
|
|
@ -354,10 +350,19 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
def send_session_ended(music_session, connection)
|
||||
def send_session_ended(session_id)
|
||||
|
||||
# TODO: this should actually publish to all users who have a notification for this session
|
||||
@@mq_router.server_publish_to_session(music_session, nil, sender = {:client_id => connection.client_id})
|
||||
notifications = Notification.where(:session_id => session_id)
|
||||
|
||||
# publish to all users who have a notification for this session
|
||||
# TODO: do this in BULK or in async block
|
||||
notifications.each do |n|
|
||||
puts "*************SENDING SESSION_ENDED TO #{n.target_user_id}***************"
|
||||
msg = @@message_factory.session_ended(n.target_user_id, session_id)
|
||||
@@mq_router.publish_to_user(n.target_user_id, msg)
|
||||
end
|
||||
|
||||
Notification.delete_all "(session_id = '#{session_id}')"
|
||||
end
|
||||
|
||||
def send_join_request(music_session, join_request, text)
|
||||
|
|
@ -467,8 +472,8 @@ module JamRuby
|
|||
follower_users = user_followers.map { |uf| uf.user }
|
||||
friends_and_followers = friend_users.concat(follower_users).uniq
|
||||
|
||||
# remove anyone in the session
|
||||
friends_and_followers = friends_and_followers - music_session.users
|
||||
# remove anyone in the session and invited musicians
|
||||
friends_and_followers = friends_and_followers - music_session.users - music_session.invited_musicians
|
||||
notifications, online_ff, offline_ff = [], [], []
|
||||
notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, user)
|
||||
|
||||
|
|
@ -478,6 +483,7 @@ module JamRuby
|
|||
notification.description = NotificationTypes::MUSICIAN_SESSION_JOIN
|
||||
notification.source_user_id = user.id
|
||||
notification.target_user_id = ff.id
|
||||
notification.session_id = music_session.id
|
||||
notification.save
|
||||
|
||||
if ff.online
|
||||
|
|
@ -519,6 +525,7 @@ module JamRuby
|
|||
notification.band_id = band.id
|
||||
notification.description = NotificationTypes::BAND_SESSION_JOIN
|
||||
notification.target_user_id = follower.id
|
||||
notification.session_id = music_session.id
|
||||
notification.save
|
||||
|
||||
if follower.online
|
||||
|
|
@ -562,9 +569,10 @@ module JamRuby
|
|||
|
||||
friends_and_followers.each do |ff|
|
||||
notification = Notification.new
|
||||
notification.description = NotificationTypes::MUSICIAN_SESSION_JOIN
|
||||
notification.description = NotificationTypes::MUSICIAN_RECORDING_SAVED
|
||||
notification.source_user_id = user.id
|
||||
notification.target_user_id = ff.id
|
||||
notification.recording_id = recording.id
|
||||
notification.save
|
||||
|
||||
if ff.online
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@
|
|||
var template = $('#template-notification-panel').html();
|
||||
var notificationHtml = context.JK.fillTemplate(template, {
|
||||
notificationId: val.notification_id,
|
||||
sessionId: val.sessionId,
|
||||
avatar_url: context.JK.resolveAvatarUrl(val.photo_url),
|
||||
text: val.formatted_msg,
|
||||
date: context.JK.formatDateTime(val.created_at)
|
||||
|
|
@ -158,13 +159,14 @@
|
|||
function initializeActions(payload, type) {
|
||||
|
||||
var $notification = $('li[notification-id=' + payload.notification_id + ']');
|
||||
var $btnNotificationAction = '#btn-notification-action';
|
||||
|
||||
// wire up "x" button to delete notification
|
||||
$notification.find('#img-delete-notification').click(deleteNotificationHandler);
|
||||
|
||||
// customize action buttons based on notification type
|
||||
if (type === context.JK.MessageType.FRIEND_REQUEST) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('ACCEPT');
|
||||
$action_btn.click(function() {
|
||||
acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -180,7 +182,7 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.SESSION_INVITATION) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('JOIN');
|
||||
$action_btn.click(function() {
|
||||
openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -188,7 +190,7 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.JOIN_REQUEST) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('APPROVE');
|
||||
$action_btn.click(function() {
|
||||
approveJoinRequest({ "join_request_id": payload.join_request_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -196,7 +198,7 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.JOIN_REQUEST_APPROVED) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('JOIN');
|
||||
$action_btn.click(function() {
|
||||
openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -208,15 +210,17 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.MUSICIAN_SESSION_JOIN || type === context.JK.MessageType.BAND_SESSION_JOIN) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('LISTEN');
|
||||
$action_btn.attr('href', '/sessions/' + payload.session_id);
|
||||
$action_btn.attr('rel', 'external');
|
||||
$action_btn.click(function() {
|
||||
listenToSession({ "session_id": payload.session_id, "notification_id": payload.notification_id });
|
||||
});
|
||||
}
|
||||
|
||||
else if (type === context.JK.MessageType.MUSICIAN_RECORDING_SAVED || type === context.JK.MessageType.BAND_RECORDING_SAVED) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('LISTEN');
|
||||
$action_btn.click(function() {
|
||||
listenToRecording({ "recording_id": payload.recording_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -229,7 +233,7 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.BAND_INVITATION) {
|
||||
var $action_btn = $notification.find('#btn-notification-action');
|
||||
var $action_btn = $notification.find($btnNotificationAction);
|
||||
$action_btn.text('ACCEPT');
|
||||
$action_btn.click(function() {
|
||||
acceptBandInvitation({ "band_invitation_id": payload.band_invitation_id, "band_id": payload.band_id, "notification_id": payload.notification_id });
|
||||
|
|
@ -335,6 +339,7 @@
|
|||
var template = $("#template-notification-panel").html();
|
||||
var notificationHtml = context.JK.fillTemplate(template, {
|
||||
notificationId: payload.notification_id,
|
||||
sessionId: payload.session_id,
|
||||
avatar_url: context.JK.resolveAvatarUrl(payload.photo_url),
|
||||
text: sidebarText,
|
||||
date: context.JK.formatDateTime(payload.created_at)
|
||||
|
|
@ -592,6 +597,17 @@
|
|||
|
||||
function registerSessionEnded() {
|
||||
// TODO: this should clean up all notifications related to this session
|
||||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_ENDED, function(header, payload) {
|
||||
logger.debug("Handling SESSION_ENDED msg " + JSON.stringify(payload));
|
||||
deleteSessionNotifications(payload.session_id);
|
||||
});
|
||||
}
|
||||
|
||||
// remove all notifications for this session
|
||||
function deleteSessionNotifications(sessionId) {
|
||||
console.log("sessionId=%o", sessionId);
|
||||
$('li[session-id=' + sessionId + ']').hide();
|
||||
decrementNotificationCount();
|
||||
}
|
||||
|
||||
function registerJoinRequest() {
|
||||
|
|
@ -680,13 +696,8 @@
|
|||
|
||||
var recordingId = payload.recording_id;
|
||||
|
||||
if(recordingId&& context.JK.CurrentSessionModel.recordingModel.isRecording(recordingId)) {
|
||||
if(recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(recordingId)) {
|
||||
context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(recordingId);
|
||||
/**app.notify({
|
||||
"title": "Recording Stopped",
|
||||
"text": payload.username + " has left the session.",
|
||||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
}); */
|
||||
}
|
||||
else {
|
||||
app.notify({
|
||||
|
|
@ -712,7 +723,8 @@
|
|||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToSession,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id
|
||||
"session_id": payload.session_id,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -733,7 +745,8 @@
|
|||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToSession,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id
|
||||
"session_id": payload.session_id,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -741,7 +754,7 @@
|
|||
|
||||
function listenToSession(args) {
|
||||
deleteNotification(args.notification_id);
|
||||
context.location = '/client#/session/' + args.session_id;
|
||||
context.JK.popExternalLink('/recordings/' + args.session_id);
|
||||
}
|
||||
|
||||
function registerMusicianRecordingSaved() {
|
||||
|
|
@ -758,7 +771,8 @@
|
|||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToRecording,
|
||||
"ok_callback_args": {
|
||||
"recording_id": payload.recording_id
|
||||
"recording_id": payload.recording_id,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -779,7 +793,8 @@
|
|||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToRecording,
|
||||
"ok_callback_args": {
|
||||
"recording_id": payload.recording_id
|
||||
"recording_id": payload.recording_id,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -787,7 +802,7 @@
|
|||
|
||||
function listenToRecording(args) {
|
||||
deleteNotification(args.notification_id);
|
||||
context.location = '/client#/recording/' + args.recording_id;
|
||||
context.JK.popExternalLink('/recordings/' + args.recording_id);
|
||||
}
|
||||
|
||||
function registerRecordingStarted() {
|
||||
|
|
|
|||
|
|
@ -549,6 +549,22 @@
|
|||
});
|
||||
}
|
||||
|
||||
context.JK.popExternalLink = function(href) {
|
||||
if(!context.jamClient) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (href) {
|
||||
// make absolute if not already
|
||||
if(href.indexOf('http') != 0 && href.indexOf('mailto') != 0) {
|
||||
href = window.location.protocol + '//' + window.location.host + href;
|
||||
}
|
||||
|
||||
context.jamClient.OpenSystemBrowser(href);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
context.JK.checkbox = function($checkbox) {
|
||||
$checkbox.iCheck({
|
||||
checkboxClass: 'icheckbox_minimal',
|
||||
|
|
|
|||
|
|
@ -198,7 +198,7 @@
|
|||
|
||||
<!-- Notification panel template -->
|
||||
<script type="text/template" id="template-notification-panel">
|
||||
<li notification-id="{notificationId}">
|
||||
<li session-id="{sessionId}" notification-id="{notificationId}">
|
||||
<div class="avatar-small"><img src="{avatar_url}" /></div>
|
||||
<div class="note-text">
|
||||
{text}
|
||||
|
|
|
|||
Loading…
Reference in New Issue