From bbee617c4b5693d6aab9afb7159720602c3cbfb3 Mon Sep 17 00:00:00 2001 From: Steven Miers Date: Mon, 22 Dec 2014 14:23:05 -0600 Subject: [PATCH] VRFS-1960 : Jam Track Signed Notification, usage in notificationPanel, and spec. --- db/up/jam_track_updates.sql | 1 + pb/src/client_container.proto | 2 +- .../jam_ruby/constants/notification_types.rb | 2 ++ ruby/lib/jam_ruby/message_factory.rb | 10 ++++++---- ruby/lib/jam_ruby/models/jam_track_right.rb | 12 ++++++++++++ ruby/lib/jam_ruby/models/notification.rb | 17 ++++++++++++++--- ruby/lib/jam_ruby/resque/jam_tracks_builder.rb | 14 +++++++++++--- web/app/assets/javascripts/notificationPanel.js | 6 ++++++ .../api_jam_tracks_controller_spec.rb | 4 +--- 9 files changed, 54 insertions(+), 14 deletions(-) diff --git a/db/up/jam_track_updates.sql b/db/up/jam_track_updates.sql index 257b3b7aa..3ee39e190 100644 --- a/db/up/jam_track_updates.sql +++ b/db/up/jam_track_updates.sql @@ -32,6 +32,7 @@ ALTER TABLE jam_track_rights ADD COLUMN download_count INTEGER NOT NULL DEFAULT 0, ADD COLUMN signed BOOLEAN NOT NULL DEFAULT FALSE, ADD COLUMN downloaded_since_sign BOOLEAN NOT NULL DEFAULT FALSE, + ADD COLUMN last_signed_at timestamp without time zone NULL, ADD COLUMN last_downloaded_at timestamp without time zone NULL, ADD COLUMN created_at timestamp without time zone NOT NULL, ADD COLUMN updated_at timestamp without time zone NOT NULL, diff --git a/pb/src/client_container.proto b/pb/src/client_container.proto index 3835e8239..bac794c88 100644 --- a/pb/src/client_container.proto +++ b/pb/src/client_container.proto @@ -593,7 +593,7 @@ message SourceDown { } message JamTrackSignComplete { - required string jam_track_right = 1; // jam track right id + required int32 jam_track_right_id = 1; // jam track right id } // route_to: session diff --git a/ruby/lib/jam_ruby/constants/notification_types.rb b/ruby/lib/jam_ruby/constants/notification_types.rb index 515f56d04..87dbe14e5 100644 --- a/ruby/lib/jam_ruby/constants/notification_types.rb +++ b/ruby/lib/jam_ruby/constants/notification_types.rb @@ -45,5 +45,7 @@ module NotificationTypes # general purpose text message TEXT_MESSAGE = "TEXT_MESSAGE" + # Jam Tracks: + JAM_TRACK_SIGN_COMPLETE = "JAM_TRACK_SIGN_COMPLETE" 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 9587b2c03..e85401065 100644 --- a/ruby/lib/jam_ruby/message_factory.rb +++ b/ruby/lib/jam_ruby/message_factory.rb @@ -712,13 +712,15 @@ module JamRuby ) end - def jam_track_sign_complete(jam_track_right_id) - signed = Jampb::JamTrackSignComplete.new() + def jam_track_sign_complete(receiver_id, jam_track_right_id) + signed = Jampb::JamTrackSignComplete.new( + :jam_track_right_id => jam_track_right_id + ) Jampb::ClientMessage.new( :type => ClientMessage::Type::JAM_TRACK_SIGN_COMPLETE, - :route_to => USER_TARGET_PREFIX + client_id, - :jam_track_sign_complete => signed + :route_to => USER_TARGET_PREFIX + receiver_id, #:route_to => CLIENT_TARGET, + :jam_track_sign_complete => signed ) end diff --git a/ruby/lib/jam_ruby/models/jam_track_right.rb b/ruby/lib/jam_ruby/models/jam_track_right.rb index 796ce89d2..1593971a8 100644 --- a/ruby/lib/jam_ruby/models/jam_track_right.rb +++ b/ruby/lib/jam_ruby/models/jam_track_right.rb @@ -38,6 +38,18 @@ module JamRuby JamTrackRight.where("downloaded_since_sign=? AND updated_at <= ?", true, 5.minutes.ago).limit(1000) end + def finish_sign(length, md5) + self.last_signed_at = Time.now + self.length = length + self.md5 = md5 + self.signed = true + if save + Notification.send_jam_track_sign_complete(self) + else + raise "Error sending notification #{self.errors}" + end + end + # creates a short-lived URL that has access to the object. # the idea is that this is used when a user who has the rights to this tries to download this JamTrack # we would verify their rights (can_download?), and generates a URL in response to the click so that they can download diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index a908cfe74..ccd4198e7 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -204,6 +204,9 @@ module JamRuby when NotificationTypes::SCHEDULED_SESSION_COMMENT return "New message about session." + when NotificationTypes::JAM_TRACK_SIGN_COMPLETE + return "Jam Track is ready for download." + # recording notifications when NotificationTypes::MUSICIAN_RECORDING_SAVED return "#{name} has made a new recording." @@ -1187,9 +1190,17 @@ module JamRuby end end - def send_jam_track_signed(jam_track_right) - msg = @@message_factory.jam_track_signed(jam_track_right) - @@mq_router.publish_to_all_clients(msg) + def send_jam_track_sign_complete(jam_track_right) + + notification = Notification.new + notification.jam_track_right_id = jam_track_right.id + notification.description = NotificationTypes::JAM_TRACK_SIGN_COMPLETE + notification.target_user_id = jam_track_right.user_id + notification.save! + + msg = @@message_factory.jam_track_sign_complete(jam_track_right.user_id, jam_track_right.id) + @@mq_router.publish_to_user(jam_track_right.user_id, msg) + #@@mq_router.publish_to_all_clients(msg) end def send_client_update(product, version, uri, size) diff --git a/ruby/lib/jam_ruby/resque/jam_tracks_builder.rb b/ruby/lib/jam_ruby/resque/jam_tracks_builder.rb index 310755fce..1dcf80367 100644 --- a/ruby/lib/jam_ruby/resque/jam_tracks_builder.rb +++ b/ruby/lib/jam_ruby/resque/jam_tracks_builder.rb @@ -11,15 +11,23 @@ module JamRuby attr_accessor :jam_track_right_id def self.perform(jam_track_right_id) - jam_track_builder = JamTracksBuilder.new() - jam_track_builder.jam_track_right_id = jam_track_right_id - jam_track_builder.run + JamWebEventMachine.run_wait_stop do + jam_track_builder = JamTracksBuilder.new() + jam_track_builder.jam_track_right_id = jam_track_right_id + jam_track_builder.run + end end def run @@log.info("jam_track_builder job starting. jam_track_right_id #{jam_track_right_id}") @jam_track_right = JamTrackRight.find(jam_track_right_id) JamRuby::JamTracksManager.save_jam_track_right_jkz(@jam_track_right) + + length = @jam_track_right.url.size() + md5 = Digest::MD5.new + + @jam_track_right.finish_sign(length, md5.to_s) + puts "Signed jamtrack to #{@jam_track_right[:url]}" end end diff --git a/web/app/assets/javascripts/notificationPanel.js b/web/app/assets/javascripts/notificationPanel.js index df6e23b48..41fa918c4 100644 --- a/web/app/assets/javascripts/notificationPanel.js +++ b/web/app/assets/javascripts/notificationPanel.js @@ -390,6 +390,12 @@ context.jamClient.OnDownloadAvailable(); // poke backend, letting it know a download is available } + else if (type === context.JK.MessageType.JAM_TRACK_SIGN_COMPLETE) { + $notification.find('#div-actions').hide(); + logger.debug("context.jamClient.OnDownloadAvailable!") + context.jamClient.OnDownloadAvailable(); // poke backend, letting it know a download is available + } + else if (type === context.JK.MessageType.BAND_INVITATION) { var $action_btn = $notification.find($btnNotificationAction); $action_btn.text('ACCEPT'); diff --git a/web/spec/controllers/api_jam_tracks_controller_spec.rb b/web/spec/controllers/api_jam_tracks_controller_spec.rb index 35da57118..e64130f3e 100644 --- a/web/spec/controllers/api_jam_tracks_controller_spec.rb +++ b/web/spec/controllers/api_jam_tracks_controller_spec.rb @@ -1,5 +1,4 @@ require 'spec_helper' - describe ApiJamTracksController do include CarrierWave::Test::Matchers @@ -81,8 +80,7 @@ describe ApiJamTracksController do right.download_count.should eq(1) notifications = Notification.where(:jam_track_right_id => right.id) - notifications.count.should == 1 - puts "notifications.first.inspect: #{notifications.first.inspect}" + notifications.count.should == 1 end end end