From 7e78163bb992876fc68c3e9bf21704b07149452a Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sat, 28 Dec 2013 23:51:35 -0500 Subject: [PATCH] VRFS-933 notification work --- pb/src/client_container.proto | 349 +++++++++++------- ruby/Gemfile | 1 + ruby/lib/jam_ruby/app/mailers/user_mailer.rb | 39 ++ .../jam_ruby/constants/notification_types.rb | 11 +- ruby/lib/jam_ruby/message_factory.rb | 304 ++++++++------- ruby/lib/jam_ruby/models/notification.rb | 294 ++++++++++----- ruby/lib/jam_ruby/models/user.rb | 41 +- .../assets/javascripts/AAB_message_factory.js | 36 +- web/app/assets/javascripts/sidebar.js | 167 +++++++-- .../controllers/api_invitations_controller.rb | 2 +- web/app/controllers/api_users_controller.rb | 4 +- 11 files changed, 831 insertions(+), 417 deletions(-) diff --git a/pb/src/client_container.proto b/pb/src/client_container.proto index fef2995dc..4f594e7cb 100644 --- a/pb/src/client_container.proto +++ b/pb/src/client_container.proto @@ -9,43 +9,62 @@ package jampb; message ClientMessage { enum Type { - LOGIN = 100; - LOGIN_ACK = 101; + LOGIN = 100; + LOGIN_ACK = 105; + LOGIN_MUSIC_SESSION = 110; + LOGIN_MUSIC_SESSION_ACK = 115; + LEAVE_MUSIC_SESSION = 120; + LEAVE_MUSIC_SESSION_ACK = 125; + HEARTBEAT = 130; + HEARTBEAT_ACK = 135; - LOGIN_MUSIC_SESSION = 102; - LOGIN_MUSIC_SESSION_ACK = 103; - FRIEND_SESSION_JOIN = 104; - LEAVE_MUSIC_SESSION = 105; - LEAVE_MUSIC_SESSION_ACK = 106; - HEARTBEAT = 107; - FRIEND_UPDATE = 108; - SESSION_INVITATION = 109; - MUSICIAN_SESSION_DEPART = 110; - JOIN_REQUEST = 111; - FRIEND_REQUEST = 112; - FRIEND_REQUEST_ACCEPTED = 113; - MUSICIAN_SESSION_JOIN = 114; - MUSICIAN_SESSION_FRESH = 115; - MUSICIAN_SESSION_STALE = 116; - HEARTBEAT_ACK = 117; - JOIN_REQUEST_APPROVED = 118; - JOIN_REQUEST_REJECTED = 119; - BAND_INVITATION = 120; - BAND_INVITATION_ACCEPTED = 121; + // friend notifications + FRIEND_UPDATE = 140; + FRIEND_REQUEST = 145; + FRIEND_REQUEST_ACCEPTED = 150; + FRIEND_SESSION_JOIN = 155; + NEW_USER_FOLLOWER = 160; + NEW_BAND_FOLLOWER = 161; - TEST_SESSION_MESSAGE = 200; + // session invitations + SESSION_INVITATION = 165; + SESSION_ENDED = 170; + JOIN_REQUEST = 175; + JOIN_REQUEST_APPROVED = 180; + JOIN_REQUEST_REJECTED = 185; + + // musician notifications + MUSICIAN_SESSION_JOIN = 190; + MUSICIAN_SESSION_DEPART = 195; + + // recording notifications + MUSICIAN_RECORDING_SAVED = 200; + BAND_RECORDING_SAVED = 205; + RECORDING_STARTED = 210; + RECORDING_ENDED = 215; + RECORDING_MASTER_MIX_COMPLETE = 220; + + // band notifications + BAND_INVITATION = 225; + BAND_INVITATION_ACCEPTED = 230; + BAND_SESSION_JOIN = 235; + + MUSICIAN_SESSION_FRESH = 240; + MUSICIAN_SESSION_STALE = 245; + + TEST_SESSION_MESSAGE = 295; PING_REQUEST = 300; - PING_ACK = 301; - PEER_MESSAGE = 302; - TEST_CLIENT_MESSAGE = 303; + PING_ACK = 305; + PEER_MESSAGE = 310; + TEST_CLIENT_MESSAGE = 315; SERVER_BAD_STATE_RECOVERED = 900; SERVER_GENERIC_ERROR = 1000; - SERVER_REJECTION_ERROR = 1001; - SERVER_PERMISSION_ERROR = 1002; - SERVER_BAD_STATE_ERROR = 1003; + SERVER_REJECTION_ERROR = 1005; + SERVER_PERMISSION_ERROR = 1010; + SERVER_BAD_STATE_ERROR = 1015; } // Identifies which inner message is filled in @@ -59,45 +78,66 @@ message ClientMessage { // Client-Server messages (to/from) optional Login login = 100; // to server - optional LoginAck login_ack = 101; // from server - optional LoginMusicSession login_music_session = 102; // to server - optional LoginMusicSessionAck login_music_session_ack = 103; // from server - optional FriendSessionJoin friend_session_join = 104; // from server to all members - optional LeaveMusicSession leave_music_session = 105; - optional LeaveMusicSessionAck leave_music_session_ack = 106; - optional Heartbeat heartbeat = 107; - optional FriendUpdate friend_update = 108; // from server to all friends of user - optional SessionInvitation session_invitation = 109; // from server to user - optional MusicianSessionDepart musician_session_depart = 110; - optional JoinRequest join_request = 111; - optional FriendRequest friend_request = 112; - optional FriendRequestAccepted friend_request_accepted = 113; - optional MusicianSessionJoin musician_session_join = 114; - optional MusicianSessionFresh musician_session_fresh = 115; - optional MusicianSessionStale musician_session_stale = 116; - optional HeartbeatAck heartbeat_ack = 117; - optional JoinRequestApproved join_request_approved = 118; - optional JoinRequestRejected join_request_rejected = 119; - optional BandInvitation band_invitation = 120; - optional BandInvitationAccepted band_invitation_accepted = 121; + optional LoginAck login_ack = 105; // from server + optional LoginMusicSession login_music_session = 110; // to server + optional LoginMusicSessionAck login_music_session_ack = 115; // from server + optional LeaveMusicSession leave_music_session = 120; + optional LeaveMusicSessionAck leave_music_session_ack = 125; + optional Heartbeat heartbeat = 130; + optional HeartbeatAck heartbeat_ack = 135; + + // friend notifications + 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; + + // session invitations + optional SessionInvitation session_invitation = 165; // from server to user + optional SessionEnded session_ended = 170; + 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; + + // recording notifications + optional MusicianRecordingSaved musician_recording_saved = 200; + optional BandRecordingSaved band_recording_saved = 205; + optional RecordingStarted recording_started = 210; + optional RecordingEnded recording_ended = 215; + optional RecordingMasterMixComplete recording_master_mix_complete = 220; + + // 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; + // Client-Session messages (to/from) - optional TestSessionMessage test_session_message = 200; + optional TestSessionMessage test_session_message = 295; // Client-Client messages (to/from) optional PingRequest ping_request = 300; - optional PingAck ping_ack = 301; - optional PeerMessage peer_message = 302; - optional TestClientMessage test_client_message = 303; + optional PingAck ping_ack = 305; + optional PeerMessage peer_message = 310; + optional TestClientMessage test_client_message = 315; // Server-to-Client special messages optional ServerBadStateRecovered server_bad_state_recovered = 900; // Server-to-Client errors optional ServerGenericError server_generic_error = 1000; - optional ServerRejectionError server_rejection_error = 1001; - optional ServerPermissionError server_permission_error = 1002; - optional ServerBadStateError server_bad_state_error = 1003; + optional ServerRejectionError server_rejection_error = 1005; + optional ServerPermissionError server_permission_error = 1010; + optional ServerBadStateError server_bad_state_error = 1015; } // route_to: server @@ -157,6 +197,40 @@ 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; +} + +// 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; +} + +// 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 { @@ -166,41 +240,33 @@ message FriendSessionJoin { optional string photo_url = 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; +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; } -// 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 +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; } -// 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 { - 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: 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 notification_id = 3; + optional string created_at = 4; } -// route_to: client: -// sent by server to let the rest of the participants know a user has gone stale (websocket connection dropped) -message MusicianSessionStale { - 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; +message SessionEnded { + } message JoinRequest { @@ -233,6 +299,45 @@ message JoinRequestRejected { optional string created_at = 7; } +// 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 +} + +message MusicianRecordingSaved { + +} + +message BandRecordingSaved { + +} + +message RecordingStarted { + +} + +message RecordingEnded { + +} + +message RecordingMasterMixComplete { + +} + message BandInvitation { optional string band_invitation_id = 1; optional string band_id = 2; @@ -256,6 +361,33 @@ message BandInvitationAccepted { 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; +} + +// 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 { + 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 gone stale (websocket connection dropped) +message MusicianSessionStale { + 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: session // a test message used by ruby-client currently. just gives way to send out to rest of session message TestSessionMessage { @@ -298,57 +430,12 @@ message Heartbeat { message HeartbeatAck { } -// 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; -} - -// 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; -} - -// 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; -} - -// 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 notification_id = 3; - optional string created_at = 4; -} - // route_to: client // this should follow a ServerBadStateError in the case that the // websocket gateway recovers from whatever ailed it message ServerBadStateRecovered { } - - // route_to: client // this indicates unhandled error on server // if you receive this, your connection will close after. diff --git a/ruby/Gemfile b/ruby/Gemfile index 67fa507f4..f8607162e 100644 --- a/ruby/Gemfile +++ b/ruby/Gemfile @@ -10,6 +10,7 @@ gem 'pg', '0.15.1', :platform => [:mri, :mswin, :mingw] gem 'jdbc_postgres', :platform => [:jruby] gem 'activerecord', '3.2.13' +gem "activerecord-import", "~> 0.4.1" gem 'uuidtools', '2.1.2' gem 'bcrypt-ruby', '3.0.1' gem 'ruby-protocol-buffers', '1.2.2' diff --git a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb index c399f4e24..b59c74f86 100644 --- a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb @@ -88,5 +88,44 @@ end end + ######### NOTIFICATION EMAILS ######### + + + def friend_request(source_user, target_user) + end + + def friend_request_accepted(source_user, target_user) + end + + def new_user_follower(source_user, target_user) + @user = target_user + sendgrid_unique_args :type => "new_user_follower" + mail(:to => @user.email, :subject => "You have a new follower on JamKazam") do |format| + format.text + format.html + end + end + + def new_band_follower(source_user, target_users, band) + sendgrid_unique_args :type => "new_band_follower" + + mail(:to => extract_emails(target_users), :subject => "Your band has a new follower on JamKazam") do |format| + format.text + format.html + end + end + + def session_invitation(source_user, target_user) + @user = target_user + end + + def musician_session_join(user) + @user = user + end + + def extract_emails(users) + users.map! { |u| u.email } + end + end end diff --git a/ruby/lib/jam_ruby/constants/notification_types.rb b/ruby/lib/jam_ruby/constants/notification_types.rb index 272095f59..f8b8e5d55 100644 --- a/ruby/lib/jam_ruby/constants/notification_types.rb +++ b/ruby/lib/jam_ruby/constants/notification_types.rb @@ -5,10 +5,12 @@ module NotificationTypes FRIEND_REQUEST = "FRIEND_REQUEST" FRIEND_REQUEST_ACCEPTED = "FRIEND_REQUEST_ACCEPTED" FRIEND_SESSION_JOIN = "FRIEND_SESSION_JOIN" + NEW_USER_FOLLOWER = "NEW_USER_FOLLOWER" + NEW_BAND_FOLLOWER = "NEW_BAND_FOLLOWER" # session notifications SESSION_INVITATION = "SESSION_INVITATION" - SESSION_ENDED = "SESSION_ENDED" # used to remove session-related notification from sidebar + SESSION_ENDED = "SESSION_ENDED" # used to remove session-related notifications from sidebar JOIN_REQUEST = "JOIN_REQUEST" JOIN_REQUEST_APPROVED = "JOIN_REQUEST_APPROVED" JOIN_REQUEST_REJECTED = "JOIN_REQUEST_REJECTED" @@ -18,10 +20,15 @@ module NotificationTypes MUSICIAN_SESSION_DEPART = "MUSICIAN_SESSION_DEPART" # recording notifications - RECORDING_CREATED = "RECORDING_CREATED" + MUSICIAN_RECORDING_SAVED = "MUSICIAN_RECORDING_SAVED" + BAND_RECORDING_SAVED = "BAND_RECORDING_SAVED" + RECORDING_STARTED = "RECORDING_STARTED" + RECORDING_ENDED = "RECORDING_ENDED" + RECORDING_MASTER_MIX_COMPLETE = "RECORDING_MASTER_MIX_COMPLETE" # band notifications BAND_INVITATION = "BAND_INVITATION" BAND_INVITATION_ACCEPTED = "BAND_INVITATION_ACCEPTED" + BAND_SESSION_JOIN = "BAND_SESSION_JOIN" # cleared using SESSION_ENDED notification end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/message_factory.rb b/ruby/lib/jam_ruby/message_factory.rb index 51df0e0d5..425f182cf 100644 --- a/ruby/lib/jam_ruby/message_factory.rb +++ b/ruby/lib/jam_ruby/message_factory.rb @@ -9,18 +9,18 @@ CLIENT_TARGET_PREFIX = "client:" def initialize() - @type_values = {} + @type_values = {} - Jampb::ClientMessage::Type.constants.each do |constant| - @type_values[Jampb::ClientMessage::Type.const_get(constant)] = constant - end + Jampb::ClientMessage::Type.constants.each do |constant| + @type_values[Jampb::ClientMessage::Type.const_get(constant)] = constant + end end - # given a string (bytes) payload, return a client message - def parse_client_msg(payload) - return Jampb::ClientMessage.parse(payload) - end + # given a string (bytes) payload, return a client message + def parse_client_msg(payload) + return Jampb::ClientMessage.parse(payload) + end # create a login message using user/pass def login_with_user_pass(username, password, options = {}) @@ -114,6 +114,28 @@ ) end + # create a heartbeat + def heartbeat() + heartbeat = Jampb::Heartbeat.new + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::HEARTBEAT, + :route_to => SERVER_TARGET, + :heartbeat => heartbeat + ) + end + + # create a heartbeat ack + def heartbeat_ack() + heartbeat_ack = Jampb::HeartbeatAck.new + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::HEARTBEAT_ACK, + :route_to => CLIENT_TARGET, + :heartbeat_ack => heartbeat_ack + ) + end + # create a server bad state recovered msg def server_bad_state_recovered(original_message_id) recovered = Jampb::ServerBadStateRecovered.new() @@ -126,7 +148,7 @@ ) end - # create a server error + # create a server error def server_generic_error(error_msg) error = Jampb::ServerGenericError.new(:error_msg => error_msg) @@ -137,7 +159,7 @@ ) end - # create a server rejection error + # create a server rejection error def server_rejection_error(error_msg) error = Jampb::ServerRejectionError.new(:error_msg => error_msg) @@ -172,6 +194,64 @@ ) end + ###################################### NOTIFICATIONS ###################################### + + # create a friend update message + def friend_update(user_id, name, photo_url, online, msg) + friend = Jampb::FriendUpdate.new( + :user_id => user_id, + :name => name, + :photo_url => photo_url, + :online => online, + :msg => msg + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::FRIEND_UPDATE, + :route_to => USER_TARGET_PREFIX + user_id, + :friend_update => friend + ) + end + + # create a friend request message + def friend_request(friend_request_id, user_id, name, photo_url, friend_id, 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 + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::FRIEND_REQUEST, + :route_to => USER_TARGET_PREFIX + friend_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) + 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 + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::FRIEND_REQUEST_ACCEPTED, + :route_to => USER_TARGET_PREFIX + user_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( @@ -188,6 +268,38 @@ ) end + def new_user_follower(receiver_id, follower_name, 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, + :created_at => created_at + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::NEW_USER_FOLLOWER, + :route_to => USER_TARGET_PREFIX + receiver_id, + :new_user_follower => new_user_follower + ) + end + + def new_band_follower(receiver_id, follower_name, 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, + :created_at => created_at + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::NEW_BAND_FOLLOWER, + :route_to => USER_TARGET_PREFIX + receiver_id, + :new_user_follower => new_band_follower + ) + end + # create a musician joined session message def musician_session_join(session_id, user_id, username, photo_url) join = Jampb::MusicianSessionJoin.new( @@ -221,35 +333,18 @@ ) end - # create a musician fresh session message - def musician_session_fresh(session_id, user_id, username, photo_url) - fresh = Jampb::MusicianSessionFresh.new( - :session_id => session_id, - :user_id => user_id, - :username => username, - :photo_url => photo_url + def session_invitation(receiver_id, sender_name, session_id, notification_id, created_at) + session_invitation = Jampb::SessionInvitation.new( + :sender_name => sender_name, + :session_id => session_id, + :notification_id => notification_id, + :created_at => created_at ) return Jampb::ClientMessage.new( - :type => ClientMessage::Type::MUSICIAN_SESSION_FRESH, - :route_to => CLIENT_TARGET, - :musician_session_fresh => fresh - ) - end - - # create a musician stale session message - def musician_session_stale(session_id, user_id, username, photo_url) - stale = Jampb::MusicianSessionStale.new( - :session_id => session_id, - :user_id => user_id, - :username => username, - :photo_url => photo_url - ) - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::MUSICIAN_SESSION_STALE, - :route_to => CLIENT_TARGET, - :musician_session_stale => stale + :type => ClientMessage::Type::SESSION_INVITATION, + :route_to => USER_TARGET_PREFIX + receiver_id, + :session_invitation => session_invitation ) end @@ -351,85 +446,46 @@ ) end - # create a test message to send in session - def test_session_message(session_id, msg) - test = Jampb::TestSessionMessage.new(:msg => msg) + # create a musician fresh session message + def musician_session_fresh(session_id, user_id, username, photo_url) + fresh = Jampb::MusicianSessionFresh.new( + :session_id => session_id, + :user_id => user_id, + :username => username, + :photo_url => photo_url + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::MUSICIAN_SESSION_FRESH, + :route_to => CLIENT_TARGET, + :musician_session_fresh => fresh + ) + end + + # create a musician stale session message + def musician_session_stale(session_id, user_id, username, photo_url) + stale = Jampb::MusicianSessionStale.new( + :session_id => session_id, + :user_id => user_id, + :username => username, + :photo_url => photo_url + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::MUSICIAN_SESSION_STALE, + :route_to => CLIENT_TARGET, + :musician_session_stale => stale + ) + end + + # create a test message to send in session + def test_session_message(session_id, msg) + test = Jampb::TestSessionMessage.new(:msg => msg) return Jampb::ClientMessage.new( :type => ClientMessage::Type::TEST_SESSION_MESSAGE, :route_to => SESSION_TARGET_PREFIX + session_id, :test_session_message => test - ) - end - - def session_invitation(receiver_id, sender_name, session_id, notification_id, created_at) - session_invitation = Jampb::SessionInvitation.new( - :sender_name => sender_name, - :session_id => session_id, - :notification_id => notification_id, - :created_at => created_at - ) - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::SESSION_INVITATION, - :route_to => USER_TARGET_PREFIX + receiver_id, - :session_invitation => session_invitation - ) - end - - # create a friend update message - def friend_update(user_id, name, photo_url, online, msg) - friend = Jampb::FriendUpdate.new( - :user_id => user_id, - :name => name, - :photo_url => photo_url, - :online => online, - :msg => msg - ) - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::FRIEND_UPDATE, - :route_to => USER_TARGET_PREFIX + user_id, - :friend_update => friend - ) - end - - # create a friend request message - def friend_request(friend_request_id, user_id, name, photo_url, friend_id, 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 - ) - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::FRIEND_REQUEST, - :route_to => USER_TARGET_PREFIX + friend_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) - 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 - ) - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::FRIEND_REQUEST_ACCEPTED, - :route_to => USER_TARGET_PREFIX + user_id, - :friend_request_accepted => friend_request_accepted ) end @@ -473,28 +529,6 @@ #################################################### - # create a heartbeat - def heartbeat() - heartbeat = Jampb::Heartbeat.new - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::HEARTBEAT, - :route_to => SERVER_TARGET, - :heartbeat => heartbeat - ) - end - - # create a heartbeat ack - def heartbeat_ack() - heartbeat_ack = Jampb::HeartbeatAck.new - - return Jampb::ClientMessage.new( - :type => ClientMessage::Type::HEARTBEAT_ACK, - :route_to => CLIENT_TARGET, - :heartbeat_ack => heartbeat_ack - ) - end - # is this message directed to the server? def server_directed? msg return msg.route_to == MessageFactory::SERVER_TARGET @@ -519,8 +553,8 @@ return msg.route_to[MessageFactory::SESSION_TARGET_PREFIX..-1] end - def get_message_type msg - return @type_values[msg.type] - end + def get_message_type msg + return @type_values[msg.type] + end end end diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 5c54cdd00..9205bfbe2 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -81,7 +81,7 @@ module JamRuby return friend_ids end - def retrieve_followers(connection, user_id) + def retrieve_user_followers(connection, user_id) follower_ids = [] connection.exec("SELECT uf.follower_id as friend_id FROM users_followers uf WHERE uf.user_id = $1", [user_id]) do |follower_results| follower_results.each do |follower_result| @@ -93,7 +93,7 @@ module JamRuby def retrieve_friends_and_followers(connection, user_id) ids = retrieve_friends(connection, user_id) - ids.concat(retrieve_followers(connection, user_id)) + ids.concat(retrieve_user_followers(connection, user_id)) ids.uniq! {|id| id} return ids end @@ -109,7 +109,17 @@ module JamRuby return ids end - def format_msg(description, user = nil) + 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? name = user.name @@ -118,6 +128,8 @@ module JamRuby end case description + + # friend notifications when NotificationTypes::FRIEND_UPDATE return "#{name} is now " @@ -130,12 +142,13 @@ module JamRuby when NotificationTypes::FRIEND_SESSION_JOIN return "#{name} has joined the session." - when NotificationTypes::MUSICIAN_SESSION_JOIN - return "#{name} has joined the session." + when NotificationTypes::NEW_USER_FOLLOWER + return "#{name} is now following you on JamKazam." - when NotificationTypes::MUSICIAN_SESSION_DEPART - return "#{name} has left the session." + when NotificationTypes::NEW_BAND_FOLLOWER + return "#{name} is now following your band #{band.name} on JamKazam." + # session notifications when NotificationTypes::SESSION_INVITATION return "#{name} has invited you to a session." @@ -148,12 +161,42 @@ module JamRuby when NotificationTypes::JOIN_REQUEST_REJECTED return "We're sorry, but you cannot join the session at this time." + + # musician notifications + when NotificationTypes::MUSICIAN_SESSION_JOIN + return "#{name} has joined the session." + + when NotificationTypes::MUSICIAN_SESSION_DEPART + return "#{name} has left the session." + + + # recording notifications + when NotificationTypes::MUSICIAN_RECORDING_SAVED + return "#{name} has made a new recording." + + when NotificationTypes::BAND_RECORDING_SAVED + return "#{name} has made a new recording." + + when NotificationTypes::RECORDING_STARTED + return "#{name} has started a recording." + + when NotificationTypes::RECORDING_ENDED + return "#{name} has stopped recording." + + when NotificationTypes::RECORDING_MASTER_MIX_COMPLETE + return "This recording has been mastered and mixed and is ready to share." + + + # band notifications when NotificationTypes::BAND_INVITATION return "You have been invited to join the band #{name}." when NotificationTypes::BAND_INVITATION_ACCEPTED return "#{name} has accepted your band invitation." + when NotificationTypes::BAND_SESSION_JOIN + return "#{name} is now in a session." + else return "" end @@ -238,14 +281,43 @@ module JamRuby @@mq_router.publish_to_user(user_id, msg) end - ################## SESSION INVITATION ################## - def send_session_invitation(receiver_id, sender, session_id) + ################## FRIEND SESSION JOIN ################## + def send_friend_session_join(db_conn, connection, user) + ids = retrieve_friends_and_followers_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::SESSION_INVITATION + notification.description = NotificationTypes::NEW_USER_FOLLOWER notification.source_user_id = sender.id - notification.target_user_id = receiver_id + notification.target_user_id = receiver.id notification.session_id = session_id notification.save @@ -259,87 +331,41 @@ module JamRuby ) # (3) send notification - @@mq_router.publish_to_user(receiver_id, msg) + @@mq_router.publish_to_user(receiver.id, msg) end - ################## SESSION INVITATION ################## - def send_musician_session_join(music_session, connection, user) + def send_new_band_follower(follower, band) + end - # (1) create notification - msg = @@message_factory.musician_session_join( - music_session.id, - user.id, - user.name, - user.photo_url + ################## 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 + notification.target_user_id = receiver.id + notification.session_id = session_id + notification.save + + # (2) create notification + msg = @@message_factory.session_invitation( + receiver_id, + sender.name, + session_id, + notification.id, + notification.created_at.to_s ) - # (2) send notification - @@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => connection.client_id}) + # (3) send notification + @@mq_router.publish_to_user(receiver.id, msg) end - ################## MUSICIAN SESSION DEPART ################## - def send_musician_session_depart(music_session, client_id, user, recordingId = nil) + ################## SESSION ENDED ################## + def send_session_ended(music_session, connection) - # (1) create notification - msg = @@message_factory.musician_session_depart( - music_session.id, - user.id, - user.name, - user.photo_url, - recordingId - ) - - # (2) send notification - @@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id}) - 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, - user.name, - 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, - user.name, - user.photo_url - ) - - # (2) send notification - @@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id}) - end - - ################## FRIEND SESSION JOIN ################## - def send_friend_session_join(db_conn, connection, user) - ids = retrieve_friends_and_followers_not_in_session(db_conn, user.id, connection.music_session.id) - - if ids.length > 0 - # (1) save to database - - # (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 + # 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 ################## @@ -423,6 +449,74 @@ module JamRuby @@mq_router.publish_to_user(join_request.user.id, msg) end + ################## MUSICIAN SESSION JOIN ################## + def send_musician_session_join(music_session, connection, user) + + # (1) create notification + msg = @@message_factory.musician_session_join( + music_session.id, + user.id, + user.name, + user.photo_url + ) + + # (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) + + # (1) create notification + msg = @@message_factory.musician_session_depart( + music_session.id, + user.id, + user.name, + user.photo_url, + 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_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 + notification.target_user_id = join_request.user.id + 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, + music_session.creator.name, + music_session.creator.photo_url, + notification_msg, + notification.id, + notification.created_at.to_s + ) + + # (3) send notification + @@mq_router.publish_to_friends(ids, msg, sender = {:client_id => connection.client_id}) + end + + ################## BAND RECORDING SAVED ################## + + ################## RECORDING STARTED ################## + + ################## RECORDING ENDED ################## + + ################## RECORDING MASTER MIX COMPLETE ################## + ################## BAND INVITATION ################## def send_band_invitation(band, band_invitation, sender, receiver) @@ -481,6 +575,38 @@ module JamRuby @@mq_router.publish_to_user(receiver.id, msg) end + ################## BAND SESSION JOIN ################## + + ################## 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, + user.name, + 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, + user.name, + user.photo_url + ) + + # (2) send notification + @@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id}) + end + end end end \ No newline at end of file diff --git a/ruby/lib/jam_ruby/models/user.rb b/ruby/lib/jam_ruby/models/user.rb index c2b138aed..c0c47f254 100644 --- a/ruby/lib/jam_ruby/models/user.rb +++ b/ruby/lib/jam_ruby/models/user.rb @@ -548,6 +548,28 @@ module JamRuby self.save end + def create_user_following(user_id) + follower = UserFollower.new + follower.user_id = user_id + follower.follower_id = self.id + follower.save + + # TODO: make this async + user = User.find(user_id) + Notification.send_new_user_follower(self, user) + end + + def create_band_following(band_id) + follower = BandFollower.new + follower.band_id = band_id + follower.follower_id = self.id + follower.save + + # TODO: make this async + band = Band.find(band_id) + Notification.send_new_band_follower(self, band) + end + def self.finalize_update_email(update_email_token) # updates the user model to have a new email address user = User.find_by_update_email_token!(update_email_token) @@ -560,7 +582,6 @@ module JamRuby return user end - def self.create_user_like(user_id, liker_id) liker = UserLiker.new() liker.user_id = user_id @@ -578,7 +599,7 @@ module JamRuby end def self.create_band_like(band_id, liker_id) - liker = BandLiker.new() + liker = BandLiker.new liker.band_id = band_id liker.liker_id = liker_id liker.save @@ -588,13 +609,6 @@ module JamRuby JamRuby::BandLiker.delete_all "(band_id = '#{band_id}' AND liker_id = '#{liker_id}')" end - def self.create_user_following(user_id, follower_id) - follower = UserFollower.new() - follower.user_id = user_id - follower.follower_id = follower_id - follower.save - end - def self.delete_following(user_id, band_id, follower_id) if !user_id.nil? JamRuby::UserFollower.delete_all "(user_id = '#{user_id}' AND follower_id = '#{follower_id}')" @@ -604,19 +618,12 @@ module JamRuby end end - def self.create_band_following(band_id, follower_id) - follower = BandFollower.new() - follower.band_id = band_id - follower.follower_id = follower_id - follower.save - end - def self.delete_band_following(band_id, follower_id) JamRuby::BandFollower.delete_all "(band_id = '#{band_id}' AND follower_id = '#{follower_id}')" end def self.create_favorite(user_id, recording_id) - favorite = UserFavorite.new() + favorite = UserFavorite.new favorite.user_id = user_id favorite.recording_id = recording_id favorite.save diff --git a/web/app/assets/javascripts/AAB_message_factory.js b/web/app/assets/javascripts/AAB_message_factory.js index b648b7ec9..e96aedff2 100644 --- a/web/app/assets/javascripts/AAB_message_factory.js +++ b/web/app/assets/javascripts/AAB_message_factory.js @@ -12,22 +12,42 @@ LOGIN_ACK : "LOGIN_ACK", LOGIN_MUSIC_SESSION : "LOGIN_MUSIC_SESSION", LOGIN_MUSIC_SESSION_ACK : "LOGIN_MUSIC_SESSION_ACK", - FRIEND_SESSION_JOIN : "FRIEND_SESSION_JOIN", - MUSICIAN_SESSION_JOIN : "MUSICIAN_SESSION_JOIN", - MUSICIAN_SESSION_DEPART : "MUSICIAN_SESSION_DEPART", LEAVE_MUSIC_SESSION : "LEAVE_MUSIC_SESSION", LEAVE_MUSIC_SESSION_ACK : "LEAVE_MUSIC_SESSION_ACK", HEARTBEAT : "HEARTBEAT", HEARTBEAT_ACK : "HEARTBEAT_ACK", + + // friend notifications FRIEND_UPDATE : "FRIEND_UPDATE", + FRIEND_REQUEST : "FRIEND_REQUEST", + FRIEND_REQUEST_ACCEPTED : "FRIEND_REQUEST_ACCEPTED", + FRIEND_SESSION_JOIN : "FRIEND_SESSION_JOIN", + NEW_USER_FOLLOWER : "NEW_USER_FOLLOWER", + NEW_BAND_FOLLOWER : "NEW_BAND_FOLLOWER", + + // session notifications SESSION_INVITATION : "SESSION_INVITATION", + SESSION_ENDED : "SESSION_ENDED", JOIN_REQUEST : "JOIN_REQUEST", JOIN_REQUEST_APPROVED : "JOIN_REQUEST_APPROVED", JOIN_REQUEST_REJECTED : "JOIN_REQUEST_REJECTED", - FRIEND_REQUEST : "FRIEND_REQUEST", - FRIEND_REQUEST_ACCEPTED : "FRIEND_REQUEST_ACCEPTED", + + // musician notifications + MUSICIAN_SESSION_JOIN : "MUSICIAN_SESSION_JOIN", + MUSICIAN_SESSION_DEPART : "MUSICIAN_SESSION_DEPART", + + // recording notifications + MUSICIAN_RECORDING_SAVED : "MUSICIAN_RECORDING_SAVED", + BAND_RECORDING_SAVED : "BAND_RECORDING_SAVED", + RECORDING_STARTED : "RECORDING_STARTED", + RECORDING_ENDED : "RECORDING_ENDED", + RECORDING_MASTER_MIX_COMPLETE : "RECORDING_MASTER_MIX_COMPLETE", + + // 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", PING_ACK : "PING_ACK", @@ -84,10 +104,10 @@ // reconnect_music_session_id is an optional argument that allows the session to be immediately associated // with a music session. factory.login_with_token = function(token, reconnect_music_session_id) { - //context.JK.logger.debug("*** login_with_token: client_id = "+$.cookie("client_id")); + //context.JK.logger.debug("*** login_with_token: client_id = "+$.cookie("client_id")); var login = { token : token, - client_id : $.cookie("client_id") - }; + client_id : $.cookie("client_id") + }; return client_container(msg.LOGIN, route_to.SERVER, login); }; diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index f78fda21e..849a53ce6 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -156,9 +156,11 @@ acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id }); }); } + else if (type === context.JK.MessageType.FRIEND_REQUEST_ACCEPTED) { $notification.find('#div-actions').hide(); } + else if (type === context.JK.MessageType.SESSION_INVITATION) { var $action_btn = $notification.find('#btn-notification-action'); $action_btn.text('JOIN'); @@ -166,6 +168,7 @@ openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id }); }); } + else if (type === context.JK.MessageType.JOIN_REQUEST) { var $action_btn = $notification.find('#btn-notification-action'); $action_btn.text('APPROVE'); @@ -173,6 +176,7 @@ approveJoinRequest({ "join_request_id": payload.join_request_id, "notification_id": payload.notification_id }); }); } + else if (type === context.JK.MessageType.JOIN_REQUEST_APPROVED) { var $action_btn = $notification.find('#btn-notification-action'); $action_btn.text('JOIN'); @@ -180,9 +184,11 @@ openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id }); }); } + else if (type === context.JK.MessageType.JOIN_REQUEST_REJECTED) { $notification.find('#div-actions').hide(); } + else if (type === context.JK.MessageType.BAND_INVITATION) { var $action_btn = $notification.find('#btn-notification-action'); $action_btn.text('ACCEPT'); @@ -190,6 +196,7 @@ acceptBandInvitation({ "band_invitation_id": payload.band_invitation_id, "band_id": payload.band_id, "notification_id": payload.notification_id }); }); } + else if (type === context.JK.MessageType.BAND_INVITATION_ACCEPTED) { $notification.find('#div-actions').hide(); } @@ -421,18 +428,36 @@ $('.sidebar .invite-friend-row').hoverIntent(inviteHoverIn, inviteHoverOut); + // friend notifications registerFriendUpdate(); registerFriendRequest(); registerFriendRequestAccepted(); - registerMusicianSessionJoin(); - registerMusicianSessionDepart(); registerFriendSessionJoin(); + registerNewUserFollower(); + registerNewBandFollower(); + + // session invitations registerSessionInvitation(); + registerSessionEnded(); registerJoinRequest(); registerJoinRequestApproved(); registerJoinRequestRejected(); + + // musician notifications + registerMusicianSessionJoin(); + registerMusicianSessionDepart(); + + // recording notifications + registerMusicianRecordingSaved(); + registerBandRecordingSaved(); + registerRecordingStarted(); + registerRecordingEnded(); + registerRecordingMasterMixComplete(); + + // band notifications registerBandInvitation(); registerBandInvitationAccepted(); + registerBandSessionJoin(); // watch for Invite More Users events $('#sidebar-div .btn-email-invitation').click(function() { @@ -512,45 +537,14 @@ }); } - 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)); - - // display notification - app.notify({ - "title": "Musician Joined Session", - "text": payload.username + " has joined the session.", - "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)); - - if(payload.recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(payload.recordingId)) { - context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(payload.recordingId); - /**app.notify({ - "title": "Recording Stopped", - "text": payload.username + " has left the session.", - "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) - }); */ - } - else { - app.notify({ - "title": "Musician Left Session", - "text": payload.username + " has left the session.", - "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) - }); - } - }); - } - 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", @@ -560,6 +554,41 @@ }); } + 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, + "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) + }); + }); + } + + function registerNewBandFollower() { + + 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, + "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) + }); + }); + + } + function registerSessionInvitation() { context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_INVITATION, function(header, payload) { logger.debug("Handling SESSION_INVITATION msg " + JSON.stringify(payload)); @@ -608,6 +637,10 @@ context.location = '#/session/' + args.session_id; } + function registerSessionEnded() { + + } + function registerJoinRequest() { context.JK.JamServer.registerMessageCallback(context.JK.MessageType.JOIN_REQUEST, function(header, payload) { logger.debug("Handling JOIN_REQUEST msg " + JSON.stringify(payload)); @@ -678,6 +711,62 @@ }); } + + 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)); + + // display notification + app.notify({ + "title": "Musician Joined Session", + "text": payload.username + " has joined the session.", + "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)); + + if(payload.recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(payload.recordingId)) { + context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(payload.recordingId); + /**app.notify({ + "title": "Recording Stopped", + "text": payload.username + " has left the session.", + "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) + }); */ + } + else { + app.notify({ + "title": "Musician Left Session", + "text": payload.username + " has left the session.", + "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) + }); + } + }); + } + + function registerMusicianRecordingSaved() { + + } + + function registerBandRecordingSaved() { + + } + + function registerRecordingStarted() { + + } + + function registerRecordingEnded() { + + } + + function registerRecordingMasterMixComplete() { + + } + function registerBandInvitation() { context.JK.JamServer.registerMessageCallback(context.JK.MessageType.BAND_INVITATION, function(header, payload) { logger.debug("Handling BAND_INVITATION msg " + JSON.stringify(payload)); @@ -726,6 +815,10 @@ }); } + function registerBandSessionJoin() { + + } + this.initialize = function(invitationDialogInstance) { events(); initializeFriendsPanel(); diff --git a/web/app/controllers/api_invitations_controller.rb b/web/app/controllers/api_invitations_controller.rb index 48faa4fb5..266f97d6d 100644 --- a/web/app/controllers/api_invitations_controller.rb +++ b/web/app/controllers/api_invitations_controller.rb @@ -46,7 +46,7 @@ class ApiInvitationsController < ApiController User.save_session_settings(current_user, music_session) # send notification - Notification.send_session_invitation(receiver.id, current_user, music_session.id) + Notification.send_session_invitation(receiver, current_user, music_session.id) respond_with @invitation, :responder => ApiResponder, :location => api_invitation_detail_url(@invitation) else diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 1fa1c4271..00e539451 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -269,11 +269,11 @@ class ApiUsersController < ApiController id = params[:id] if !params[:user_id].nil? - User.create_user_following(params[:user_id], id) + @user.create_user_following(params[:user_id]) respond_with @user, responder: ApiResponder, :location => api_user_following_index_url(@user) elsif !params[:band_id].nil? - User.create_band_following(params[:band_id], id) + @user.create_band_following(params[:band_id]) respond_with @user, responder: ApiResponder, :location => api_band_following_index_url(@user) end end