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.rb b/ruby/lib/jam_ruby.rb index be78578a6..10eb7eef3 100755 --- a/ruby/lib/jam_ruby.rb +++ b/ruby/lib/jam_ruby.rb @@ -123,6 +123,8 @@ 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" +require "jam_ruby/models/geo_ip_locations" include Jampb 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 diff --git a/ruby/lib/jam_ruby/connection_manager.rb b/ruby/lib/jam_ruby/connection_manager.rb index ebb1b9345..086b14a22 100644 --- a/ruby/lib/jam_ruby/connection_manager.rb +++ b/ruby/lib/jam_ruby/connection_manager.rb @@ -56,7 +56,29 @@ module JamRuby end if ip_address - # todo turn ip_address string into a number, then fetch the locid and ispid and the other stuff... + # todo turn ip_address string into a number, then fetch the isp and block records + + addr = JamIsp.ip_to_num(ip_address) + #puts("============= JamIsp.ip_to_num returns #{addr} for #{ip_address} =============") + + isp = JamIsp.lookup(addr) + #puts("============= JamIsp.lookup returns #{isp.inspect} for #{addr} =============") + if isp.nil? then ispid = 0 else ispid = isp.coid end + + block = GeoIpBlocks.lookup(addr) + #puts("============= GeoIpBlocks.lookup returns #{block.inspect} for #{addr} =============") + if block.nil? then locid = 0 else locid = block.locid end + + location = GeoIpLocations.lookup(locid) + + locidispid = 0 + latitude = 0.0 + longitude = 0.0 + countrycode = 'US' + region = 'TX' + city = 'Austin' + + # todo stuff this stuff into the connection records end sql =< 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/connection.rb b/ruby/lib/jam_ruby/models/connection.rb index c1fbec61f..a090629d0 100644 --- a/ruby/lib/jam_ruby/models/connection.rb +++ b/ruby/lib/jam_ruby/models/connection.rb @@ -101,6 +101,17 @@ module JamRuby if music_session.is_recording? errors.add(:music_session, ValidationMessages::CANT_JOIN_RECORDING_SESSION) end + + unless user.admin? + num_sessions = Connection.where(:user_id => user_id) + .where(["(music_session_id IS NOT NULL) AND (aasm_state != ?)",EXPIRED_STATE.to_s]) + .count + if 0 < num_sessions + errors.add(:music_session, ValidationMessages::CANT_JOIN_MULTIPLE_SESSIONS) + return false; + end + end + return true end diff --git a/ruby/lib/jam_ruby/models/geo_ip_blocks.rb b/ruby/lib/jam_ruby/models/geo_ip_blocks.rb new file mode 100644 index 000000000..417d5bb95 --- /dev/null +++ b/ruby/lib/jam_ruby/models/geo_ip_blocks.rb @@ -0,0 +1,20 @@ +module JamRuby + class GeoIpBlocks < ActiveRecord::Base + + self.table_name = 'geoipblocks' + + def self.lookup(ipnum) + GeoIpBlocks.select(:locid) + .where('geom && ST_MakePoint(?, 0) AND ? BETWEEN beginip AND endip', ipnum, ipnum) + .limit(1) + .first + end + + def self.make_row(beginip, endip, locid) + c = ActiveRecord::Base.connection.raw_connection + c.prepare('blah', 'insert into geoipblocks (beginip, endip, locid, geom) values($1::bigint, $2::bigint, $3, ST_MakeEnvelope($1::bigint, -1, $2::bigint, 1))') + c.exec_prepared('blah', [beginip, endip, locid]) + c.exec("deallocate blah") + end + end +end diff --git a/ruby/lib/jam_ruby/models/geo_ip_locations.rb b/ruby/lib/jam_ruby/models/geo_ip_locations.rb new file mode 100644 index 000000000..28dcfa0ef --- /dev/null +++ b/ruby/lib/jam_ruby/models/geo_ip_locations.rb @@ -0,0 +1,20 @@ +module JamRuby + class GeoIpLocations < ActiveRecord::Base + + self.table_name = 'geoiplocations' + + def self.lookup(locid) + GeoIpLocations.select('locid, countrycode, region, city, latitude, longitude') + .where(:locid => locid) + .limit(1) + .first + end + + def self.make_row(locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode) + c = ActiveRecord::Base.connection.raw_connection + c.prepare('blah', 'insert into geoiplocations (locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode, geog) values($1, $2, $3, $4, $5, $6, $7, $8, $9, ST_SetSRID(ST_MakePoint($7, $6), 4326)::geography)') + c.exec_prepared('blah', [locid, countrycode, region, city, postalcode, latitude, longitude, metrocode, areacode]) + c.exec("deallocate blah") + end + end +end diff --git a/ruby/lib/jam_ruby/models/music_session_history.rb b/ruby/lib/jam_ruby/models/music_session_history.rb index e504db256..553c03bac 100644 --- a/ruby/lib/jam_ruby/models/music_session_history.rb +++ b/ruby/lib/jam_ruby/models/music_session_history.rb @@ -172,6 +172,8 @@ module JamRuby .first hist.end_history if hist + + 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 48c363a1b..6bb3ec67a 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 = [] @@ -232,7 +228,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 +256,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 +283,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 +317,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,14 +346,22 @@ 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 - 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| + 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 +471,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 +482,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 @@ -499,7 +504,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 @@ -519,6 +524,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 @@ -540,7 +546,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 @@ -562,9 +568,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 @@ -585,7 +592,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 +627,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 +711,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 +738,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 diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 99bc51a4e..0c0211fc7 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -46,7 +46,6 @@ describe ConnectionManager do end it "can't create two client_ids of same value" do - client_id = "client_id1" user_id = create_user("test", "user1", "user1@jamkazam.com") @@ -425,5 +424,36 @@ describe ConnectionManager do assert_num_connections(client_id, 0) end + + it "join_music_session fails if user has music_session already active" do + user_id = create_user("test", "user11", "user11@jamkazam.com") + + user = User.find(user_id) + music_session = MusicSession.find(create_music_session(user_id)) + + client_id = Faker::Number.number(20) + @connman.create_connection(user_id, client_id, "1.1.1.1") + connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS) + + client_id = Faker::Number.number(20) + @connman.create_connection(user_id, client_id, Faker::Internet.ip_v4_address) + music_session = MusicSession.find(create_music_session(user_id)) + connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS) + + connection.errors.size.should == 1 + connection.errors.get(:music_session).should == [ValidationMessages::CANT_JOIN_MULTIPLE_SESSIONS] + + user.update_attribute(:admin, true) + client_id = Faker::Number.number(20) + @connman.create_connection(user_id, client_id, "1.1.1.1") + music_session = MusicSession.find(create_music_session(user_id)) + connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS) + client_id = Faker::Number.number(20) + @connman.create_connection(user_id, client_id, Faker::Internet.ip_v4_address) + music_session = MusicSession.find(create_music_session(user_id)) + connection = @connman.join_music_session(user, client_id, music_session, true, TRACKS) + connection.errors.size.should == 0 + end + end diff --git a/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb b/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb new file mode 100644 index 000000000..dd914143c --- /dev/null +++ b/ruby/spec/jam_ruby/models/geo_ip_blocks_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe GeoIpBlocks do + + before do + GeoIpBlocks.delete_all + GeoIpBlocks.make_row(0x00000000, 0xffffffff, 17192) + end + + it "count" do GeoIpBlocks.count.should == 1 end + + let(:first) { GeoIpBlocks.lookup(0x01020304) } + let(:second) { GeoIpBlocks.lookup(0x02030405) } + let(:seventh) { GeoIpBlocks.lookup(9999999999) } # bogus + + it "first.locid" do first.locid.should == 17192 end + it "second.locid" do second.locid.should == 17192 end + it "seventh" do seventh.should be_nil end +end diff --git a/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb new file mode 100644 index 000000000..c6be8a6df --- /dev/null +++ b/ruby/spec/jam_ruby/models/geo_ip_locations_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper' + +describe GeoIpLocations do + + before do + GeoIpLocations.delete_all + GeoIpLocations.make_row(17192, 'US', 'TX', 'Austin', '78749', 30.2076, -97.8587, 635, '512') + GeoIpLocations.make_row(48086, 'MX', '28', 'Matamoros', '', 25.8833, -97.5000, nil, '') + end + + it "count" do GeoIpLocations.count.should == 2 end + + let(:first) { GeoIpLocations.lookup(17192) } + let(:second) { GeoIpLocations.lookup(48086) } + let(:third) { GeoIpLocations.lookup(999999) } # bogus + + it "first" do + first.locid.should == 17192 + first.countrycode.should eql('US') + first.region.should eql('TX') + first.city.should eql('Austin') + first.latitude.should == 30.2076 + first.longitude.should == -97.8587 + end + + it "second" do + second.locid.should == 48086 + second.countrycode.should eql('MX') + second.region.should eql('28') + second.city.should eql('Matamoros') + second.latitude.should == 25.8833 + second.longitude.should == -97.5000 + end + + it "third" do third.should be_nil end +end diff --git a/web/app/assets/javascripts/bandProfile.js b/web/app/assets/javascripts/bandProfile.js index 20ff38afc..7027661ea 100644 --- a/web/app/assets/javascripts/bandProfile.js +++ b/web/app/assets/javascripts/bandProfile.js @@ -47,55 +47,53 @@ /****************** MAIN PORTION OF SCREEN *****************/ function addFollowing(isBand, id) { - var newFollowing = {}; + var newFollowing = {}; - if (!isBand) { - newFollowing.user_id = id; - } - else { - newFollowing.band_id = id; - } + if (!isBand) { + newFollowing.user_id = id; + } + else { + newFollowing.band_id = id; + } - rest.addFollowing(newFollowing) - .done(function() { - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(true); - } - else { - configureMemberFollowingButton(true, id); - } - }) - .fail(app.ajaxError); + rest.addFollowing(newFollowing) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) + 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(true); + } + else { + configureMemberFollowingButton(true, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) - .done(function() { - renderActive(); // refresh stats - if (isBand) { - var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; - var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; - $('#band-profile-follower-stats').html(newCount + text); - configureBandFollowingButton(false); - } - else { - configureMemberFollowingButton(false, id); - } - }) - .fail(app.ajaxError); + rest.removeFollowing(id) + .done(function() { + if (isBand) { + var newCount = parseInt($("#band-profile-follower-stats").text()) - 1; + var text = newCount > 1 || newCount == 0 ? " Followers" : " Follower"; + $('#band-profile-follower-stats').html(newCount + text); + configureBandFollowingButton(false); + } + else { + configureMemberFollowingButton(false, id); + } + renderActive(); + }) + .fail(app.ajaxError); } function configureBandFollowingButton(following) { $('#btn-follow-band').unbind("click"); if (following) { - $('#btn-follow-band').text('STOP FOLLOWING'); + $('#btn-follow-band').text('UNFOLLOW'); $('#btn-follow-band').click(function() { removeFollowing(true, bandId); return false; @@ -121,7 +119,7 @@ $btnFollowMember.unbind("click"); if (following) { - $btnFollowMember.text('UN-FOLLOW'); + $btnFollowMember.text('UNFOLLOW'); $btnFollowMember.click(function() { removeFollowing(false, userId); return false; diff --git a/web/app/assets/javascripts/hoverBand.js b/web/app/assets/javascripts/hoverBand.js index fc6ca414c..2b98e8e62 100644 --- a/web/app/assets/javascripts/hoverBand.js +++ b/web/app/assets/javascripts/hoverBand.js @@ -49,20 +49,23 @@ }); var bandHtml = context.JK.fillTemplate(template, { - avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), - name: response.name, - location: response.location, - genres: genres.join(', '), - musicians: musicianHtml, - like_count: response.liker_count, - follower_count: response.follower_count, - recording_count: response.recording_count, - session_count: response.session_count, - biography: response.biography, - profile_url: "/client#/bandProfile/" + response.id + bandId: response.id, + avatar_url: context.JK.resolveBandAvatarUrl(response.photo_url), + name: response.name, + location: response.location, + genres: genres.join(', '), + musicians: musicianHtml, + like_count: response.liker_count, + follower_count: response.follower_count, + recording_count: response.recording_count, + session_count: response.session_count, + biography: response.biography, + followAction: response.is_following ? "removeBandFollowing" : "addBandFollowing", + profile_url: "/client#/bandProfile/" + response.id }); $(hoverSelector).append('

Band Detail

' + bandHtml); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -77,6 +80,20 @@ }); }; + function configureActionButtons(band) { + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile + if (!context.JK.currentUserId) { + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (band.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverFan.js b/web/app/assets/javascripts/hoverFan.js index b23342180..44d6ba075 100644 --- a/web/app/assets/javascripts/hoverFan.js +++ b/web/app/assets/javascripts/hoverFan.js @@ -56,12 +56,15 @@ location: response.location, friend_count: response.friend_count, follower_count: response.follower_count, + friendAction: response.is_friend ? "removeFanFriend" : (response.pending_friend_request ? "" : "sendFanFriendRequest"), + followAction: response.is_following ? "removeFanFollowing" : "addFanFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Fan Detail

' + fanHtml); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -76,6 +79,33 @@ }); }; + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + + $(btnFollowSelector, hoverSelector).click(function(evt) { + rest.removeFollowing(user.id); + }); + } + + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverMusician.js b/web/app/assets/javascripts/hoverMusician.js index 5a1e6d427..449e12380 100644 --- a/web/app/assets/javascripts/hoverMusician.js +++ b/web/app/assets/javascripts/hoverMusician.js @@ -75,12 +75,15 @@ session_count: response.session_count, session_display: sessionDisplayStyle, session_id: sessionId, + friendAction: response.is_friend ? "removeMusicianFriend" : (response.pending_friend_request ? "" : "sendMusicianFriendRequest"), + followAction: response.is_following ? "removeMusicianFollowing" : "addMusicianFollowing", biography: response.biography, followings: response.followings && response.followings.length > 0 ? followingHtml : "N/A", profile_url: "/client#/profile/" + response.id }); $(hoverSelector).append('

Musician Detail

' + musicianHtml); + configureActionButtons(response); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -95,6 +98,28 @@ }); }; + function configureActionButtons(user) { + var btnFriendSelector = "#btnFriend"; + var btnFollowSelector = "#btnFollow"; + + // if unauthenticated or authenticated user is viewing his own profile + if (!context.JK.currentUserId || context.JK.currentUserId === user.id) { + $(btnFriendSelector, hoverSelector).hide(); + $(btnFollowSelector, hoverSelector).hide(); + } + else { + if (user.is_friend) { + $(btnFriendSelector, hoverSelector).html('DISCONNECT'); + } + if (user.is_following) { + $(btnFollowSelector, hoverSelector).html('UNFOLLOW'); + } + if (user.pending_friend_request) { + $(btnFriendSelector, hoverSelector).hide(); + } + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverRecording.js b/web/app/assets/javascripts/hoverRecording.js index a3c43508a..e6fe325f3 100644 --- a/web/app/assets/javascripts/hoverRecording.js +++ b/web/app/assets/javascripts/hoverRecording.js @@ -55,6 +55,7 @@ }); $(hoverSelector).append('

Recording Detail

' + recordingHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -69,6 +70,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnLike", hoverSelector).hide(); + $("#btnShare", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/hoverSession.js b/web/app/assets/javascripts/hoverSession.js index 055d8cf17..373bd0cc6 100644 --- a/web/app/assets/javascripts/hoverSession.js +++ b/web/app/assets/javascripts/hoverSession.js @@ -50,6 +50,7 @@ }); $(hoverSelector).append('

Session Detail

' + sessionHtml); + toggleActionButtons(); }) .fail(function(xhr) { if(xhr.status >= 500) { @@ -64,6 +65,13 @@ }); }; + function toggleActionButtons() { + if (!context.JK.currentUserId) { + $("#btnLike", hoverSelector).hide(); + $("#btnShare", hoverSelector).hide(); + } + } + this.hideBubble = function() { $(hoverSelector).hide(); }; diff --git a/web/app/assets/javascripts/jam_rest.js b/web/app/assets/javascripts/jam_rest.js index 92fe43939..4363a11d8 100644 --- a/web/app/assets/javascripts/jam_rest.js +++ b/web/app/assets/javascripts/jam_rest.js @@ -451,7 +451,7 @@ }); } - function removeLike(options) { + function removeLike(likableId, options) { var id = getId(options); return $.ajax({ type: "DELETE", @@ -476,15 +476,13 @@ }); } - function removeFollowing(options) { + function removeFollowing(followableId, options) { var id = getId(options); - return $.ajax({ type: "DELETE", dataType: "json", contentType: 'application/json', - url: "/api/users/" + id + "/followings", - data: JSON.stringify(options), + url: "/api/users/" + id + "/followings/" + followableId, processData: false }); } diff --git a/web/app/assets/javascripts/jamkazam.js b/web/app/assets/javascripts/jamkazam.js index 0db35ebe6..49311fecc 100644 --- a/web/app/assets/javascripts/jamkazam.js +++ b/web/app/assets/javascripts/jamkazam.js @@ -99,6 +99,7 @@ context.jamClient.OnLoggedIn(payload.user_id, payload.token); $.cookie('client_id', payload.client_id); + app.initAfterConnect(); heartbeatMS = payload.heartbeat_interval * 1000; logger.debug("jamkazam.js.loggedIn(): clientId now " + app.clientId + "; Setting up heartbeat every " + heartbeatMS + " MS"); diff --git a/web/app/assets/javascripts/profile.js b/web/app/assets/javascripts/profile.js index ff15ff574..2b5a9d509 100644 --- a/web/app/assets/javascripts/profile.js +++ b/web/app/assets/javascripts/profile.js @@ -193,10 +193,10 @@ function configureFriendButton() { if (isFriend()) { - $('#btn-add-friend').text('REMOVE FRIEND'); + $('#btn-add-friend').text('DISCONNECT'); } else { - $('#btn-add-friend').text('ADD FRIEND'); + $('#btn-add-friend').text('CONNECT'); } } @@ -213,10 +213,7 @@ } function removeFollowing(isBand, id) { - var following = {}; - following.target_entity_id = id; - - rest.removeFollowing(following) + rest.removeFollowing(id) .done(function() { if (!isBand) { updateFollowingCount(-1); @@ -242,7 +239,7 @@ function configureFollowingButton() { if (isFollowing()) { - $('#btn-follow-user').text('STOP FOLLOWING'); + $('#btn-follow-user').text('UNFOLLOW'); } else { $('#btn-follow-user').text('FOLLOW'); diff --git a/web/app/assets/javascripts/searchResults.js b/web/app/assets/javascripts/searchResults.js index 884c2dbda..2f32a697d 100644 --- a/web/app/assets/javascripts/searchResults.js +++ b/web/app/assets/javascripts/searchResults.js @@ -117,23 +117,23 @@ selector = isSidebar ? '#sidebar-search-results' : '#search-results'; $(selector).append(invitationSentHtml); - // wire up button click handler if search result is not a friend or the current use + // wire up button click handler if search result is not a friend or the current user if (isSidebar) { var $sidebar = $('div[layout=sidebar] div[user-id=' + val.id + ']'); - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $sidebar.find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + // hide the button if the search result is already a friend + $sidebar.find('.btn-connect-friend').hide(); } else { - // hide the button if the search result is already a friend - $sidebar.find('.btn-connect-friend').hide(); + $sidebar.find('.btn-connect-friend').click(sendFriendRequest); } } else { - if (!val.is_friend && val.id !== context.JK.currentUserId) { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); + if (val.is_friend || val.pending_friend_request || val.id === context.JK.currentUserId) { + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); } else { - $('div[user-id=' + val.id + ']').find('.btn-connect-friend').hide(); + $('div[user-id=' + val.id + ']').find('.btn-connect-friend').click(sendFriendRequest); } } resultDivVisibility(val, isSidebar); diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 32e91cea1..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) @@ -553,8 +558,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 +567,7 @@ $.each(participants, function(index, val) { if (index < 4) { - participantHtml += "" + val.name + ""; + participantHtml += "" + val.name + ""; } }); @@ -593,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() { @@ -681,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({ @@ -713,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 } }); }); @@ -734,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 } }); }); @@ -742,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() { @@ -759,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 } }); }); @@ -780,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 } }); }); @@ -788,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/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/assets/stylesheets/web/recordings.css.scss b/web/app/assets/stylesheets/web/recordings.css.scss index 2e3ac9e24..4bd55f50e 100644 --- a/web/app/assets/stylesheets/web/recordings.css.scss +++ b/web/app/assets/stylesheets/web/recordings.css.scss @@ -55,4 +55,8 @@ position:absolute; top:3px; right:4px; +} + +#btnPlayPause { + position: relative; } \ No newline at end of file diff --git a/web/app/assets/stylesheets/web/sessions.css.scss b/web/app/assets/stylesheets/web/sessions.css.scss index 1e790e03a..ef513c304 100644 --- a/web/app/assets/stylesheets/web/sessions.css.scss +++ b/web/app/assets/stylesheets/web/sessions.css.scss @@ -16,4 +16,8 @@ font-size:15px; color:#cccc00; margin-left:20px; -}*/ \ No newline at end of file +}*/ + +#btnPlayPause { + position: relative; +} \ No newline at end of file diff --git a/web/app/controllers/api_users_controller.rb b/web/app/controllers/api_users_controller.rb index 9227ceb93..697bc2c95 100644 --- a/web/app/controllers/api_users_controller.rb +++ b/web/app/controllers/api_users_controller.rb @@ -1,6 +1,6 @@ class ApiUsersController < ApiController - before_filter :api_signed_in_user, :except => [:create, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring] + before_filter :api_signed_in_user, :except => [:create, :show, :signup_confirm, :auth_session_create, :complete, :finalize_update_email, :isp_scoring] before_filter :auth_user, :only => [:session_settings_show, :session_history_index, :session_user_history_index, :update, :delete, :liking_create, :liking_destroy, # likes :following_create, :following_show, :following_destroy, # followings @@ -202,7 +202,7 @@ class ApiUsersController < ApiController end def liking_destroy - User.delete_liking(params[:id], params[:target_entity_id]) + User.delete_liking(params[:id], params[:likable_id]) respond_with responder: ApiResponder, :status => 204 end @@ -230,7 +230,7 @@ class ApiUsersController < ApiController end def following_destroy - User.delete_following(params[:id], params[:target_entity_id]) + User.delete_following(params[:id], params[:followable_id]) respond_with responder: ApiResponder, :status => 204 end diff --git a/web/app/views/api_search/index.rabl b/web/app/views/api_search/index.rabl index 8164c4549..b6a902199 100644 --- a/web/app/views/api_search/index.rabl +++ b/web/app/views/api_search/index.rabl @@ -23,6 +23,10 @@ if @search.musicians_text_search? musician.friends?(current_user) end + node :pending_friend_request do |musician| + musician.pending_friend_request?(current_user) + end + child :musician_instruments => :instruments do attributes :instrument_id, :description, :proficiency_level, :priority end @@ -50,6 +54,10 @@ if @search.musicians_filter_search? @search.is_follower?(musician) end + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end + node :biography do |musician| musician.biography.nil? ? "" : musician.biography end @@ -112,6 +120,10 @@ if @search.fans_text_search? node :is_friend do |fan| fan.friends?(current_user) end + + node :pending_friend_request do |musician| + @search.pending_friend_request?(musician) + end } end diff --git a/web/app/views/clients/_account_identity.html.erb b/web/app/views/clients/_account_identity.html.erb index 345825c42..f54f5f3d5 100644 --- a/web/app/views/clients/_account_identity.html.erb +++ b/web/app/views/clients/_account_identity.html.erb @@ -55,8 +55,6 @@
-
- Forgot Password?
diff --git a/web/app/views/clients/_hoverBand.html.erb b/web/app/views/clients/_hoverBand.html.erb index ee8f0c5ff..7ee0fe2c2 100644 --- a/web/app/views/clients/_hoverBand.html.erb +++ b/web/app/views/clients/_hoverBand.html.erb @@ -5,25 +5,49 @@ @@ -54,9 +92,9 @@
- - - + + +


diff --git a/web/app/views/clients/_sidebar.html.erb b/web/app/views/clients/_sidebar.html.erb index 10c6a0bd5..77e5e9489 100644 --- a/web/app/views/clients/_sidebar.html.erb +++ b/web/app/views/clients/_sidebar.html.erb @@ -170,9 +170,9 @@ <% end %> diff --git a/web/app/views/recordings/show.html.erb b/web/app/views/recordings/show.html.erb index cec8f1caa..229d6d275 100644 --- a/web/app/views/recordings/show.html.erb +++ b/web/app/views/recordings/show.html.erb @@ -52,7 +52,7 @@
<% if @claimed_recording.has_mix? %> - + <%= 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/features/recordings_spec.rb b/web/spec/features/recordings_spec.rb index 57416c2d6..58f5aebe1 100644 --- a/web/spec/features/recordings_spec.rb +++ b/web/spec/features/recordings_spec.rb @@ -36,13 +36,13 @@ 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-leave-session').trigger(:click) expect(page).to have_selector('h2', text: 'feed') end + formal_leave_by creator check_recording_finished_for [creator, joiner1] end @@ -74,12 +74,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-leave-session').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/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 diff --git a/web/spec/support/utilities.rb b/web/spec/support/utilities.rb index 7d44a27ea..c3af90ebb 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-leave-session').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