VRFS-933 notification work

This commit is contained in:
Brian Smith 2014-01-04 17:02:47 -05:00
parent 071ab4c0e9
commit fab83707b7
16 changed files with 327 additions and 160 deletions

View File

@ -101,6 +101,7 @@ message ClientMessage {
optional SessionJoin session_join = 190;
optional SessionDepart session_depart = 195;
optional MusicianSessionJoin musician_session_join = 196;
optional BandSessionJoin band_session_join = 197;
// recording notifications
optional MusicianRecordingSaved musician_recording_saved = 200;
@ -112,7 +113,6 @@ message ClientMessage {
// band notifications
optional BandInvitation band_invitation = 225;
optional BandInvitationAccepted band_invitation_accepted = 230;
optional BandSessionJoin band_session_join = 235;
optional MusicianSessionFresh musician_session_fresh = 240;
optional MusicianSessionStale musician_session_stale = 245;
@ -289,6 +289,14 @@ message MusicianSessionJoin {
optional string created_at = 5;
}
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;
}
message MusicianRecordingSaved {
optional string recording_id = 1;
optional string photo_url = 2;
@ -316,7 +324,10 @@ message RecordingEnded {
}
message RecordingMasterMixComplete {
optional string recording_id = 1;
optional string msg = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
message BandInvitation {
@ -336,14 +347,6 @@ message BandInvitationAccepted {
optional string created_at = 5;
}
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;
}
// route_to: client:
// sent by server to let the rest of the participants know a client has become active again after going stale
message MusicianSessionFresh {

View File

@ -126,6 +126,24 @@
send_notification(email, subject, msg, unique_args)
end
def band_session_join(email, msg)
subject = "A band that you follow has joined a session"
unique_args = {:type => "band_session_join"}
send_notification(email, subject, msg, unique_args)
end
def musician_recording_saved(email, msg)
subject = msg
unique_args = {:type => "musician_recording_saved"}
send_notification(email, subject, msg, unique_args)
end
def band_recording_saved(email, msg)
subject = msg
unique_args = {:type => "band_recording_saved"}
send_notification(email, subject, msg, unique_args)
end
def band_invitation(email, msg)
subject = "You have been invited to join a band on JamKazam"
unique_args = {:type => "band_invitation"}
@ -138,12 +156,6 @@
send_notification(email, subject, msg, unique_args)
end
def band_session_join(email, msg)
subject = "A band that you follow has joined a session"
unique_args = {:type => "band_session_join"}
send_notification(email, subject, msg, unique_args)
end
def send_notification(email, subject, msg, unique_args)
@body = msg
sendgrid_category "Notification"

View File

@ -0,0 +1,3 @@
<% provide(:title, 'New Band Invitation') %>
<p><%= @body %></p>

View File

@ -0,0 +1,3 @@
<% provide(:title, 'Band Invitation Accepted') %>
<p><%= @body %></p>

View File

@ -0,0 +1,3 @@
<% provide(:title, 'New Band Recording') %>
<p><%= @body %></p>

View File

@ -0,0 +1,3 @@
<% provide(:title, 'New Musician Recording') %>
<p><%= @body %></p>

View File

@ -0,0 +1,3 @@
<% provide(:title, 'Recording Master Mix Completed') %>
<p><%= @body %></p>

View File

@ -389,6 +389,22 @@ module JamRuby
)
end
def band_session_join(receiver_id, session_id, photo_url, msg, notification_id, created_at)
band_session_join = Jampb::BandSessionJoin.new(
:session_id => session_id,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::BAND_SESSION_JOIN,
:route_to => USER_TARGET_PREFIX + receiver_id,
:band_session_join => band_session_join
)
end
def musician_recording_saved(receiver_id, recording_id, photo_url, msg, notification_id, created_at)
musician_recording_saved = Jampb::MusicianRecordingSaved.new(
:recording_id => recording_id,
@ -421,7 +437,7 @@ module JamRuby
)
end
def recording_started(photo_url, msg)
def recording_started(receiver_id, photo_url, msg)
recording_started = Jampb::RecordingStarted.new(
:photo_url => photo_url,
:msg => msg
@ -429,12 +445,12 @@ module JamRuby
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::RECORDING_STARTED,
:route_to => CLIENT_TARGET,
:route_to => USER_TARGET_PREFIX + receiver_id,
:recording_started => recording_started
)
end
def recording_ended(photo_url, msg)
def recording_ended(receiver_id, photo_url, msg)
recording_ended = Jampb::RecordingEnded.new(
:photo_url => photo_url,
:msg => msg
@ -442,7 +458,7 @@ module JamRuby
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::RECORDING_ENDED,
:route_to => CLIENT_TARGET,
:route_to => USER_TARGET_PREFIX + receiver_id,
:recording_ended => recording_ended
)
end
@ -485,22 +501,6 @@ module JamRuby
)
end
def band_session_join(session_id, photo_url, msg, notification_id, created_at)
band_session_join = Jampb::BandSessionJoin.new(
:session_id => session_id,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::BAND_SESSION_JOIN,
:route_to => USER_TARGET_PREFIX + receiver_id,
:band_session_join => band_session_join
)
end
# create a musician fresh session message
def musician_session_fresh(session_id, user_id, username, photo_url)
fresh = Jampb::MusicianSessionFresh.new(

View File

@ -151,6 +151,9 @@ module JamRuby
when NotificationTypes::MUSICIAN_SESSION_JOIN
return "#{name} is now in a session."
when NotificationTypes::BAND_SESSION_JOIN
return "#{band_name} is now in a session."
# recording notifications
when NotificationTypes::MUSICIAN_RECORDING_SAVED
@ -176,9 +179,6 @@ module JamRuby
when NotificationTypes::BAND_INVITATION_ACCEPTED
return "#{name} has accepted your band invitation to join #{band_name}."
when NotificationTypes::BAND_SESSION_JOIN
return "#{band_name} is now in a session."
else
return ""
end
@ -510,80 +510,189 @@ module JamRuby
end
end
def send_musician_recording_saved(recording, user)
def send_band_session_join(music_session, band)
ids = retrieve_friends_and_followers(connection, user_id)
# if the session is private, don't send any notifications
if music_session.musician_access || music_session.fan_access
notification = Notification.new
notification.description = NotificationTypes::MUSICIAN_RECORDING_SAVED
notification.source_user_id = user.id
notification.target_user_id = join_request.user.id
notification.session_id = music_session.id
notification.save
band_followers = BandFollower.where(:band_id => band.id)
notification_msg = format_msg(notification.description, user)
unless band_followers.empty?
notifications, online_followers, offline_followers = []
msg = @@message_factory.musician_recording_saved(
join_request.id,
music_session.id,
music_session.creator.name,
music_session.creator.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
band_followers.each do |bf|
if (bf.follower.musician && music_session.musician_access) || (!bf.follower.musician && music_session.fan_access)
notification = Notification.new
notification.band_id = band.id
notification.description = NotificationTypes::BAND_SESSION_JOIN
notification.target_user_id = receiver.id
notification.save
# notifications << notification
bf.follower.online ? online_followers << bf.follower : offline_followers << bf.follower
end
end
@@mq_router.publish_to_friends(ids, msg, sender = {:client_id => connection.client_id})
# this was throwing an error related to the split method. (activerecord-import gem)
# unless notifications.empty?
# Notification.import notifications
# end
notification_msg = format_msg(NotificationTypes::BAND_SESSION_JOIN, nil, band)
# send real-time notifications
unless online_followers.empty?
msg = @@message_factory.band_session_join(
receiver.id,
music_session.id,
band.name,
band.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_friends(online_followers.map! {|f| f.id}, msg, band.id)
end
# send email notifications
unless offline_followers.empty?
UserMailer.band_session_join(offline_followers.map! {|f| f.email}, msg)
end
end
end
end
def send_band_recording_saved(recording, user)
def send_musician_recording_saved(recording)
ids = retrieve_friends_and_followers(connection, user_id)
if music_session.musician_access || music_session.fan_access
notification = Notification.new
notification.description = NotificationTypes::MUSICIAN_RECORDING_SAVED
notification.source_user_id = user.id
notification.target_user_id = join_request.user.id
notification.session_id = music_session.id
notification.save
user = recording.owner
notification_msg = format_msg(notification.description, user)
friends = Friendship.where(:friend_id => user.id)
user_followers = UserFollower.where(:user_id => user.id)
msg = @@message_factory.band_recording_saved(
join_request.id,
music_session.id,
music_session.creator.name,
music_session.creator.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
friend_users = friends.map { |fu| fu.friend }
follower_users = user_followers.map { |uf| uf.follower }
friends_and_followers = friend_users.concat(follower_users)
@@mq_router.publish_to_friends(ids, msg, sender = {:client_id => connection.client_id})
unless friends_and_followers.empty?
friends_and_followers = friends_and_followers - music_session.users
notifications, online_ff, offline_ff = []
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.save
# notifications << notification
ff.online ? online_ff << ff : offline_ff << ff
end
# unless notifications.empty?
# Notification.import notifications
# end
notification_msg = format_msg(NotificationTypes::MUSICIAN_RECORDING_SAVED, user)
# send real-time notifications
online_followers.each do |of|
msg = @@message_factory.musician_recording_saved(
of.id,
recording.id,
user.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_user(of.id, notification_msg)
end
# send email notifications
unless offline_ff.empty?
UserMailer.musician_recording_saved(offline_ff.map! {|f| f.email}, msg)
end
end
end
end
def send_band_recording_saved(recording)
band_followers = BandFollower.where(:band_id => band.id)
band_followers.each do |bf|
notification = Notification.new
notification.description = NotificationTypes::BAND_RECORDING_SAVED
notification.band_id = band.id
notification.target_user_id = bf.follower.id
notification.recording_id = recording.id
notification.save
# notifications << notification
bf.follower.online ? online_followers << bf.follower : offline_followers << bf.follower
end
# this was throwing an error related to the split method. (activerecord-import gem)
# unless notifications.empty?
# Notification.import notifications
# end
notification_msg = format_msg(NotificationTypes::BAND_RECORDING_SAVED, nil, recording.band)
# send real-time notifications
online_followers.each do |of|
msg = @@message_factory.band_recording_saved(
of.id,
recording.id,
band.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_user(of.id, notification_msg)
end
# send email notifications
unless offline_followers.empty?
UserMailer.band_recording_saved(offline_followers.map! {|f| f.email}, msg)
end
end
def send_recording_started(music_session, connection, user)
notification_msg = format_msg(NotificationTypes::RECORDING_STARTED, user)
msg = @@message_factory.recording_started(
user.photo_url,
notification_msg
)
music_session.users.each do |musician|
if musician.id != user.id
msg = @@message_factory.recording_started(
musician.id,
user.photo_url,
notification_msg
)
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
@@mq_router.publish_to_user(musician.id, msg)
end
end
end
def send_recording_ended(music_session, connection, user)
notification_msg = format_msg(NotificationTypes::RECORDING_ENDED, user)
msg = @@message_factory.recording_ended(
user.photo_url,
notification_msg
)
music_session.users.each do |musician|
if musician.id != user.id
msg = @@message_factory.recording_ended(
musician.id,
user.photo_url,
notification_msg
)
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
@@mq_router.publish_to_user(musician.id, msg)
end
end
end
def send_recording_master_mix_complete(recording)
@ -646,58 +755,6 @@ module JamRuby
end
end
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
band_followers = BandFollower.where(:band_id => band.id)
unless band_followers.empty?
notifications, online_followers, offline_followers = []
band_followers.each do |bf|
if (bf.follower.musician && music_session.musician_access) || (!bf.follower.musician && music_session.fan_access)
notification = Notification.new
notification.band_id = band.id
notification.description = NotificationTypes::BAND_SESSION_JOIN
notification.target_user_id = receiver.id
notification.save
# notifications << notification
bf.follower.online ? online_followers << bf.follower : offline_followers << bf.follower
end
end
# this was throwing an error related to the split method. (activerecord-import gem)
# unless notifications.empty?
# Notification.import notifications
# end
notification_msg = format_msg(NotificationTypes::BAND_SESSION_JOIN, nil, band)
# send real-time notifications
unless online_followers.empty?
msg = @@message_factory.band_session_join(
receiver.id,
music_session.id,
band.name,
band.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_friends(online_followers.map! {|f| f.id}, msg, band.id)
end
# send email notifications
unless offline_followers.empty?
UserMailer.band_session_join(offline_followers.map! {|f| f.email}, msg)
end
end
end
end
def send_musician_session_fresh(music_session, client_id, user)
msg = @@message_factory.musician_session_fresh(

View File

@ -34,6 +34,7 @@
SESSION_JOIN : "SESSION_JOIN",
SESSION_DEPART : "SESSION_DEPART",
MUSICIAN_SESSION_JOIN : "MUSICIAN_SESSION_JOIN",
BAND_SESSION_JOIN : "BAND_SESSION_JOIN",
// recording notifications
MUSICIAN_RECORDING_SAVED : "MUSICIAN_RECORDING_SAVED",
@ -45,7 +46,6 @@
// band notifications
BAND_INVITATION : "BAND_INVITATION",
BAND_INVITATION_ACCEPTED : "BAND_INVITATION_ACCEPTED",
BAND_SESSION_JOIN : "BAND_SESSION_JOIN",
TEST_SESSION_MESSAGE : "TEST_SESSION_MESSAGE",
PING_REQUEST : "PING_REQUEST",

View File

@ -443,6 +443,7 @@
registerSessionJoin();
registerSessionDepart();
registerMusicianSessionJoin();
registerBandSessionJoin();
// recording notifications
registerMusicianRecordingSaved();
@ -454,7 +455,6 @@
// band notifications
registerBandInvitation();
registerBandInvitationAccepted();
registerBandSessionJoin();
// watch for Invite More Users events
$('#sidebar-div .btn-email-invitation').click(function() {
@ -608,7 +608,7 @@
}
function registerSessionEnded() {
// TODO: this should clean up all notifications related to this session
}
function registerJoinRequest() {
@ -695,8 +695,10 @@
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_DEPART, function(header, payload) {
logger.debug("Handling SESSION_DEPART msg " + JSON.stringify(payload));
if(payload.recording_id && context.JK.CurrentSessionModel.recordingModel.isRecording(payload.recording_id)) {
context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(payload.recording_id);
var recordingId = payload.recording_id;
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.",
@ -723,16 +725,84 @@
"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
}
});
});
}
function registerBandSessionJoin() {
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);
// TODO: add LISTEN button linking to session
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
}
});
});
}
function listenToSession(args) {
var sessionId = args.session_id;
}
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));
handleNotification(payload, header.type);
app.notify({
"title": "Musician Recording Saved",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
}, {
"ok_text": "LISTEN",
"ok_callback": listenToRecording,
"ok_callback_args": {
"recording_id": payload.recording_id
}
});
});
}
function registerBandRecordingSaved() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_RECORDING_SAVED, function(header, payload) {
logger.debug("Handling BAND_RECORDING_SAVED msg " + JSON.stringify(payload));
handleNotification(payload, header.type);
app.notify({
"title": "Band Recording Saved",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
}, {
"ok_text": "LISTEN",
"ok_callback": listenToRecording,
"ok_callback_args": {
"recording_id": payload.recording_id
}
});
});
}
function listenToRecording(args) {
var recordingId = args.recording_id;
}
function registerRecordingStarted() {
@ -760,7 +830,27 @@
}
function registerRecordingMasterMixComplete() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_MASTER_MIX_COMPLETE, function(header, payload) {
logger.debug("Handling RECORDING_MASTER_MIX_COMPLETE msg " + JSON.stringify(payload));
handleNotification(payload, header.type);
app.notify({
"title": "Recording Master Mix Complete",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
}, {
"ok_text": "SHARE",
"ok_callback": shareRecording,
"ok_callback_args": {
"recording_id": payload.recording_id
}
});
});
}
function shareRecording(args) {
var recordingId = args.recording_id;
}
function registerBandInvitation() {
@ -809,21 +899,6 @@
});
}
function registerBandSessionJoin() {
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);
// TODO: add LISTEN button linking to session
app.notify({
"title": "Band Joined Session",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
this.initialize = function(invitationDialogInstance) {
events();
initializeFriendsPanel();