From b8829b417a962d8dbfe829e3bc0db23328d35efe Mon Sep 17 00:00:00 2001 From: Seth Call Date: Wed, 15 Jan 2014 18:00:45 +0000 Subject: [PATCH] * VRFS-997 - mix complete notification --- pb/src/client_container.proto | 7 ++++--- ruby/lib/jam_ruby/message_factory.rb | 15 ++++++++++++++- ruby/lib/jam_ruby/models/mix.rb | 4 +--- ruby/lib/jam_ruby/models/notification.rb | 19 +++++++++++++++++++ web/app/assets/javascripts/sidebar.js | 1 + 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/pb/src/client_container.proto b/pb/src/client_container.proto index 9e16de1f4..d39447312 100644 --- a/pb/src/client_container.proto +++ b/pb/src/client_container.proto @@ -327,9 +327,10 @@ message RecordingEnded { message RecordingMasterMixComplete { optional string recording_id = 1; - optional string msg = 2; - optional string notification_id = 3; - optional string created_at = 4; + optional string band_id = 2; + optional string msg = 3; + optional string notification_id = 4; + optional string created_at = 5; } message DownloadAvailable { diff --git a/ruby/lib/jam_ruby/message_factory.rb b/ruby/lib/jam_ruby/message_factory.rb index 24b8ddcff..333006f2c 100644 --- a/ruby/lib/jam_ruby/message_factory.rb +++ b/ruby/lib/jam_ruby/message_factory.rb @@ -473,7 +473,20 @@ module JamRuby ) end - def recording_master_mix_complete + def recording_master_mix_complete(receiver_id, recording_id, band_id, msg, notification_id, created_at) + recording_master_mix_complete = Jampb::RecordingMasterMixComplete.new( + :band_invitation_id => invitation_id, + :photo_url => photo_url, + :msg => msg, + :notification_id => notification_id, + :created_at => created_at + ) + + return Jampb::ClientMessage.new( + :type => ClientMessage::Type::RECORDING_MASTER_MIX_COMPLETE, + :route_to => USER_TARGET_PREFIX + receiver_id, + :recording_master_mix_complete => recording_master_mix_complete + ) end # create a band invitation message diff --git a/ruby/lib/jam_ruby/models/mix.rb b/ruby/lib/jam_ruby/models/mix.rb index 8f712a7fb..cf96fb8f7 100644 --- a/ruby/lib/jam_ruby/models/mix.rb +++ b/ruby/lib/jam_ruby/models/mix.rb @@ -56,9 +56,7 @@ module JamRuby self.md5 = md5 self.completed = true if save - recording.users.each do |user| - Notification.send_download_available(user.id) - end + Notification.send_recording_master_mix_complete(recording) end end diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index 127b761ac..c439d1672 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -11,6 +11,8 @@ module JamRuby belongs_to :session, :class_name => "JamRuby::MusicSession", :foreign_key => "session_id" belongs_to :recording, :class_name => "JamRuby::Recording", :foreign_key => "recording_id" + validates :target_user, :presence => true + def index(user_id) Notification.where(:target_user_id => user_id).limit(50) end @@ -658,6 +660,23 @@ module JamRuby end def send_recording_master_mix_complete(recording) + + # only people who get told about mixes are folks who claimed it... not everyone in the session + recording.claimed_recordings.each do |claimed_recording| + + notification = Notification.new + notification.band_id = recording.band.id if recording.band + notification.recording_id = recording.id + notification.target_user_id = claimed_recording.user_id + notification.description = NotificationTypes::RECORDING_MASTER_MIX_COMPLETE + notification.save + + notification_msg = format_msg(notification.description, nil, recording.band) + + msg = @@message_factory.recording_master_mix_complete(claimed_recording.user_id, recording.id, notification.band_id, notification_msg, notification.id, notification.created_at.to_s) + + @@mq_router.publish_to_user(claimed_recording.user_id, msg) + end end def send_band_invitation(band, band_invitation, sender, receiver) diff --git a/web/app/assets/javascripts/sidebar.js b/web/app/assets/javascripts/sidebar.js index 618e88d39..e302ec48e 100644 --- a/web/app/assets/javascripts/sidebar.js +++ b/web/app/assets/javascripts/sidebar.js @@ -211,6 +211,7 @@ else if (type === context.JK.MessageType.RECORDING_MASTER_MIX_COMPLETE) { $notification.find('#div-actions').hide(); + context.jamClient.OnDownloadAvailable(); // poke backend, letting it know a download is available } else if (type === context.JK.MessageType.BAND_INVITATION) {