VRFS-933 notification work

This commit is contained in:
Brian Smith 2014-01-02 14:57:16 -05:00
parent 452ddb3ff0
commit 3872898b95
17 changed files with 475 additions and 484 deletions

View File

@ -32,10 +32,9 @@ message ClientMessage {
JOIN_REQUEST = 175;
JOIN_REQUEST_APPROVED = 180;
JOIN_REQUEST_REJECTED = 185;
// musician notifications
MUSICIAN_SESSION_JOIN = 190;
MUSICIAN_SESSION_DEPART = 195;
SESSION_JOIN = 190;
SESSION_DEPART = 195;
MUSICIAN_SESSION_JOIN = 196;
// recording notifications
MUSICIAN_RECORDING_SAVED = 200;
@ -90,7 +89,6 @@ message ClientMessage {
optional FriendUpdate friend_update = 140; // from server to all friends of user
optional FriendRequest friend_request = 145;
optional FriendRequestAccepted friend_request_accepted = 150;
optional FriendSessionJoin friend_session_join = 155;
optional NewUserFollower new_user_follower = 160;
optional NewBandFollower new_band_follower = 161;
@ -100,10 +98,9 @@ message ClientMessage {
optional JoinRequest join_request = 175;
optional JoinRequestApproved join_request_approved = 180;
optional JoinRequestRejected join_request_rejected = 185;
// musician notifications
optional MusicianSessionJoin musician_session_join = 190;
optional MusicianSessionDepart musician_session_depart = 195;
optional SessionJoin session_join = 190;
optional SessionDepart session_depart = 195;
optional MusicianSessionJoin musician_session_join = 196;
// recording notifications
optional MusicianRecordingSaved musician_recording_saved = 200;
@ -197,70 +194,45 @@ message LeaveMusicSessionAck {
optional string error_reason = 2;
}
// target: client
// send from server to client when a user logs in
message FriendUpdate {
optional string user_id = 1;
optional string name = 2;
optional string photo_url = 3;
optional bool online = 4;
optional string msg = 5;
optional string photo_url = 2;
optional bool online = 3;
optional string msg = 4;
}
// target: client
// send from server to client when user sends a friend request
message FriendRequest {
optional string friend_request_id = 1;
optional string user_id = 2;
optional string name = 3;
optional string photo_url = 4;
optional string friend_id = 5;
optional string msg = 6;
optional string notification_id = 7;
optional string created_at = 8;
optional string photo_url = 2;
optional string msg = 3;
optional string notification_id = 4;
optional string created_at = 5;
}
// target: client
message FriendRequestAccepted {
optional string friend_id = 1; // accepter
optional string name = 2;
optional string photo_url = 3;
optional string user_id = 4; // original requester
optional string msg = 5;
optional string notification_id = 6;
optional string created_at = 7;
}
// route_to: client:
// sent by server to let the rest of the participants know a user has joined.
message FriendSessionJoin {
optional string session_id = 1; // the session ID
optional string user_id = 2; // this is the user_id and can be used for user unicast messages
optional string username = 3; // meant to be a display name
optional string photo_url = 4;
optional string photo_url = 1;
optional string msg = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
message NewUserFollower {
optional string name = 1;
optional string photo_url = 2;
optional string msg = 3;
optional string notification_id = 4;
optional string created_at = 5;
optional string photo_url = 1;
optional string msg = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
message NewBandFollower {
optional string name = 1;
optional string photo_url = 2;
optional string msg = 3;
optional string notification_id = 4;
optional string created_at = 5;
optional string photo_url = 1;
optional string msg = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
// route_to: user:[USER_ID]
// let a user know they've been invited to a session
message SessionInvitation {
optional string sender_name = 1;
optional string session_id = 2;
optional string session_id = 1;
optional string msg = 2;
optional string notification_id = 3;
optional string created_at = 4;
}
@ -272,50 +244,49 @@ message SessionEnded {
message JoinRequest {
optional string join_request_id = 1;
optional string session_id = 2;
optional string username = 3;
optional string photo_url = 4;
optional string msg = 5;
optional string notification_id = 6;
optional string created_at = 7;
optional string photo_url = 3;
optional string msg = 4;
optional string notification_id = 5;
optional string created_at = 6;
}
message JoinRequestApproved {
optional string join_request_id = 1;
optional string session_id = 2;
optional string username = 3;
optional string photo_url = 4;
optional string msg = 5;
optional string notification_id = 6;
optional string created_at = 7;
optional string photo_url = 3;
optional string msg = 4;
optional string notification_id = 5;
optional string created_at = 6;
}
message JoinRequestRejected {
optional string invitation_id = 1;
optional string session_id = 2;
optional string username = 3;
optional string photo_url = 4;
optional string msg = 5;
optional string notification_id = 6;
optional string created_at = 7;
optional string photo_url = 3;
optional string msg = 4;
optional string notification_id = 5;
optional string created_at = 6;
}
message SessionJoin {
optional string session_id = 1;
optional string photo_url = 2;
optional string msg = 3;
}
message SessionDepart {
optional string session_id = 1;
optional string photo_url = 2;
optional string msg = 3;
optional string recording_id = 4;
}
// route_to: client:
// sent by server to let the rest of the participants know a user has joined.
message MusicianSessionJoin {
optional string session_id = 1; // the session ID
optional string user_id = 2; // this is the user_id and can be used for user unicast messages
optional string username = 3; // meant to be a display name
optional string photo_url = 4;
}
// route_to: client:
// sent by server to let the rest of the participants know a user has left.
message MusicianSessionDepart {
optional string session_id = 1; // the session ID
optional string user_id = 2; // this is the user_id and can be used for user unicast messages
optional string username = 3; // meant to be a display name
optional string photo_url = 4;
optional string recordingId = 5; // if specified, the recording was stopped automatically
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 {
@ -327,11 +298,13 @@ message BandRecordingSaved {
}
message RecordingStarted {
optional string photo_url = 1;
optional string msg = 2;
}
message RecordingEnded {
optional string photo_url = 1;
optional string msg = 2;
}
message RecordingMasterMixComplete {
@ -341,35 +314,28 @@ message RecordingMasterMixComplete {
message BandInvitation {
optional string band_invitation_id = 1;
optional string band_id = 2;
optional string user_id = 3;
optional string username = 4;
optional string photo_url = 5;
optional string band_name = 6;
optional string msg = 7;
optional string notification_id = 8;
optional string created_at = 9;
}
message BandInvitationAccepted {
optional string band_invitation_id = 1;
optional string user_id = 2;
optional string username = 3;
optional string photo_url = 4;
optional string band_name = 5;
optional string msg = 6;
optional string notification_id = 7;
optional string created_at = 8;
}
message BandSessionJoin {
optional string session_id = 1;
optional string band_name = 2;
optional string photo_url = 3;
optional string msg = 4;
optional string notification_id = 5;
optional string created_at = 6;
}
message BandInvitationAccepted {
optional string band_invitation_id = 1;
optional string photo_url = 2;
optional string msg = 3;
optional string notification_id = 4;
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

@ -89,59 +89,65 @@
end
#################################### NOTIFICATION EMAILS ####################################
def friend_request(target_user, msg)
def friend_request(email, msg)
subject = "You have a new friend request on JamKazam"
unique_args = {:type => "friend_request"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def friend_request_accepted(target_user, msg)
def friend_request_accepted(email, msg)
subject = "You have a new friend on JamKazam"
unique_args = {:type => "friend_request_accepted"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def new_user_follower(target_user, msg)
def new_user_follower(email, msg)
subject = "You have a new follower on JamKazam"
unique_args = {:type => "new_user_follower"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def new_band_follower(target_user, msg)
def new_band_follower(email, msg)
subject = "Your band has a new follower on JamKazam"
unique_args = {:type => "new_band_follower"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def session_invitation(target_user, msg)
def session_invitation(email, msg)
subject = "You have been invited to a session on JamKazam"
unique_args = {:type => "session_invitation"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def musician_session_join(target_user)
def musician_session_join(email, msg)
subject = "Someone you know is in a session on JamKazam"
unique_args = {:type => "musician_session_join"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def band_invitation(target_user, msg)
def band_invitation(email, msg)
subject = "You have been invited to join a band on JamKazam"
unique_args = {:type => "band_invitation"}
send_notification(target_user, subject, msg, unique_args)
send_notification(email, subject, msg, unique_args)
end
def band_invitation_accepted(target_user, msg)
def band_invitation_accepted(email, msg)
subject = "Your band invitation was accepted"
unique_args = {:type => "band_invitation_accepted"}
send_notification(target_user, subject, msg, unique_args)
end
def send_notification(target_user, subject, msg, unique_args)
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"
sendgrid_unique_args :type => unique_args[:type]
mail(:to => target_user.email, :subject => subject) do |format|
mail(:bcc => email, :subject => subject) do |format|
format.text
format.html
end

View File

@ -14,10 +14,9 @@ module NotificationTypes
JOIN_REQUEST = "JOIN_REQUEST"
JOIN_REQUEST_APPROVED = "JOIN_REQUEST_APPROVED"
JOIN_REQUEST_REJECTED = "JOIN_REQUEST_REJECTED"
# musician notifications
SESSION_JOIN = "SESSION_JOIN"
SESSION_DEPART = "SESSION_DEPART"
MUSICIAN_SESSION_JOIN = "MUSICIAN_SESSION_JOIN"
MUSICIAN_SESSION_DEPART = "MUSICIAN_SESSION_DEPART"
# recording notifications
MUSICIAN_RECORDING_SAVED = "MUSICIAN_RECORDING_SAVED"

View File

@ -1,4 +1,4 @@
module JamRuby
module JamRuby
# creates messages (implementation: protocol buffer) objects cleanly
class MessageFactory
@ -197,10 +197,9 @@
###################################### NOTIFICATIONS ######################################
# create a friend update message
def friend_update(user_id, name, photo_url, online, msg)
def friend_update(user_id, photo_url, online, msg)
friend = Jampb::FriendUpdate.new(
:user_id => user_id,
:name => name,
:photo_url => photo_url,
:online => online,
:msg => msg
@ -214,13 +213,10 @@
end
# create a friend request message
def friend_request(friend_request_id, user_id, name, photo_url, friend_id, msg, notification_id, created_at)
def friend_request(receiver_id, friend_request_id, photo_url, msg, notification_id, created_at)
friend_request = Jampb::FriendRequest.new(
:friend_request_id => friend_request_id,
:user_id => user_id,
:name => name,
:photo_url => photo_url,
:friend_id => friend_id,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
@ -228,18 +224,15 @@
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::FRIEND_REQUEST,
:route_to => USER_TARGET_PREFIX + friend_id,
:route_to => USER_TARGET_PREFIX + receiver_id,
:friend_request => friend_request
)
end
# create a friend request acceptance message
def friend_request_accepted(friend_id, name, photo_url, user_id, msg, notification_id, created_at)
def friend_request_accepted(receiver_id, photo_url, msg, notification_id, created_at)
friend_request_accepted = Jampb::FriendRequestAccepted.new(
:friend_id => friend_id,
:name => name,
:photo_url => photo_url,
:user_id => user_id,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
@ -247,30 +240,13 @@
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::FRIEND_REQUEST_ACCEPTED,
:route_to => USER_TARGET_PREFIX + user_id,
:route_to => USER_TARGET_PREFIX + receiver_id,
:friend_request_accepted => friend_request_accepted
)
end
# create a friend joined session message
def friend_session_join(session_id, user_id, username, photo_url)
join = Jampb::FriendSessionJoin.new(
:session_id => session_id,
:user_id => user_id,
:username => username,
:photo_url => photo_url
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::FRIEND_SESSION_JOIN,
:route_to => CLIENT_TARGET,
:friend_session_join => join
)
end
def new_user_follower(receiver_id, follower_name, photo_url, msg, notification_id, created_at)
def new_user_follower(receiver_id, photo_url, msg, notification_id, created_at)
new_user_follower = Jampb::NewUserFollower.new(
:name => follower_name,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
@ -284,9 +260,8 @@
)
end
def new_band_follower(receiver_id, follower_name, photo_url, msg, notification_id, created_at)
def new_band_follower(receiver_id, photo_url, msg, notification_id, created_at)
new_band_follower = Jampb::NewBandFollower.new(
:name => follower_name,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
@ -300,43 +275,10 @@
)
end
# create a musician joined session message
def musician_session_join(session_id, user_id, username, photo_url)
join = Jampb::MusicianSessionJoin.new(
:session_id => session_id,
:user_id => user_id,
:username => username,
:photo_url => photo_url
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::MUSICIAN_SESSION_JOIN,
:route_to => CLIENT_TARGET,
:musician_session_join => join
)
end
# create a musician left session message
def musician_session_depart(session_id, user_id, username, photo_url, recordingId = nil)
left = Jampb::MusicianSessionDepart.new(
:session_id => session_id,
:user_id => user_id,
:username => username,
:photo_url => photo_url,
:recordingId => recordingId
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::MUSICIAN_SESSION_DEPART,
:route_to => CLIENT_TARGET,
:musician_session_depart => left
)
end
def session_invitation(receiver_id, sender_name, session_id, notification_id, created_at)
def session_invitation(receiver_id, session_id, msg, notification_id, created_at)
session_invitation = Jampb::SessionInvitation.new(
:sender_name => sender_name,
:session_id => session_id,
:session_id => session_id,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
)
@ -349,11 +291,10 @@
end
# create a join request session message
def join_request(join_request_id, session_id, username, photo_url, msg, notification_id, created_at)
def join_request(join_request_id, session_id, photo_url, msg, notification_id, created_at)
req = Jampb::JoinRequest.new(
:join_request_id => join_request_id,
:session_id => session_id,
:username => username,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
@ -368,11 +309,10 @@
end
# create a join request approved session message
def join_request_approved(join_request_id, session_id, username, photo_url, msg, notification_id, created_at)
def join_request_approved(join_request_id, session_id, photo_url, msg, notification_id, created_at)
req_approved = Jampb::JoinRequestApproved.new(
:join_request_id => join_request_id,
:session_id => session_id,
:username => username,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
@ -387,11 +327,10 @@
end
# create a join request rejected session message
def join_request_rejected(join_request_id, session_id, username, photo_url, msg, notification_id, created_at)
def join_request_rejected(join_request_id, session_id, photo_url, msg, notification_id, created_at)
req_rejected = Jampb::JoinRequestRejected.new(
:join_request_id => join_request_id,
:session_id => session_id,
:username => username,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,
@ -405,15 +344,92 @@
)
end
def session_join(session_id, photo_url, msg)
join = Jampb::SessionJoin.new(
:session_id => session_id,
:photo_url => photo_url,
:msg => msg
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::SESSION_JOIN,
:route_to => CLIENT_TARGET,
:session_join => join
)
end
def session_depart(session_id, photo_url, msg, recording_id = nil)
left = Jampb::SessionDepart.new(
:session_id => session_id,
:photo_url => photo_url,
:msg => msg,
:recording_id => recording_id
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::SESSION_DEPART,
:route_to => CLIENT_TARGET,
:session_depart => left
)
end
def musician_session_join(receiver_id, session_id, photo_url, msg, notification_id, created_at)
musician_session_join = Jampb::MusicianSessionJoin.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::MUSICIAN_SESSION_JOIN,
:route_to => USER_TARGET_PREFIX + receiver_id,
:musician_session_join => musician_session_join
)
end
def musician_recording_saved
end
def band_recording_saved
end
def recording_started(photo_url, msg)
recording_started = Jampb::RecordingStarted.new(
:photo_url => photo_url,
:msg => msg
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::RECORDING_STARTED,
:route_to => CLIENT_TARGET,
:recording_started => recording_started
)
end
def recording_ended(photo_url, msg)
recording_ended = Jampb::RecordingEnded.new(
:photo_url => photo_url,
:msg => msg
)
return Jampb::ClientMessage.new(
:type => ClientMessage::Type::RECORDING_ENDED,
:route_to => CLIENT_TARGET,
:recording_ended => recording_ended
)
end
def recording_master_mix_complete
end
# create a band invitation message
def band_invitation(invitation_id, band_id, receiver_id, username, photo_url, band_name, msg, notification_id, created_at)
def band_invitation(receiver_id, invitation_id, band_id, photo_url, msg, notification_id, created_at)
band_invitation = Jampb::BandInvitation.new(
:band_invitation_id => invitation_id,
:band_id => band_id,
:user_id => receiver_id,
:username => username,
:photo_url => photo_url,
:band_name => band_name,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
@ -427,13 +443,10 @@
end
# create a band invitation acceptance message
def band_invitation_accepted(invitation_id, receiver_id, username, photo_url, band_name, msg, notification_id, created_at)
def band_invitation_accepted(receiver_id, invitation_id, photo_url, msg, notification_id, created_at)
band_invitation_accepted = Jampb::BandInvitationAccepted.new(
:band_invitation_id => invitation_id,
:user_id => receiver_id,
:username => username,
:photo_url => photo_url,
:band_name => band_name,
:msg => msg,
:notification_id => notification_id,
:created_at => created_at
@ -446,10 +459,9 @@
)
end
def band_session_join(session_id, receiver_id, band_name, photo_url, msg, notification_id, created_at)
def band_session_join(session_id, photo_url, msg, notification_id, created_at)
band_session_join = Jampb::BandSessionJoin.new(
:session_id => session_id,
:band_name => band_name,
:photo_url => photo_url,
:msg => msg,
:notification_id => notification_id,

View File

@ -177,9 +177,9 @@ module JamRuby
end
# stops any active recording
def stop_recording
def stop_recording(user)
current_recording = self.recording
current_recording.stop unless current_recording.nil?
current_recording.stop(user) unless current_recording.nil?
end
def to_s

View File

@ -12,8 +12,7 @@ module JamRuby
belongs_to :recording, :class_name => "JamRuby::Recording", :foreign_key => "recording_id"
def index(user_id)
results = Notification.where(:target_user_id => user_id).limit(50)
return results
Notification.where(:target_user_id => user_id).limit(50)
end
def photo_url
@ -100,16 +99,6 @@ module JamRuby
return ids
end
def retrieve_band_followers(connection, band_id)
follower_ids = []
connection.exec("SELECT bf.follower_id as follower_id FROM bands_followers bf WHERE bf.band_id = $1", [band_id]) do |follower_results|
follower_results.each do |follower_result|
follower_ids.push(follower_result['follower_id'])
end
end
return follower_ids
end
def format_msg(description, user = nil, band = nil)
name = ""
unless user.nil?
@ -130,9 +119,6 @@ module JamRuby
when NotificationTypes::FRIEND_REQUEST_ACCEPTED
return "#{name} has accepted your friend request."
when NotificationTypes::FRIEND_SESSION_JOIN
return "#{name} has joined the session."
when NotificationTypes::NEW_USER_FOLLOWER
return "#{name} is now following you on JamKazam."
@ -152,14 +138,15 @@ module JamRuby
when NotificationTypes::JOIN_REQUEST_REJECTED
return "We're sorry, but you cannot join the session at this time."
when NotificationTypes::SESSION_JOIN
return "#{name} has joined the session."
when NotificationTypes::SESSION_DEPART
return "#{name} has left the session."
# musician notifications
when NotificationTypes::MUSICIAN_SESSION_JOIN
return "#{name} is now in a session."
when NotificationTypes::MUSICIAN_SESSION_DEPART
return "#{name} has left the session."
# recording notifications
when NotificationTypes::MUSICIAN_RECORDING_SAVED
@ -193,36 +180,30 @@ module JamRuby
end
end
################### FRIEND UPDATE ###################
def send_friend_update(user_id, online, connection)
# (1) get all of this user's friends
friend_ids = retrieve_friends(connection, user_id)
unless friend_ids.blank?
unless friend_ids.empty?
user = User.find(user_id)
# (2) create notification
online_msg = online ? "online." : "offline."
notification_msg = format_msg(NotificationTypes::FRIEND_UPDATE, user) + online_msg
msg = @@message_factory.friend_update(
user_id, user.name,
user.id,
user.photo_url,
online,
notification_msg
)
# (3) send notification
@@mq_router.publish_to_friends(friend_ids, msg, user_id)
end
end
################### FRIEND REQUEST ###################
def send_friend_request(friend_request_id, user_id, friend_id)
user = User.find(user_id)
friend = User.find(friend_id)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::FRIEND_REQUEST
notification.source_user_id = user_id
@ -232,33 +213,27 @@ module JamRuby
notification_msg = format_msg(notification.description, user)
# (2) create notification
if friend.online
msg = @@message_factory.friend_request(
friend_request_id,
user.id,
user.name,
user.photo_url,
friend.id,
friend_request_id,
user.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (2a) send notification if user is online
@@mq_router.publish_to_user(friend_id, msg)
else
# (2b) send email if user is offline
UserMailer.friend_request(friend, notification_msg)
UserMailer.friend_request(friend.email, notification_msg)
end
end
############### FRIEND REQUEST ACCEPTED ###############
def send_friend_request_accepted(user_id, friend_id)
friend = User.find(friend_id)
user = User.find(user_id)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::FRIEND_REQUEST_ACCEPTED
notification.source_user_id = friend_id
@ -267,59 +242,24 @@ module JamRuby
notification_msg = format_msg(notification.description, friend)
# (2) create notification
if user.online
msg = @@message_factory.friend_request_accepted(
friend.id,
friend.name,
friend.photo_url,
user.id,
friend.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_user(user.id, msg)
else
# (2b) send email if user is offline
UserMailer.friend_request_accepted(user, notification_msg)
UserMailer.friend_request_accepted(user.email, notification_msg)
end
end
################## FRIEND SESSION JOIN ##################
def send_friend_session_join(db_conn, connection, user)
ids = retrieve_friends_not_in_session(db_conn, user.id, connection.music_session.id)
unless ids.empty?
# (1) bulk save to database
notifications = []
ids.each do |id|
notification = Notification.new
notification.description = NotificationTypes::FRIEND_SESSION_JOIN
notification.source_user_id = user.id
notification.target_user_id = id
notifications << notification
end
Notification.import notifications
# (2) create notification
msg = @@message_factory.friend_session_join(
connection.music_session.id,
user.id,
user.name,
user.photo_url)
# (3) send notification
@@mq_router.publish_to_friends(ids, msg, sender = {:client_id => connection.client_id})
end
end
############### NEW FOLLOWER ###############
def send_new_user_follower(follower, user)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::NEW_USER_FOLLOWER
notification.source_user_id = follower.id
@ -328,22 +268,19 @@ module JamRuby
notification_msg = format_msg(notification.description, follower)
# (2) create notification
if user.online
msg = @@message_factory.new_user_follower(
user.id,
follower.name,
follower.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (2a) send notification if user is online
@@mq_router.publish_to_user(user.id, msg)
else
# (2b) send email if user is offline
UserMailer.new_user_follower(user, notification_msg)
UserMailer.new_user_follower(user.email, notification_msg)
end
end
@ -351,10 +288,8 @@ module JamRuby
notifications = []
# these notifications go to each band member
band.band_musicians.each.each do |bm|
# create notifications (saved below in bulk)
notification = Notification.new
notification.description = NotificationTypes::NEW_BAND_FOLLOWER
notification.source_user_id = follower.id
@ -363,32 +298,30 @@ module JamRuby
notification_msg = format_msg(notification.description, follower, band)
# send notification
if bm.user.online
msg = @@message_factory.new_user_follower(
bm.user_id,
follower.name,
follower.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (2a) send notification if user is online
@@mq_router.publish_to_user(user.id, msg)
else
# (2b) send email if user is offline
UserMailer.new_band_follower(user, notification_msg)
UserMailer.new_band_follower(user.email, notification_msg)
end
end
unless notifications.empty?
Notification.import notifications
end
Notification.import notifications
end
################## SESSION INVITATION ##################
def send_session_invitation(receiver, sender, session_id)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::SESSION_INVITATION
notification.source_user_id = sender.id
@ -396,36 +329,32 @@ module JamRuby
notification.session_id = session_id
notification.save
# (2) create notification
notification_msg = format_msg(NotificationTypes::SESSION_INVITATION, sender)
if receiver.online
msg = @@message_factory.session_invitation(
receiver.id,
sender.name,
session_id,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (2a) send notification
@@mq_router.publish_to_user(receiver.id, msg)
else
# (2b) send email if user is offline
UserMailer.session_invitation(receiver, )
UserMailer.session_invitation(receiver.email, notification_msg)
end
end
################## SESSION ENDED ##################
def send_session_ended(music_session, connection)
# 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})
end
################## JOIN REQUEST ##################
def send_join_request(music_session, join_request, text)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::JOIN_REQUEST
notification.source_user_id = join_request.user.id
@ -433,8 +362,8 @@ module JamRuby
notification.session_id = music_session.id
notification.save
# (2) create notification
notification_msg = format_msg(notification.description, join_request.user)
msg = @@message_factory.join_request(
join_request.id,
music_session.id,
@ -445,14 +374,11 @@ module JamRuby
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_user(music_session.creator.id, msg)
end
################## JOIN REQUEST APPROVED ##################
def send_join_request_approved(music_session, join_request)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::JOIN_REQUEST_APPROVED
notification.source_user_id = music_session.creator.id
@ -460,8 +386,8 @@ module JamRuby
notification.session_id = music_session.id
notification.save
# (2) create notification
notification_msg = format_msg(notification.description, music_session.creator)
msg = @@message_factory.join_request_approved(
join_request.id,
music_session.id,
@ -472,14 +398,11 @@ module JamRuby
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_user(join_request.user.id, msg)
end
################## JOIN REQUEST REJECTED ##################
def send_join_request_rejected(music_session, join_request)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::JOIN_REQUEST_REJECTED
notification.source_user_id = music_session.creator.id
@ -487,8 +410,8 @@ module JamRuby
notification.session_id = music_session.id
notification.save
# (2) create notification
notification_msg = format_msg(notification.description, music_session.creator)
msg = @@message_factory.join_request_rejected(
join_request.id,
music_session.id,
@ -498,47 +421,96 @@ module JamRuby
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_user(join_request.user.id, msg)
end
################## MUSICIAN SESSION JOIN ##################
def send_musician_session_join(music_session, connection, user)
def send_session_join(music_session, connection, user)
notification_msg = format_msg(NotificationTypes::SESSION_JOIN, user)
# (1) create notification
msg = @@message_factory.musician_session_join(
msg = @@message_factory.session_join(
music_session.id,
user.id,
user.name,
user.photo_url
user.photo_url,
notification_msg
)
# (2) send notification
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
end
################## MUSICIAN SESSION DEPART ##################
def send_musician_session_depart(music_session, client_id, user, recordingId = nil)
def send_session_depart(music_session, client_id, user, recordingId = nil)
# (1) create notification
msg = @@message_factory.musician_session_depart(
notification_msg = format_msg(NotificationTypes::SESSION_DEPART, user)
msg = @@message_factory.session_depart(
music_session.id,
user.id,
user.name,
user.photo_url,
notification_msg,
recordingId
)
# (2) send notification
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id})
end
################## MUSICIAN RECORDING SAVED ##################
def send_musician_session_join(music_session, connection, user)
if music_session.musician_access || music_session.fan_access
friends = Friendship.where(:friend_id => user.id)
user_followers = UserFollower.where(:user_id => user.id)
friend_users = friends.map { |fu| fu.friend }
follower_users = user_followers.map { |uf| uf.follower }
friends_and_followers = friend_users.concat(follower_users)
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|
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
notifications << notification
ff.online ? online_ff << ff : offline_ff << ff
end
end
unless notifications.empty?
Notification.import notifications
end
notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, user)
# send real-time notifications
unless online_ff.empty?
msg = @@message_factory.musician_session_join(
receiver.id,
music_session.id,
user.photo_url,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_friends(online_ff.map! {|f| f.id}, msg, user.id)
end
# send email notifications
unless offline_ff.empty?
UserMailer.musician_session_join(offline_ff.map! {|f| f.email}, msg)
end
end
end
end
def send_musician_recording_saved(recording, user)
ids = retrieve_friends_and_followers(connection, user_id)
# (1) save to database
notification = Notification.new
notification.description = NotificationTypes::MUSICIAN_RECORDING_SAVED
notification.source_user_id = user.id
@ -546,8 +518,8 @@ module JamRuby
notification.session_id = music_session.id
notification.save
# (2) create notification
notification_msg = format_msg(notification.description, user)
msg = @@message_factory.join_request_approved(
join_request.id,
music_session.id,
@ -558,22 +530,43 @@ module JamRuby
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_friends(ids, msg, sender = {:client_id => connection.client_id})
end
################## MUSICIAN RECORDING SAVED ##################
################## BAND RECORDING SAVED ##################
################## RECORDING STARTED ##################
def send_recording_started(music_session, connection, user)
################## RECORDING ENDED ##################
notification_msg = format_msg(NotificationTypes::RECORDING_STARTED, user)
msg = @@message_factory.recording_started(
music_session.id,
user.photo_url,
notification_msg
)
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
end
def send_recording_ended(music_session, connection, user)
notification_msg = format_msg(NotificationTypes::RECORDING_ENDED, user)
msg = @@message_factory.recording_ended(
music_session.id,
user.name,
user.photo_url
)
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id})
end
################## RECORDING MASTER MIX COMPLETE ##################
################## BAND INVITATION ##################
def send_band_invitation(band, band_invitation, sender, receiver)
# (1) save to database
notification = Notification.new
notification.band_id = band.id
notification.band_invitation_id = band_invitation.id
@ -584,31 +577,26 @@ module JamRuby
notification_msg = format_msg(notification.description, nil, band)
# (2) create notification
if receiver.online
msg = @@message_factory.band_invitation(
receiver.id,
band_invitation.id,
band.id,
receiver.id,
sender.name,
sender.photo_url,
band.name,
notification_msg,
notification.id,
notification.created_at.to_s
)
# (3) send notification
@@mq_router.publish_to_user(receiver.id, msg)
else
UserMailer.band_invitation(receiver, notification_msg)
UserMailer.band_invitation(receiver.email, notification_msg)
end
end
################## BAND INVITATION ACCEPTED ##################
def send_band_invitation_accepted(band, band_invitation, sender, receiver)
# (1) save to database
notification = Notification.new
notification.band_id = band.id
notification.description = NotificationTypes::BAND_INVITATION_ACCEPTED
@ -618,56 +606,74 @@ module JamRuby
notification_msg = format_msg(notification.description, sender)
# (2) create notification
if receiver.online
msg = @@message_factory.band_invitation_accepted(
band_invitation.id,
receiver.id,
sender.name,
band_invitation.id,
sender.photo_url,
band.name,
notification_msg,
notification.id,
notification.created_at.to_s
)
@@mq_router.publish_to_user(receiver.id, msg)
else
# (2b) send email if user is offline
UserMailer.band_invitation_accepted(receiver, notification_msg)
UserMailer.band_invitation_accepted(receiver.email, notification_msg)
end
end
################## BAND SESSION JOIN ##################
def send_band_session_join(music_session, band)
# (1) save to database
notification = Notification.new
notification.band_id = band.id
notification.description = NotificationTypes::BAND_SESSION_JOIN
notification.source_user_id = sender.id
notification.target_user_id = receiver.id
notification.save
# (2) create notification
notification_msg = format_msg(notification.description, sender)
msg = @@message_factory.band_session_join(
music_session.id,
receiver.id,
sender.name,
sender.photo_url,
band.name,
notification_msg,
notification.id,
notification.created_at.to_s
)
# if the session is private, don't send any notifications
if music_session.musician_access || music_session.fan_access
# (3) send notification
@@mq_router.publish_to_user(receiver.id, msg)
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
notifications << notification
bf.follower.online ? online_followers << bf.follower : offline_followers << bf.follower
end
end
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
################## MUSICIAN SESSION FRESH ##################
def send_musician_session_fresh(music_session, client_id, user)
# (1) create notification
msg = @@message_factory.musician_session_fresh(
music_session.id,
user.id,
@ -675,14 +681,11 @@ module JamRuby
user.photo_url
)
# (2) send notification
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id})
end
################## MUSICIAN SESSION STALE ##################
def send_musician_session_stale(music_session, client_id, user)
# (1) create notification
msg = @@message_factory.musician_session_stale(
music_session.id,
user.id,
@ -690,7 +693,6 @@ module JamRuby
user.photo_url
)
# (2) send notification
@@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id})
end

View File

@ -46,7 +46,9 @@ module JamRuby
end
end
end
# connection = Connection.where(:user_id => owner.id).where(:music_session_id => music_session.id)
# Notification.send_recording_started(music_session, connection, owner)
# FIXME:
# NEED TO SEND NOTIFICATION TO ALL USERS IN THE SESSION THAT RECORDING HAS STARTED HERE.
@ -61,7 +63,7 @@ module JamRuby
end
# Stop recording a session
def stop
def stop(owner)
# Use a transaction and lock to avoid races.
music_session = MusicSession.find_by_id(music_session_id)
locker = music_session.nil? ? self : music_session
@ -70,6 +72,10 @@ module JamRuby
self.is_done = true
self.save
end
# connection = Connection.where(:user_id => owner.id).where(:music_session_id => music_session.id)
# Notification.send_recording_ended(music_session, connection, owner)
self
end

View File

@ -89,7 +89,7 @@ class MQRouter
def publish_to_friends(friend_ids, user_msg, from_user_id)
EM.schedule do
friend_ids.each do |friend_id|
@@log.debug "publishing to friend:#{friend_id} from user #{from_user_id}"
@@log.debug "publishing to friend:#{friend_id} from user/band #{from_user_id}"
# put it on the topic exchange for users
self.class.user_exchange.publish(user_msg, :routing_key => "user.#{friend_id}")
end

View File

@ -10,7 +10,7 @@ describe Mix do
@music_session.connections << @connection
@music_session.save
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@mix = Mix.schedule(@recording, "{}")
end

View File

@ -414,7 +414,7 @@ describe MusicSession do
describe "not recording" do
it "stop_recording should return nil if not recording" do
@music_session.stop_recording.should be_nil
@music_session.stop_recording(@user1).should be_nil
end
end
@ -428,7 +428,7 @@ describe MusicSession do
end
it "stop_recording should return recording object if recording" do
@music_session.stop_recording.should == @recording
@music_session.stop_recording(@user1).should == @recording
end
end

View File

@ -66,7 +66,7 @@ describe 'Musician search' do
music_session.connections << connection
music_session.save
recording = Recording.start(music_session, usr)
recording.stop
recording.stop(usr)
recording.reload
genre = FactoryGirl.create(:genre)
recording.claim(usr, "name", "description", genre, true, true)

View File

@ -33,7 +33,7 @@ describe Recording do
it "should return the state to normal properly when you stop a recording" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@music_session.reload
@music_session.is_recording?.should be_false
end
@ -41,15 +41,15 @@ describe Recording do
it "should error when you stop a recording twice" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.errors.any?.should be_false
@recording.stop
@recording.stop(@user)
@recording.errors.any?.should be_true
end
it "should be able to start, stop then start a recording again for the same music session" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording2 = Recording.start(@music_session, @user)
@music_session.recordings.exists?(@recording2).should be_true
end
@ -73,7 +73,7 @@ describe Recording do
it "should report correctly whether its tracks have been uploaded" do
@recording = Recording.start(@music_session, @user)
@recording.uploaded?.should == false
@recording.stop
@recording.stop(@user)
@recording.reload
@recording.uploaded?.should == false
@recording.recorded_tracks.first.fully_uploaded = true
@ -82,7 +82,7 @@ describe Recording do
it "should destroy a recording and all its recorded tracks properly" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@recorded_track = @recording.recorded_tracks.first
@recording.destroy
@ -92,7 +92,7 @@ describe Recording do
it "should allow a user to claim a recording" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "name", "description", @genre, true, true)
@ -112,7 +112,7 @@ describe Recording do
it "should fail if a user who was not in the session claims a recording" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
user2 = FactoryGirl.create(:user)
expect { @recording.claim(user2, "name", "description", @genre, true, true) }.to raise_error
@ -120,7 +120,7 @@ describe Recording do
it "should fail if a user tries to claim a recording twice" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "name", "description", @genre, true, true)
@ -130,7 +130,7 @@ describe Recording do
it "should allow editing metadata for claimed recordings" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@claimed_recording = @recording.claim(@user, "name", "description", @genre, true, true)
@ -146,7 +146,7 @@ describe Recording do
it "should only allow the owner to edit a claimed recording" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@claimed_recording = @recording.claim(@user, "name", "description", @genre, true, true)
@ -157,7 +157,7 @@ describe Recording do
it "should record the duration of the recording properly" do
@recording = Recording.start(@music_session, @user)
@recording.duration.should be_nil
@recording.stop
@recording.stop(@user)
@recording.reload
@recording.duration.should_not be_nil
# Note: it will be 0 since this was fast. You can see something non-zero by just
@ -172,7 +172,7 @@ describe Recording do
@music_session.connections << @connection2
@music_session.save
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@claimed_recording = @recording.claim(@user, "name", "description", @genre, true, true)
@ -185,7 +185,7 @@ describe Recording do
it "should destroy the entire recording if there was only one claimed_recording which is discarded" do
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@claimed_recording = @recording.claim(@user, "name", "description", @genre, true, true)
@ -197,7 +197,7 @@ describe Recording do
it "should use the since parameter when restricting uploads" do
stub_const("APP_CONFIG", app_config)
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "Recording", "Recording Description", @genre, true, true)
@ -210,7 +210,7 @@ describe Recording do
pending
stub_const("APP_CONFIG", app_config)
@recording = Recording.start(@music_session, @user)
@recording.stop
@recording.stop(@user)
@recording.reload
@genre = FactoryGirl.create(:genre)
@recording.claim(@user, "Recording", "Recording Description", @genre, true, true)
@ -256,7 +256,7 @@ describe Recording do
@music_session.save
@recording = Recording.start(@music_session, @user)
#sleep 4
@recording.stop
@recording.stop(@user)
@recording.recorded_tracks.length.should == 2
@recorded_track = @recording.recorded_tracks.first
@recorded_track.upload_start(25000, "md5hash")

View File

@ -31,10 +31,9 @@
JOIN_REQUEST : "JOIN_REQUEST",
JOIN_REQUEST_APPROVED : "JOIN_REQUEST_APPROVED",
JOIN_REQUEST_REJECTED : "JOIN_REQUEST_REJECTED",
// musician notifications
SESSION_JOIN : "SESSION_JOIN",
SESSION_DEPART : "SESSION_DEPART",
MUSICIAN_SESSION_JOIN : "MUSICIAN_SESSION_JOIN",
MUSICIAN_SESSION_DEPART : "MUSICIAN_SESSION_DEPART",
// recording notifications
MUSICIAN_RECORDING_SAVED : "MUSICIAN_RECORDING_SAVED",

View File

@ -357,12 +357,7 @@
// default handler for incoming notification
function handleNotification(payload, type) {
var sidebarText;
if (type === context.JK.MessageType.SESSION_INVITATION) {
sidebarText = payload.sender_name + " has invited you to a session.";
}
else {
sidebarText = payload.msg;
}
sidebarText = payload.msg;
// increment displayed notification count
incrementNotificationCount();
@ -436,7 +431,6 @@
registerFriendUpdate();
registerFriendRequest();
registerFriendRequestAccepted();
registerFriendSessionJoin();
registerNewUserFollower();
registerNewBandFollower();
@ -446,10 +440,9 @@
registerJoinRequest();
registerJoinRequestApproved();
registerJoinRequestRejected();
// musician notifications
registerSessionJoin();
registerSessionDepart();
registerMusicianSessionJoin();
registerMusicianSessionDepart();
// recording notifications
registerMusicianRecordingSaved();
@ -479,11 +472,9 @@
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.FRIEND_UPDATE, function(header, payload) {
logger.debug("Handling FRIEND_UPDATE msg " + JSON.stringify(payload));
// update friends panel in sidebar
friends[payload.user_id].online = payload.online;
updateFriendList(friends);
// display notification
var online_text = payload.online ? "online" : "offline";
app.notify({
"title": "Friend is now " + online_text,
@ -499,7 +490,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "New Friend Request",
"text": payload.msg,
@ -529,10 +519,8 @@
handleNotification(payload, header.type);
// refresh friends panel
initializeFriendsPanel();
// display notification
app.notify({
"title": "Friend Request Accepted",
"text": payload.msg,
@ -541,32 +529,13 @@
});
}
function registerFriendSessionJoin() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.FRIEND_SESSION_JOIN, function(header, payload) {
logger.debug("Handling FRIEND_SESSION_JOIN msg " + JSON.stringify(payload));
// update sidebar
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "Friend Joined Session",
"text": payload.username + " has joined a session.",
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
function registerNewUserFollower() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.NEW_USER_FOLLOWER, function(header, payload) {
logger.debug("Handling NEW_USER_FOLLOWER msg " + JSON.stringify(payload));
// update sidebar
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "New Follower",
"text": payload.msg,
@ -580,10 +549,8 @@
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.NEW_BAND_FOLLOWER, function(header, payload) {
logger.debug("Handling NEW_BAND_FOLLOWER msg " + JSON.stringify(payload));
// update sidebar
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "New Band Follower",
"text": payload.msg,
@ -618,7 +585,6 @@
participantHtml += "</tbody></table>";
// display notification
app.notify({
"title": "Session Invitation",
"text": participantHtml
@ -651,7 +617,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "New Join Request",
"text": payload.msg,
@ -687,7 +652,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "Join Request Approved",
"text": payload.msg,
@ -706,7 +670,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "Join Request Rejected",
"text": payload.msg,
@ -715,26 +678,25 @@
});
}
function registerMusicianSessionJoin() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_SESSION_JOIN, function(header, payload) {
logger.debug("Handling MUSICIAN_SESSION_JOIN msg " + JSON.stringify(payload));
function registerSessionJoin() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_JOIN, function(header, payload) {
logger.debug("Handling SESSION_JOIN msg " + JSON.stringify(payload));
// display notification
app.notify({
"title": "Musician Joined Session",
"text": payload.username + " has joined the session.",
"title": "New Session Participant",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
function registerMusicianSessionDepart() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.MUSICIAN_SESSION_DEPART, function(header, payload) {
logger.debug("Handling MUSICIAN_SESSION_DEPART msg " + JSON.stringify(payload));
function registerSessionDepart() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_DEPART, function(header, payload) {
logger.debug("Handling SESSION_DEPART msg " + JSON.stringify(payload));
if(payload.recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(payload.recordingId)) {
context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(payload.recordingId);
if(payload.recording_id && context.JK.CurrentSessionModel.recordingModel.isRecording(payload.recording_id)) {
context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(payload.recording_id);
/**app.notify({
"title": "Recording Stopped",
"text": payload.username + " has left the session.",
@ -744,13 +706,27 @@
else {
app.notify({
"title": "Musician Left Session",
"text": payload.username + " has left the session.",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
}
});
}
function registerMusicianSessionJoin() {
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);
app.notify({
"title": "Musician Joined Session",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
function registerMusicianRecordingSaved() {
}
@ -760,11 +736,27 @@
}
function registerRecordingStarted() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_STARTED, function(header, payload) {
logger.debug("Handling RECORDING_STARTED msg " + JSON.stringify(payload));
app.notify({
"title": "Recording Started",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
function registerRecordingEnded() {
context.JK.JamServer.registerMessageCallback(context.JK.MessageType.RECORDING_ENDED, function(header, payload) {
logger.debug("Handling RECORDING_ENDED msg " + JSON.stringify(payload));
app.notify({
"title": "Recording Ended",
"text": payload.msg,
"icon_url": context.JK.resolveAvatarUrl(payload.photo_url)
});
});
}
function registerRecordingMasterMixComplete() {
@ -777,7 +769,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "Band Invitation",
"text": payload.msg,
@ -810,7 +801,6 @@
handleNotification(payload, header.type);
// display notification
app.notify({
"title": "Band Invitation Accepted",
"text": payload.msg,
@ -820,7 +810,18 @@
}
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) {

View File

@ -58,7 +58,7 @@ class ApiRecordingsController < ApiController
raise PermissionError, ValidationMessages::PERMISSION_VALIDATION_ERROR
end
@recording.stop
@recording.stop(current_user)
if @recording.errors.any?
response.status = :unprocessable_entity

View File

@ -48,6 +48,10 @@ MusicSessionManager < BaseManager
connection = ConnectionManager.new.join_music_session(user, client_id, music_session, as_musician, tracks)
unless connection.errors.any?
unless band.nil?
Notification.send_band_session_join(music_session, band)
end
return_value = music_session
else
return_value = connection
@ -101,7 +105,7 @@ 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_friend_session_join(db_conn, connection, user)
Notification.send_session_join(music_session, connection, user)
Notification.send_musician_session_join(music_session, connection, user)
end
end
@ -125,9 +129,9 @@ MusicSessionManager < BaseManager
end
ConnectionManager.new.leave_music_session(user, connection, music_session) do
recording = music_session.stop_recording # stop any ongoing recording, if there is one
recording = music_session.stop_recording(user) # stop any ongoing recording, if there is one
recordingId = recording.id unless recording.nil?
Notification.send_musician_session_depart(music_session, connection.client_id, user, recordingId)
Notification.send_session_depart(music_session, connection.client_id, user, recordingId)
end
end
end

View File

@ -349,9 +349,9 @@ module JamWebsockets
Notification.send_friend_update(user_id, false, conn) if count == 0
music_session = MusicSession.find_by_id(music_session_id) unless music_session_id.nil?
user = User.find_by_id(user_id) unless user_id.nil?
recording = music_session.stop_recording unless music_session.nil? # stop any ongoing recording, if there is one
recording = music_session.stop_recording(user) unless music_session.nil? # stop any ongoing recording, if there is one
recordingId = recording.id unless recording.nil?
Notification.send_musician_session_depart(music_session, cid, user, recordingId) unless music_session.nil? || user.nil?
Notification.send_session_depart(music_session, cid, user, recordingId) unless music_session.nil? || user.nil?
}
end
end
@ -398,21 +398,17 @@ module JamWebsockets
end
if @message_factory.server_directed? client_msg
handle_server_directed(client_msg, client)
elsif @message_factory.client_directed? client_msg
to_client_id = client_msg.route_to[MessageFactory::CLIENT_TARGET_PREFIX.length..-1]
handle_client_directed(to_client_id, client_msg, client)
elsif @message_factory.session_directed? client_msg
session_id = client_msg.target[MessageFactory::SESSION_TARGET_PREFIX.length..-1]
handle_session_directed(session_id, client_msg, client)
elsif @message_factory.user_directed? client_msg
user_id = client_msg.target[MessageFactory::USER_PREFIX_TARGET.length..-1]
handle_user_directed(user_id, client_msg, client)
@ -485,9 +481,9 @@ module JamWebsockets
# if this is a reclaim of a connection, but music_session_id comes back null, then we need to check if this connection was IN a music session before.
# if so, then we need to tell the others in the session that this user is now departed
unless context.nil? || music_session_upon_reentry.nil? || music_session_upon_reentry.destroyed?
recording = music_session_upon_reentry.stop_recording
recording = music_session_upon_reentry.stop_recording(user)
recordingId = recording.id unless recording.nil?
Notification.send_musician_session_depart(music_session_upon_reentry, client.client_id, context.user, recordingId)
Notification.send_session_depart(music_session_upon_reentry, client.client_id, context.user, recordingId)
end
else
music_session = MusicSession.find_by_id(music_session_id)