From 4ef19e43564578e291eec83f1db6aef4f3a54164 Mon Sep 17 00:00:00 2001 From: Anthony Davis Date: Sat, 22 Feb 2014 21:12:12 -0600 Subject: [PATCH 01/19] VRFS-1218 DRYing it slightly, move toward VRFS-1214 --- web/spec/features/recordings_spec.rb | 16 ++-------------- web/spec/support/utilities.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/web/spec/features/recordings_spec.rb b/web/spec/features/recordings_spec.rb index 573199fbb..682870117 100644 --- a/web/spec/features/recordings_spec.rb +++ b/web/spec/features/recordings_spec.rb @@ -36,13 +36,7 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature # confirms that a formal leave (by hitting the 'Leave' button) will result in a good recording it "creator starts and then leaves" do start_recording_with(creator, [joiner1]) - - in_client(creator) do - find('#session-leave').trigger(:click) - find('#btn-accept').trigger(:click) - expect(page).to have_selector('h2', text: 'feed') - end - + formal_leave_by creator check_recording_finished_for [creator, joiner1] end @@ -73,13 +67,7 @@ describe "Session Recordings", :js => true, :type => :feature, :capybara_feature it "creator starts with session leave to stop, with 3 total participants" do start_recording_with(creator, [joiner1, joiner2]) - - in_client(creator) do - find('#session-leave').trigger(:click) - find('#btn-accept').trigger(:click) - expect(page).to have_selector('h2', text: 'feed') - end - + formal_leave_by creator check_recording_finished_for [creator, joiner1, joiner2] end diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index 7d44a27ea..081a15e38 100644 --- a/web/spec/support/utilities.rb +++ b/web/spec/support/utilities.rb @@ -208,6 +208,14 @@ def create_join_session(creator, joiners=[], genre=nil) end end +def formal_leave_by user + in_client(user) do + find('#session-leave').trigger(:click) + find('#btn-accept').trigger(:click) + expect(page).to have_selector('h2', text: 'feed') + end +end + def start_recording_with(creator, joiners=[], genre=nil) create_join_session(creator, joiners, genre) in_client(creator) do From b0dfa5501fd661a5a0b9d2d13516158923f5a79d Mon Sep 17 00:00:00 2001 From: Scott Comer Date: Sat, 22 Feb 2014 23:39:20 -0600 Subject: [PATCH 02/19] data model for geoipblocks --- ruby/lib/jam_ruby.rb | 1 + ruby/lib/jam_ruby/connection_manager.rb | 31 ++++++++++++++++--- ruby/lib/jam_ruby/models/geo_ip_blocks.rb | 20 ++++++++++++ .../jam_ruby/models/geo_ip_blocks_spec.rb | 19 ++++++++++++ 4 files changed, 67 insertions(+), 4 deletions(-) create mode 100644 ruby/lib/jam_ruby/models/geo_ip_blocks.rb create mode 100644 ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb diff --git a/ruby/lib/jam_ruby.rb b/ruby/lib/jam_ruby.rb index be78578a6..41ffebc8b 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -123,6 +123,7 @@ require "jam_ruby/models/facebook_signup" require "jam_ruby/models/recording_play" require "jam_ruby/models/feed" require "jam_ruby/models/jam_isp" +require "jam_ruby/models/geo_ip_blocks" include Jampb diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index ebb1b9345..2320218b6 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -57,6 +57,26 @@ module JamRuby if ip_address # todo turn ip_address string into a number, then fetch the locid and ispid and the other stuff... + + addr = JamIsp.ip_to_num(ip_address) + puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") + + isp = JamIsp.lookup(addr) + if isp.nil? then ispid = 0 else ispid = isp.coid end + puts("============= JamIsp.lookup returns #{ispid} for #{addr} =============") + + block = GeoIpBlocks.lookup(addr) + if block.nil? then locid = 0 else locid = block.locid end + puts("============= GeoIpBlocks.lookup returns #{locid} for #{addr} =============") + + locidispid = 0 + latitude = 0.0 + longitude = 0.0 + countrycode = 'US' + region = 'TX' + city = 'Austin' + + # todo stuff this stuff into the connection records end sql =< Date: Sun, 23 Feb 2014 07:53:33 -0500 Subject: [PATCH 03/19] VRFS-807 modeled after leave session dialog --- web/app/assets/stylesheets/client/client.css | 1 + web/app/assets/stylesheets/client/terms.css.scss | 7 +++++++ web/app/views/clients/_terms.html.erb | 8 ++++---- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 web/app/assets/stylesheets/client/terms.css.scss diff --git a/web/app/assets/stylesheets/client/client.css b/web/app/assets/stylesheets/client/client.css index 773851dda..c403ed71f 100644 --- a/web/app/assets/stylesheets/client/client.css +++ b/web/app/assets/stylesheets/client/client.css @@ -41,6 +41,7 @@ *= require ./localRecordingsDialog *= require ./serverErrorDialog *= require ./leaveSessionWarning + *= require ./terms *= require ./createSession *= require ./genreSelector *= require ./sessionList diff --git a/web/app/assets/stylesheets/client/terms.css.scss b/web/app/assets/stylesheets/client/terms.css.scss new file mode 100644 index 000000000..107e307eb --- /dev/null +++ b/web/app/assets/stylesheets/client/terms.css.scss @@ -0,0 +1,7 @@ +#session-terms-conditions { + max-width:550px; + min-height:0; + p { + line-height:22px; + } +} \ No newline at end of file diff --git a/web/app/views/clients/_terms.html.erb b/web/app/views/clients/_terms.html.erb index 06627a4c3..cdc1be070 100644 --- a/web/app/views/clients/_terms.html.erb +++ b/web/app/views/clients/_terms.html.erb @@ -1,5 +1,5 @@ -
+
<%= image_tag "content/icon_add.png", {:width => 19, :height => 19, :class => 'content-icon' } %>

Terms and Conditions

@@ -9,12 +9,12 @@ I agree that intellectual property ownership of any musical works created during this session shall be governed by the terms of the Creative Commons CC BY-NC-SA license in accordance with the JamKazam Terms of Service.

-
- CANCEL -
+
+ CANCEL +

\ No newline at end of file From a8144d4b2815aadc4ed2ffe35bef3ab244fc0491 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 08:19:29 -0500 Subject: [PATCH 04/19] show user hover bubble in sidebar only if avatar or name is hovered, not the entire row --- web/app/views/clients/_sidebar.html.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/web/app/views/clients/_sidebar.html.erb b/web/app/views/clients/_sidebar.html.erb index 10c6a0bd5..102870c58 100644 --- a/web/app/views/clients/_sidebar.html.erb +++ b/web/app/views/clients/_sidebar.html.erb @@ -170,9 +170,9 @@ <% end %> From c79c841b57d49d4190289b66d55a33354e4b3b6c Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 13:31:18 -0500 Subject: [PATCH 06/19] fix avatar url for session invitation popup notification --- web/app/assets/javascripts/sidebar.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 32e91cea1..204b324d8 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -553,8 +553,7 @@ var participants = []; rest.getSession(payload.session_id).done(function(response) { $.each(response.participants, function(index, val) { - logger.debug(val.user.photo_url + "," + val.user.name); - participants.push({"photo_url": val.user.photo_url, "name": val.user.name}); + participants.push({"photo_url": context.JK.resolveAvatarUrl(val.user.photo_url), "name": val.user.name}); }); }).error(app.ajaxError); @@ -563,7 +562,7 @@ $.each(participants, function(index, val) { if (index < 4) { - participantHtml += "" + val.name + ""; + participantHtml += "" + val.name + ""; } }); From f318558c4bb66b63e7741d57dc6968458e4d81b8 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 13:32:03 -0500 Subject: [PATCH 07/19] VRFS-1215 fix UserMailer so templates are loaded correctly --- ruby/lib/jam_ruby/app/mailers/user_mailer.rb | 105 ++++++++++++++++--- 1 file changed, 91 insertions(+), 14 deletions(-) diff --git a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb index 9fbc5bf66..dcae48185 100644 --- a/ruby/lib/jam_ruby/app/mailers/user_mailer.rb +++ b/ruby/lib/jam_ruby/app/mailers/user_mailer.rb @@ -92,78 +92,155 @@ def friend_request(email, msg) subject = "You have a new friend request on JamKazam" unique_args = {:type => "friend_request"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def friend_request_accepted(email, msg) subject = "You have a new friend on JamKazam" unique_args = {:type => "friend_request_accepted"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def new_user_follower(email, msg) subject = "You have a new follower on JamKazam" unique_args = {:type => "new_user_follower"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def new_band_follower(email, msg) subject = "Your band has a new follower on JamKazam" unique_args = {:type => "new_band_follower"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def session_invitation(email, msg) subject = "You have been invited to a session on JamKazam" unique_args = {:type => "session_invitation"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def musician_session_join(email, msg) subject = "Someone you know is in a session on JamKazam" unique_args = {:type => "musician_session_join"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def band_session_join(email, msg) subject = "A band that you follow has joined a session" unique_args = {:type => "band_session_join"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def musician_recording_saved(email, msg) subject = msg unique_args = {:type => "musician_recording_saved"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def band_recording_saved(email, msg) subject = msg unique_args = {:type => "band_recording_saved"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def band_invitation(email, msg) subject = "You have been invited to join a band on JamKazam" unique_args = {:type => "band_invitation"} - send_notification(email, subject, msg, unique_args) + + @body = msg + sendgrid_category "Notification" + sendgrid_unique_args :type => unique_args[:type] + mail(:to => email, :subject => subject) do |format| + format.text + format.html + end end def band_invitation_accepted(email, msg) subject = "Your band invitation was accepted" unique_args = {:type => "band_invitation_accepted"} - 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(:bcc => email, :subject => subject) do |format| + mail(:to => email, :subject => subject) do |format| format.text format.html end end + + # def send_notification(email, subject, msg, unique_args) + # @body = msg + # sendgrid_category "Notification" + # sendgrid_unique_args :type => unique_args[:type] + # mail(:to => email, :subject => subject) do |format| + # format.text + # format.html + # end + # end ############################################################################################# end From 0a2da28ae4b02a399ad66ace315012889ecdfcab Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 14:08:28 -0500 Subject: [PATCH 08/19] VRFS-1215 must call deliver to send emails --- ruby/lib/jam_ruby/models/notification.rb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 48c363a1b..f442d696e 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -232,7 +232,7 @@ module JamRuby @@mq_router.publish_to_user(friend_id, msg) else - UserMailer.friend_request(friend.email, notification_msg) + UserMailer.friend_request(friend.email, notification_msg).deliver end end @@ -260,7 +260,7 @@ module JamRuby @@mq_router.publish_to_user(user.id, msg) else - UserMailer.friend_request_accepted(user.email, notification_msg) + UserMailer.friend_request_accepted(user.email, notification_msg).deliver end end @@ -287,7 +287,7 @@ module JamRuby @@mq_router.publish_to_user(user.id, msg) else - UserMailer.new_user_follower(user.email, notification_msg) + UserMailer.new_user_follower(user.email, notification_msg).deliver end end end @@ -321,7 +321,7 @@ module JamRuby @@mq_router.publish_to_user(bm.user_id, msg) else - UserMailer.new_band_follower(bm.user.email, notification_msg) + UserMailer.new_band_follower(bm.user.email, notification_msg).deliver end end end @@ -350,7 +350,7 @@ module JamRuby @@mq_router.publish_to_user(receiver.id, msg) else - UserMailer.session_invitation(receiver.email, notification_msg) + UserMailer.session_invitation(receiver.email, notification_msg).deliver end end @@ -499,7 +499,7 @@ module JamRuby # send email notifications unless offline_ff.empty? - UserMailer.musician_session_join(offline_ff.map! {|f| f.email}, notification_msg) + UserMailer.musician_session_join(offline_ff.map! {|f| f.email}, notification_msg).deliver end end end @@ -540,7 +540,7 @@ module JamRuby # send email notifications unless offline_followers.empty? - UserMailer.band_session_join(offline_followers.map! {|f| f.email}, notification_msg) + UserMailer.band_session_join(offline_followers.map! {|f| f.email}, notification_msg).deliver end end end @@ -585,7 +585,7 @@ module JamRuby # send email notifications unless offline_ff.empty? - UserMailer.musician_recording_saved(offline_ff.map! {|f| f.email}, notification_msg) + UserMailer.musician_recording_saved(offline_ff.map! {|f| f.email}, notification_msg).deliver end end @@ -620,7 +620,7 @@ module JamRuby # send email notifications unless offline_followers.empty? - UserMailer.band_recording_saved(offline_followers.map! {|f| f.email}, notification_msg) + UserMailer.band_recording_saved(offline_followers.map! {|f| f.email}, notification_msg).deliver end end @@ -704,7 +704,7 @@ module JamRuby @@mq_router.publish_to_user(receiver.id, msg) else - UserMailer.band_invitation(receiver.email, notification_msg) + UserMailer.band_invitation(receiver.email, notification_msg).deliver end end @@ -731,7 +731,7 @@ module JamRuby @@mq_router.publish_to_user(receiver.id, msg) else - UserMailer.band_invitation_accepted(receiver.email, notification_msg) + UserMailer.band_invitation_accepted(receiver.email, notification_msg).deliver end end From 83b4260b918b6defccc71eef9d4e313e7859f092 Mon Sep 17 00:00:00 2001 From: Brian Smith Date: Sun, 23 Feb 2014 15:47:53 -0500 Subject: [PATCH 09/19] VRFS-759 VRFS-1221 delete session notifications when session ends in db and sidebar, fix listen button for sessions and recordings --- pb/src/client_container.proto | 2 +- ruby/lib/jam_ruby/message_factory.rb | 12 +++++ .../jam_ruby/models/music_session_history.rb | 4 ++ ruby/lib/jam_ruby/models/notification.rb | 28 ++++++---- web/app/assets/javascripts/sidebar.js | 53 ++++++++++++------- web/app/assets/javascripts/utils.js | 16 ++++++ web/app/views/clients/_sidebar.html.erb | 2 +- 7 files changed, 86 insertions(+), 31 deletions(-) diff --git a/pb/src/client_container.proto b/pb/src/client_container.proto index 0e54b3528..4d06a0319 100644 --- a/pb/src/client_container.proto +++ b/pb/src/client_container.proto @@ -252,7 +252,7 @@ message SessionInvitation { } message SessionEnded { - + optional string session_id = 1; } message JoinRequest { diff --git a/ruby/lib/jam_ruby/message_factory.rb b/ruby/lib/jam_ruby/message_factory.rb index 2c91c16da..956943d7e 100644 --- a/ruby/lib/jam_ruby/message_factory.rb +++ b/ruby/lib/jam_ruby/message_factory.rb @@ -300,6 +300,18 @@ module JamRuby ) end + def session_ended(receiver_id, session_id) + session_ended = Jampb::SessionEnded.new( + :session_id => session_id + ) + + Jampb::ClientMessage.new( + :type => ClientMessage::Type::SESSION_ENDED, + :route_to => USER_TARGET_PREFIX + receiver_id, + :session_ended => session_ended + ) + end + # create a join request session message def join_request(join_request_id, session_id, photo_url, msg, notification_id, created_at) req = Jampb::JoinRequest.new( diff --git a/ruby/lib/jam_ruby/models/music_session_history.rb b/ruby/lib/jam_ruby/models/music_session_history.rb index e504db256..f728493b5 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -172,6 +172,10 @@ module JamRuby .first hist.end_history if hist + + puts "**************NOTIFICATION SESSION ENDED**************" + + Notification.send_session_ended(session_id) end def remove_non_alpha_num(token) diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index f442d696e..ab6708ca4 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -47,10 +47,6 @@ module JamRuby @@mq_router = MQRouter.new @@message_factory = MessageFactory.new - def delete_all(session_id) - Notification.delete_all "(session_id = '#{session_id}')" - end - ################### HELPERS ################### def retrieve_friends(connection, user_id) friend_ids = [] @@ -354,10 +350,19 @@ module JamRuby end end - def send_session_ended(music_session, connection) + def send_session_ended(session_id) - # TODO: this should actually publish to all users who have a notification for this session - @@mq_router.server_publish_to_session(music_session, nil, sender = {:client_id => connection.client_id}) + notifications = Notification.where(:session_id => session_id) + + # publish to all users who have a notification for this session + # TODO: do this in BULK or in async block + notifications.each do |n| + puts "*************SENDING SESSION_ENDED TO #{n.target_user_id}***************" + msg = @@message_factory.session_ended(n.target_user_id, session_id) + @@mq_router.publish_to_user(n.target_user_id, msg) + end + + Notification.delete_all "(session_id = '#{session_id}')" end def send_join_request(music_session, join_request, text) @@ -467,8 +472,8 @@ module JamRuby follower_users = user_followers.map { |uf| uf.user } friends_and_followers = friend_users.concat(follower_users).uniq - # remove anyone in the session - friends_and_followers = friends_and_followers - music_session.users + # remove anyone in the session and invited musicians + friends_and_followers = friends_and_followers - music_session.users - music_session.invited_musicians notifications, online_ff, offline_ff = [], [], [] notification_msg = format_msg(NotificationTypes::MUSICIAN_SESSION_JOIN, user) @@ -478,6 +483,7 @@ module JamRuby notification.description = NotificationTypes::MUSICIAN_SESSION_JOIN notification.source_user_id = user.id notification.target_user_id = ff.id + notification.session_id = music_session.id notification.save if ff.online @@ -519,6 +525,7 @@ module JamRuby notification.band_id = band.id notification.description = NotificationTypes::BAND_SESSION_JOIN notification.target_user_id = follower.id + notification.session_id = music_session.id notification.save if follower.online @@ -562,9 +569,10 @@ module JamRuby friends_and_followers.each do |ff| notification = Notification.new - notification.description = NotificationTypes::MUSICIAN_SESSION_JOIN + notification.description = NotificationTypes::MUSICIAN_RECORDING_SAVED notification.source_user_id = user.id notification.target_user_id = ff.id + notification.recording_id = recording.id notification.save if ff.online diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 204b324d8..d670f8ea6 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -143,6 +143,7 @@ var template = $('#template-notification-panel').html(); var notificationHtml = context.JK.fillTemplate(template, { notificationId: val.notification_id, + sessionId: val.sessionId, avatar_url: context.JK.resolveAvatarUrl(val.photo_url), text: val.formatted_msg, date: context.JK.formatDateTime(val.created_at) @@ -158,13 +159,14 @@ function initializeActions(payload, type) { var $notification = $('li[notification-id=' + payload.notification_id + ']'); + var $btnNotificationAction = '#btn-notification-action'; // wire up "x" button to delete notification $notification.find('#img-delete-notification').click(deleteNotificationHandler); // customize action buttons based on notification type if (type === context.JK.MessageType.FRIEND_REQUEST) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('ACCEPT'); $action_btn.click(function() { acceptFriendRequest({ "friend_request_id": payload.friend_request_id, "notification_id": payload.notification_id }); @@ -180,7 +182,7 @@ } else if (type === context.JK.MessageType.SESSION_INVITATION) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('JOIN'); $action_btn.click(function() { openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id }); @@ -188,7 +190,7 @@ } else if (type === context.JK.MessageType.JOIN_REQUEST) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('APPROVE'); $action_btn.click(function() { approveJoinRequest({ "join_request_id": payload.join_request_id, "notification_id": payload.notification_id }); @@ -196,7 +198,7 @@ } else if (type === context.JK.MessageType.JOIN_REQUEST_APPROVED) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('JOIN'); $action_btn.click(function() { openTerms({ "session_id": payload.session_id, "notification_id": payload.notification_id }); @@ -208,15 +210,17 @@ } else if (type === context.JK.MessageType.MUSICIAN_SESSION_JOIN || type === context.JK.MessageType.BAND_SESSION_JOIN) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('LISTEN'); + $action_btn.attr('href', '/sessions/' + payload.session_id); + $action_btn.attr('rel', 'external'); $action_btn.click(function() { listenToSession({ "session_id": payload.session_id, "notification_id": payload.notification_id }); }); } else if (type === context.JK.MessageType.MUSICIAN_RECORDING_SAVED || type === context.JK.MessageType.BAND_RECORDING_SAVED) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('LISTEN'); $action_btn.click(function() { listenToRecording({ "recording_id": payload.recording_id, "notification_id": payload.notification_id }); @@ -229,7 +233,7 @@ } else if (type === context.JK.MessageType.BAND_INVITATION) { - var $action_btn = $notification.find('#btn-notification-action'); + var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('ACCEPT'); $action_btn.click(function() { acceptBandInvitation({ "band_invitation_id": payload.band_invitation_id, "band_id": payload.band_id, "notification_id": payload.notification_id }); @@ -335,6 +339,7 @@ var template = $("#template-notification-panel").html(); var notificationHtml = context.JK.fillTemplate(template, { notificationId: payload.notification_id, + sessionId: payload.session_id, avatar_url: context.JK.resolveAvatarUrl(payload.photo_url), text: sidebarText, date: context.JK.formatDateTime(payload.created_at) @@ -592,6 +597,17 @@ function registerSessionEnded() { // TODO: this should clean up all notifications related to this session + context.JK.JamServer.registerMessageCallback(context.JK.MessageType.SESSION_ENDED, function(header, payload) { + logger.debug("Handling SESSION_ENDED msg " + JSON.stringify(payload)); + deleteSessionNotifications(payload.session_id); + }); + } + + // remove all notifications for this session + function deleteSessionNotifications(sessionId) { + console.log("sessionId=%o", sessionId); + $('li[session-id=' + sessionId + ']').hide(); + decrementNotificationCount(); } function registerJoinRequest() { @@ -680,13 +696,8 @@ var recordingId = payload.recording_id; - if(recordingId&& context.JK.CurrentSessionModel.recordingModel.isRecording(recordingId)) { + if(recordingId && context.JK.CurrentSessionModel.recordingModel.isRecording(recordingId)) { context.JK.CurrentSessionModel.recordingModel.onServerStopRecording(recordingId); - /**app.notify({ - "title": "Recording Stopped", - "text": payload.username + " has left the session.", - "icon_url": context.JK.resolveAvatarUrl(payload.photo_url) - }); */ } else { app.notify({ @@ -712,7 +723,8 @@ "ok_text": "LISTEN", "ok_callback": listenToSession, "ok_callback_args": { - "session_id": payload.session_id + "session_id": payload.session_id, + "notification_id": payload.notification_id } }); }); @@ -733,7 +745,8 @@ "ok_text": "LISTEN", "ok_callback": listenToSession, "ok_callback_args": { - "session_id": payload.session_id + "session_id": payload.session_id, + "notification_id": payload.notification_id } }); }); @@ -741,7 +754,7 @@ function listenToSession(args) { deleteNotification(args.notification_id); - context.location = '/client#/session/' + args.session_id; + context.JK.popExternalLink('/recordings/' + args.session_id); } function registerMusicianRecordingSaved() { @@ -758,7 +771,8 @@ "ok_text": "LISTEN", "ok_callback": listenToRecording, "ok_callback_args": { - "recording_id": payload.recording_id + "recording_id": payload.recording_id, + "notification_id": payload.notification_id } }); }); @@ -779,7 +793,8 @@ "ok_text": "LISTEN", "ok_callback": listenToRecording, "ok_callback_args": { - "recording_id": payload.recording_id + "recording_id": payload.recording_id, + "notification_id": payload.notification_id } }); }); @@ -787,7 +802,7 @@ function listenToRecording(args) { deleteNotification(args.notification_id); - context.location = '/client#/recording/' + args.recording_id; + context.JK.popExternalLink('/recordings/' + args.recording_id); } function registerRecordingStarted() { diff --git a/web/app/assets/javascripts/utils.js b/web/app/assets/javascripts/utils.js index 2cc124c70..8af730244 100644 --- a/web/app/assets/javascripts/utils.js +++ b/web/app/assets/javascripts/utils.js @@ -549,6 +549,22 @@ }); } + context.JK.popExternalLink = function(href) { + if(!context.jamClient) { + return; + } + + if (href) { + // make absolute if not already + if(href.indexOf('http') != 0 && href.indexOf('mailto') != 0) { + href = window.location.protocol + '//' + window.location.host + href; + } + + context.jamClient.OpenSystemBrowser(href); + } + return false; + } + context.JK.checkbox = function($checkbox) { $checkbox.iCheck({ checkboxClass: 'icheckbox_minimal', diff --git a/web/app/views/clients/_sidebar.html.erb b/web/app/views/clients/_sidebar.html.erb index 102870c58..77e5e9489 100644 --- a/web/app/views/clients/_sidebar.html.erb +++ b/web/app/views/clients/_sidebar.html.erb @@ -198,7 +198,7 @@ @@ -54,9 +92,9 @@


diff --git a/web/app/views/music_sessions/show.html.erb b/web/app/views/music_sessions/show.html.erb index a662c1c8e..12705cbee 100644 --- a/web/app/views/music_sessions/show.html.erb +++ b/web/app/views/music_sessions/show.html.erb @@ -53,7 +53,7 @@
<% if !@music_session.music_session.nil? && !@music_session.music_session.mount.blank? %> - + <%= image_tag "content/icon_playbutton.png", {:id => "imgPlayPause", :width => 20, :height => 20, :alt => ""} %> <% end %> diff --git a/web/config/routes.rb b/web/config/routes.rb index 3fa2edf92..79286139c 100644 --- a/web/config/routes.rb +++ b/web/config/routes.rb @@ -161,7 +161,7 @@ SampleApp::Application.routes.draw do # user likes match '/users/:id/likings' => 'api_users#liking_index', :via => :get, :as => 'api_user_liking_index' match '/users/:id/likings' => 'api_users#liking_create', :via => :post - match '/users/:id/likings' => 'api_users#liking_destroy', :via => :delete + match '/users/:id/likings/:likable_id' => 'api_users#liking_destroy', :via => :delete # user followers match '/users/:id/followers' => 'api_users#follower_index', :via => :get, :as => 'api_user_follower_index' @@ -169,7 +169,7 @@ SampleApp::Application.routes.draw do # user followings match '/users/:id/followings' => 'api_users#following_index', :via => :get, :as => 'api_user_following_index' match '/users/:id/followings' => 'api_users#following_create', :via => :post - match '/users/:id/followings' => 'api_users#following_destroy', :via => :delete + match '/users/:id/followings/:followable_id' => 'api_users#following_destroy', :via => :delete # favorites match '/users/:id/favorites' => 'api_users#favorite_index', :via => :get, :as => 'api_favorite_index' diff --git a/web/spec/requests/users_api_spec.rb b/web/spec/requests/users_api_spec.rb index 80d8bd5a8..6e3df944a 100644 --- a/web/spec/requests/users_api_spec.rb +++ b/web/spec/requests/users_api_spec.rb @@ -56,7 +56,7 @@ describe "User API", :type => :api do def delete_user_like(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/likings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/likings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end @@ -99,7 +99,7 @@ describe "User API", :type => :api do def delete_user_following(authenticated_user, source_user, target_user) login(authenticated_user.email, authenticated_user.password, 200, true) - delete "/api/users/#{source_user.id}/followings.json", { :target_entity_id => target_user.id }.to_json, "CONTENT_TYPE" => 'application/json' + delete "/api/users/#{source_user.id}/followings/#{target_user.id}.json", "CONTENT_TYPE" => 'application/json' return last_response end