VRFS-1243 VRFS-1310 fix join session notifications based on access level and user type
This commit is contained in:
parent
924bd082eb
commit
49269443da
|
|
@ -307,9 +307,12 @@ message TracksChanged {
|
|||
message MusicianSessionJoin {
|
||||
optional string session_id = 1;
|
||||
optional string photo_url = 2;
|
||||
optional string msg = 3;
|
||||
optional string notification_id = 4;
|
||||
optional string created_at = 5;
|
||||
optional bool fan_access = 3;
|
||||
optional bool musician_access = 4;
|
||||
optional bool approval_required = 5;
|
||||
optional string msg = 6;
|
||||
optional string notification_id = 7;
|
||||
optional string created_at = 8;
|
||||
}
|
||||
|
||||
message MusicianRecordingSaved {
|
||||
|
|
@ -370,9 +373,12 @@ message BandInvitationAccepted {
|
|||
message BandSessionJoin {
|
||||
optional string session_id = 1;
|
||||
optional string photo_url = 2;
|
||||
optional string msg = 3;
|
||||
optional string notification_id = 4;
|
||||
optional string created_at = 5;
|
||||
optional bool fan_access = 3;
|
||||
optional bool musician_access = 4;
|
||||
optional bool approval_required = 5;
|
||||
optional string msg = 6;
|
||||
optional string notification_id = 7;
|
||||
optional string created_at = 8;
|
||||
}
|
||||
|
||||
// route_to: client:
|
||||
|
|
|
|||
|
|
@ -413,11 +413,13 @@ module JamRuby
|
|||
)
|
||||
end
|
||||
|
||||
|
||||
def musician_session_join(receiver_id, session_id, photo_url, msg, notification_id, created_at)
|
||||
def musician_session_join(receiver_id, session_id, photo_url, fan_access, musician_access, approval_required, msg, notification_id, created_at)
|
||||
musician_session_join = Jampb::MusicianSessionJoin.new(
|
||||
:session_id => session_id,
|
||||
:photo_url => photo_url,
|
||||
:fan_access => fan_access,
|
||||
:musician_access => musician_access,
|
||||
:approval_required => approval_required,
|
||||
:msg => msg,
|
||||
:notification_id => notification_id,
|
||||
:created_at => created_at
|
||||
|
|
@ -430,10 +432,13 @@ module JamRuby
|
|||
)
|
||||
end
|
||||
|
||||
def band_session_join(receiver_id, session_id, photo_url, msg, notification_id, created_at)
|
||||
def band_session_join(receiver_id, session_id, photo_url, fan_access, musician_access, approval_required, msg, notification_id, created_at)
|
||||
band_session_join = Jampb::BandSessionJoin.new(
|
||||
:session_id => session_id,
|
||||
:photo_url => photo_url,
|
||||
:fan_access => fan_access,
|
||||
:musician_access => musician_access,
|
||||
:approval_required => approval_required,
|
||||
:msg => msg,
|
||||
:notification_id => notification_id,
|
||||
:created_at => created_at
|
||||
|
|
|
|||
|
|
@ -489,34 +489,36 @@ module JamRuby
|
|||
notifications, online_ff, offline_ff = [], [], []
|
||||
notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, user)
|
||||
|
||||
friends_and_followers.each do |ff|
|
||||
if (ff.musician && music_session.musician_access) || (!ff.musician && music_session.fan_access)
|
||||
notification = Notification.new
|
||||
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
|
||||
friends_and_followers.each do |ff|
|
||||
notification = Notification.new
|
||||
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
|
||||
msg = @@message_factory.musician_session_join(
|
||||
ff.id,
|
||||
music_session.id,
|
||||
user.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if ff.online
|
||||
puts "******************SENDING NOTIFICATION TO #{ff.name}******************"
|
||||
msg = @@message_factory.musician_session_join(
|
||||
ff.id,
|
||||
music_session.id,
|
||||
user.photo_url,
|
||||
music_session.fan_access,
|
||||
music_session.musician_access,
|
||||
music_session.approval_required,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
@@mq_router.publish_to_user(ff.id, msg)
|
||||
else
|
||||
offline_ff << ff
|
||||
end
|
||||
@@mq_router.publish_to_user(ff.id, msg)
|
||||
else
|
||||
offline_ff << ff
|
||||
end
|
||||
end
|
||||
|
||||
# send email notifications
|
||||
unless offline_ff.empty?
|
||||
if !offline_ff.empty? && music_session.fan_access
|
||||
begin
|
||||
UserMailer.musician_session_join(offline_ff.map! {|f| f.email}, notification_msg, music_session.id).deliver if APP_CONFIG.send_join_session_email_notifications
|
||||
rescue => e
|
||||
|
|
@ -529,40 +531,42 @@ module JamRuby
|
|||
def send_band_session_join(music_session, band)
|
||||
|
||||
# if the session is private, don't send any notifications
|
||||
if music_session.musician_access || music_session.fan_access
|
||||
if music_session.musician_access || music_session.fan_access
|
||||
|
||||
notifications, online_followers, offline_followers = [], [], []
|
||||
notification_msg = format_msg(NotificationTypes::BAND_SESSION_JOIN, nil, band)
|
||||
|
||||
band.followers.each do |bf|
|
||||
follower = bf.user
|
||||
if (follower.musician && music_session.musician_access) || (!follower.musician && music_session.fan_access)
|
||||
notification = Notification.new
|
||||
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
|
||||
notification = Notification.new
|
||||
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
|
||||
msg = @@message_factory.band_session_join(
|
||||
follower.id,
|
||||
music_session.id,
|
||||
band.photo_url,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
if follower.online
|
||||
puts "******************SENDING NOTIFICATION TO #{follower.name}******************"
|
||||
msg = @@message_factory.band_session_join(
|
||||
follower.id,
|
||||
music_session.id,
|
||||
band.photo_url,
|
||||
music_session.fan_access,
|
||||
music_session.musician_access,
|
||||
music_session.approval_required,
|
||||
notification_msg,
|
||||
notification.id,
|
||||
notification.created_at.to_s
|
||||
)
|
||||
|
||||
@@mq_router.publish_to_user(follower.id, msg)
|
||||
else
|
||||
offline_followers << follower
|
||||
end
|
||||
@@mq_router.publish_to_user(follower.id, msg)
|
||||
else
|
||||
offline_followers << follower
|
||||
end
|
||||
end
|
||||
|
||||
# send email notifications
|
||||
unless offline_followers.empty?
|
||||
if !offline_ff.empty? && music_session.fan_access
|
||||
UserMailer.band_session_join(offline_followers.map! {|f| f.email}, notification_msg, music_session.id).deliver if APP_CONFIG.send_join_session_email_notifications
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@
|
|||
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 });
|
||||
acceptFriendRequest(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -185,7 +185,7 @@
|
|||
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 });
|
||||
openTerms(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -193,7 +193,7 @@
|
|||
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 });
|
||||
approveJoinRequest(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +201,7 @@
|
|||
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 });
|
||||
openTerms(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -210,12 +210,33 @@
|
|||
}
|
||||
|
||||
else if (type === context.JK.MessageType.MUSICIAN_SESSION_JOIN || type === context.JK.MessageType.BAND_SESSION_JOIN) {
|
||||
|
||||
var actionText = '';
|
||||
var callback;
|
||||
if (context.JK.currentUserMusician) {
|
||||
// user is MUSICIAN; musician_access = TRUE
|
||||
if (payload.musician_access) {
|
||||
actionText = "JOIN";
|
||||
callback = joinSession;
|
||||
}
|
||||
// user is MUSICIAN; fan_access = TRUE
|
||||
else if (payload.fan_access) {
|
||||
actionText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// user is FAN; fan_access = TRUE
|
||||
if (payload.fan_access) {
|
||||
actionText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
|
||||
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.text(actionText);
|
||||
$action_btn.click(function() {
|
||||
listenToSession({ "session_id": payload.session_id, "notification_id": payload.notification_id });
|
||||
callback(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -223,7 +244,7 @@
|
|||
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 });
|
||||
listenToRecording(payload);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -236,7 +257,7 @@
|
|||
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 });
|
||||
acceptBandInvitation(payload);
|
||||
});
|
||||
}
|
||||
else if (type === context.JK.MessageType.BAND_INVITATION_ACCEPTED) {
|
||||
|
|
@ -606,7 +627,6 @@
|
|||
|
||||
// remove all notifications for this session
|
||||
function deleteSessionNotifications(sessionId) {
|
||||
console.log("sessionId=%o", sessionId);
|
||||
$('li[session-id=' + sessionId + ']').hide();
|
||||
decrementNotificationCount();
|
||||
}
|
||||
|
|
@ -714,20 +734,52 @@
|
|||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_SESSION_JOIN, function(header, payload) {
|
||||
logger.debug("Handling MUSICIAN_SESSION_JOIN msg " + JSON.stringify(payload));
|
||||
|
||||
handleNotification(payload, header.type);
|
||||
var okText = '';
|
||||
var showNotification = false;
|
||||
var callback;
|
||||
if (context.JK.currentUserMusician) {
|
||||
// user is MUSICIAN; musician_access = TRUE
|
||||
if (payload.musician_access) {
|
||||
showNotification = true;
|
||||
okText = "JOIN";
|
||||
callback = joinSession;
|
||||
}
|
||||
// user is MUSICIAN; fan_access = TRUE
|
||||
else if (payload.fan_access) {
|
||||
showNotification = true;
|
||||
okText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// user is FAN; fan_access = TRUE
|
||||
if (payload.fan_access) {
|
||||
showNotification = true;
|
||||
okText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
|
||||
app.notify({
|
||||
"title": "Musician Joined Session",
|
||||
"text": payload.msg,
|
||||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
}, {
|
||||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToSession,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id,
|
||||
"notification_id": payload.notification_id
|
||||
if (showNotification) {
|
||||
handleNotification(payload, header.type);
|
||||
|
||||
app.notify({
|
||||
"title": "Musician Joined Session",
|
||||
"text": payload.msg,
|
||||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
}, {
|
||||
"ok_text": okText,
|
||||
"ok_callback": callback,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id,
|
||||
"fan_access": payload.fan_access,
|
||||
"musician_access": payload.musician_access,
|
||||
"approval_required": payload.approval_required,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -735,20 +787,52 @@
|
|||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_SESSION_JOIN, function(header, payload) {
|
||||
logger.debug("Handling BAND_SESSION_JOIN msg " + JSON.stringify(payload));
|
||||
|
||||
handleNotification(payload, header.type);
|
||||
var okText = '';
|
||||
var showNotification = false;
|
||||
var callback;
|
||||
if (context.JK.currentUserMusician) {
|
||||
// user is MUSICIAN; musician_access = TRUE
|
||||
if (payload.musician_access) {
|
||||
showNotification = true;
|
||||
okText = "JOIN";
|
||||
callback = joinSession;
|
||||
}
|
||||
// user is MUSICIAN; fan_access = TRUE
|
||||
else if (payload.fan_access) {
|
||||
showNotification = true;
|
||||
okText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// user is FAN; fan_access = TRUE
|
||||
if (payload.fan_access) {
|
||||
showNotification = true;
|
||||
okText = "LISTEN";
|
||||
callback = listenToSession;
|
||||
}
|
||||
}
|
||||
|
||||
app.notify({
|
||||
"title": "Band Joined Session",
|
||||
"text": payload.msg,
|
||||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
}, {
|
||||
"ok_text": "LISTEN",
|
||||
"ok_callback": listenToSession,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id,
|
||||
"notification_id": payload.notification_id
|
||||
if (showNotification) {
|
||||
handleNotification(payload, header.type);
|
||||
|
||||
app.notify({
|
||||
"title": "Band Joined Session",
|
||||
"text": payload.msg,
|
||||
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
|
||||
}, {
|
||||
"ok_text": "LISTEN",
|
||||
"ok_callback": callback,
|
||||
"ok_callback_args": {
|
||||
"session_id": payload.session_id,
|
||||
"fan_access": payload.fan_access,
|
||||
"musician_access": payload.musician_access,
|
||||
"approval_required": payload.approval_required,
|
||||
"notification_id": payload.notification_id
|
||||
}
|
||||
}
|
||||
});
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -757,6 +841,43 @@
|
|||
context.JK.popExternalLink('/sessions/' + args.session_id);
|
||||
}
|
||||
|
||||
/*********** TODO: THE NEXT 3 FUNCTIONS ARE COPIED FROM sessionList.js. REFACTOR TO COMMON PLACE. *************/
|
||||
function joinSession(args) {
|
||||
// NOTE: invited musicians get their own notification, so no need to check if user has invitation here
|
||||
// like other places because an invited user would never get this notification
|
||||
if (args.musician_access) {
|
||||
if (args.approval_required) {
|
||||
openAlert(args.session_id);
|
||||
}
|
||||
else {
|
||||
openTerms(args);
|
||||
}
|
||||
}
|
||||
deleteNotification(args.notification_id);
|
||||
}
|
||||
|
||||
function openAlert(sessionId) {
|
||||
var alertDialog = new context.JK.AlertDialog(context.JK.app, "YES",
|
||||
"You must be approved to join this session. Would you like to send a request to join?",
|
||||
sessionId, onCreateJoinRequest);
|
||||
|
||||
alertDialog.initialize();
|
||||
context.JK.app.layout.showDialog('alert');
|
||||
}
|
||||
|
||||
function onCreateJoinRequest(sessionId) {
|
||||
var joinRequest = {};
|
||||
joinRequest.music_session = sessionId;
|
||||
joinRequest.user = context.JK.currentUserId;
|
||||
rest.createJoinRequest(joinRequest)
|
||||
.done(function(response) {
|
||||
|
||||
}).error(context.JK.app.ajaxError);
|
||||
|
||||
context.JK.app.layout.closeDialog('alert');
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function registerMusicianRecordingSaved() {
|
||||
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_RECORDING_SAVED, function(header, payload) {
|
||||
logger.debug("Handling MUSICIAN_RECORDING_SAVED msg " + JSON.stringify(payload));
|
||||
|
|
@ -776,7 +897,6 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function registerBandRecordingSaved() {
|
||||
|
|
|
|||
|
|
@ -97,10 +97,12 @@
|
|||
JK.currentUserId = '<%= current_user.id %>';
|
||||
JK.currentUserAvatarUrl = JK.resolveAvatarUrl('<%= current_user.photo_url %>');
|
||||
JK.currentUserName = '<%= current_user.name %>';
|
||||
JK.currentUserMusician = '<%= current_user.musician %>';
|
||||
<% else %>
|
||||
JK.currentUserId = null;
|
||||
JK.currentUserAvatarUrl = null;
|
||||
JK.currentUserName = null;
|
||||
JK.currentUserMusician = null;
|
||||
<% end %>
|
||||
|
||||
// Some things can't be initialized until we're connected. Put them here.
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ MusicSessionManager < BaseManager
|
|||
user.update_progression_field(:first_music_session_at)
|
||||
MusicSessionUserHistory.save(music_session.id, user.id, client_id, tracks)
|
||||
|
||||
|
||||
# only send this notification if it's a band session AND there is either fan or musician access
|
||||
unless band.nil?
|
||||
Notification.send_band_session_join(music_session, band)
|
||||
end
|
||||
|
|
@ -133,7 +133,7 @@ MusicSessionManager < BaseManager
|
|||
user.update_progression_field(:first_music_session_at)
|
||||
MusicSessionUserHistory.save(music_session_id, user.id, client_id, tracks)
|
||||
|
||||
if as_musician && music_session.musician_access
|
||||
if as_musician
|
||||
|
||||
# send to session participants
|
||||
Notification.send_session_join(music_session, connection, user)
|
||||
|
|
|
|||
Loading…
Reference in New Issue