VRFS-1960 : Jam Track Signed Notification, usage in notificationPanel, and spec.

This commit is contained in:
Steven Miers 2014-12-22 14:23:05 -06:00
parent 34cb617f5f
commit bbee617c4b
9 changed files with 54 additions and 14 deletions

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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');

View File

@ -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