Merge branch 'master' of bitbucket.org:jamkazam/jam-ruby
This commit is contained in:
commit
e4d5266245
|
|
@ -59,7 +59,6 @@ require "jam_ruby/models/user_liker"
|
|||
require "jam_ruby/models/user_like"
|
||||
require "jam_ruby/models/user_follower"
|
||||
require "jam_ruby/models/user_following"
|
||||
require "jam_ruby/models/user_favorite"
|
||||
require "jam_ruby/models/search"
|
||||
require "jam_ruby/models/recording"
|
||||
require "jam_ruby/models/recorded_track"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ module JamRuby
|
|||
belongs_to :recording, :class_name => "JamRuby::Recording", :inverse_of => :claimed_recordings
|
||||
belongs_to :user, :class_name => "JamRuby::User", :inverse_of => :claimed_recordings
|
||||
belongs_to :genre, :class_name => "JamRuby::Genre"
|
||||
has_many :recorded_tracks, :through => :recording, :class_name => "JamRuby::RecordedTrack"
|
||||
|
||||
# user must own this object
|
||||
# params is a hash, and everything is optional
|
||||
|
|
@ -25,7 +26,6 @@ module JamRuby
|
|||
end
|
||||
|
||||
# If this is the only copy, destroy the entire recording. Otherwise, just destroy this claimed_recording
|
||||
recording = self.recording
|
||||
if recording.claimed_recordings.count == 1
|
||||
recording.discard
|
||||
else
|
||||
|
|
|
|||
|
|
@ -52,6 +52,10 @@ module JamRuby
|
|||
S3Manager.url(hashed_filename)
|
||||
end
|
||||
|
||||
def is_completed
|
||||
!completed_at.nil?
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_s3_files
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ module JamRuby
|
|||
S3Manager.url(hashed_filename)
|
||||
end
|
||||
|
||||
def filename
|
||||
hashed_filename
|
||||
end
|
||||
|
||||
|
||||
# Format: "recording_#{recorded_track_id}"
|
||||
# File extension is irrelevant actually.
|
||||
def self.find_by_upload_filename(filename)
|
||||
|
|
@ -62,6 +67,7 @@ module JamRuby
|
|||
RecordedTrack.find(matches[1])
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def delete_s3_files
|
||||
|
|
|
|||
|
|
@ -10,47 +10,8 @@ module JamRuby
|
|||
belongs_to :music_session, :class_name => "JamRuby::MusicSession", :inverse_of => :recording
|
||||
has_many :mixes, :class_name => "JamRuby::Mix", :inverse_of => :recording
|
||||
has_many :recorded_tracks, :class_name => "JamRuby::RecordedTrack", :foreign_key => :recording_id
|
||||
|
||||
# favorites
|
||||
has_many :favorites, :class_name => "JamRuby::UserFavorite", :foreign_key => "recording_id"
|
||||
has_many :inverse_favorites, :through => :favorites, :source => :recording, :class_name => "JamRuby::Recording"
|
||||
|
||||
def favorite_count
|
||||
return self.favorites.size
|
||||
end
|
||||
|
||||
# FIXME: This isn't right.
|
||||
def self.user_recordings(user_id)
|
||||
query = Recording
|
||||
.joins(
|
||||
%Q{
|
||||
INNER JOIN
|
||||
recordings_users
|
||||
ON
|
||||
recordings_users.recording_id = recordings.id
|
||||
}
|
||||
)
|
||||
.joins(
|
||||
%Q{
|
||||
LEFT OUTER JOIN
|
||||
mixes
|
||||
ON
|
||||
recordings.id = mixes.recording_id
|
||||
}
|
||||
)
|
||||
.order(
|
||||
%Q{
|
||||
recordings.created_at DESC
|
||||
}
|
||||
)
|
||||
.where(
|
||||
%Q{
|
||||
recordings_users.user_id = '#{user_id}'
|
||||
}
|
||||
)
|
||||
query
|
||||
end
|
||||
|
||||
|
||||
# Start recording a session.
|
||||
def self.start(music_session_id, owner)
|
||||
|
||||
|
|
@ -188,19 +149,19 @@ module JamRuby
|
|||
end
|
||||
|
||||
# Returns the list of files this user should have synced to his computer, along with md5s and lengths
|
||||
def self.file_list(user)
|
||||
files = []
|
||||
def self.list(user)
|
||||
downloads = []
|
||||
|
||||
# That second join is important. It's saying join off of recordings, NOT user. If you take out the
|
||||
# ":recordings =>" part, you'll just get the recorded_tracks that I played. Very different!
|
||||
User.joins(:recordings).joins(:recordings => :recorded_tracks)
|
||||
.order(%Q{ recordings.created_at DESC })
|
||||
.where(%Q{ recorded_tracks.fully_uploaded = TRUE })
|
||||
.where(:id => user.id).each do |user|
|
||||
user.recordings.each do |recording|
|
||||
.where(:id => user.id).each do |theuser|
|
||||
theuser.recordings.each do |recording|
|
||||
recording.recorded_tracks.each do |recorded_track|
|
||||
recorded_track = user.claimed_recordings.first.recording.recorded_tracks.first
|
||||
files.push(
|
||||
downloads.push(
|
||||
{
|
||||
:type => "recorded_track",
|
||||
:id => recorded_track.id,
|
||||
|
|
@ -215,10 +176,10 @@ module JamRuby
|
|||
|
||||
User.joins(:recordings).joins(:recordings => :mixes)
|
||||
.order(%Q{ recordings.created_at DESC })
|
||||
.where(%Q{ mixes.completed_at IS NOT NULL }).each do |user|
|
||||
user.recordings.each do |recording|
|
||||
.where(%Q{ mixes.completed_at IS NOT NULL }).each do |theuser|
|
||||
theuser.recordings.each do |recording|
|
||||
recording.mixes.each do |mix|
|
||||
files.push(
|
||||
downloads.push(
|
||||
{
|
||||
:type => "mix",
|
||||
:id => mix.id,
|
||||
|
|
@ -231,7 +192,20 @@ module JamRuby
|
|||
end
|
||||
end
|
||||
|
||||
files
|
||||
|
||||
uploads = []
|
||||
RecordedTrack
|
||||
.joins(:recording)
|
||||
.where(:user_id => user.id)
|
||||
.where(:fully_uploaded => false)
|
||||
.where("duration IS NOT NULL").each do |recorded_track|
|
||||
uploads.push(recorded_track.filename)
|
||||
end
|
||||
|
||||
{
|
||||
"downloads" => downloads,
|
||||
"uploads" => uploads
|
||||
}
|
||||
end
|
||||
|
||||
# Check to see if all files have been uploaded. If so, kick off a mix.
|
||||
|
|
|
|||
|
|
@ -66,10 +66,6 @@ module JamRuby
|
|||
has_many :inverse_b_followings, :through => :band_followings, :class_name => "JamRuby::BandFollowing", :foreign_key => "band_id"
|
||||
has_many :inverse_band_followings, :through => :inverse_band_followings, :source => :band, :class_name => "JamRuby::Band"
|
||||
|
||||
# favorites
|
||||
has_many :favorites, :class_name => "JamRuby::UserFavorite", :foreign_key => "user_id"
|
||||
has_many :inverse_favorites, :through => :favorites, :class_name => "JamRuby::User"
|
||||
|
||||
# notifications
|
||||
has_many :notifications, :class_name => "JamRuby::Notification", :foreign_key => "target_user_id"
|
||||
has_many :inverse_notifications, :through => :notifications, :class_name => "JamRuby::User"
|
||||
|
|
@ -219,10 +215,6 @@ module JamRuby
|
|||
return self.band_followings.size
|
||||
end
|
||||
|
||||
def favorite_count
|
||||
return self.favorites.size
|
||||
end
|
||||
|
||||
def recording_count
|
||||
return self.recordings.size
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
module JamRuby
|
||||
class UserFavorite < ActiveRecord::Base
|
||||
|
||||
self.table_name = "users_favorites"
|
||||
|
||||
self.primary_key = 'id'
|
||||
|
||||
belongs_to :user, :class_name => "JamRuby::User", :foreign_key => "user_id", :inverse_of => :inverse_favorites
|
||||
belongs_to :recording, :class_name => "JamRuby::Recording", :foreign_key => "recording_id"
|
||||
end
|
||||
end
|
||||
|
|
@ -202,12 +202,16 @@ describe Recording do
|
|||
@recording.reload
|
||||
@genre = FactoryGirl.create(:genre)
|
||||
@recording.claim(@user, "Recording", @genre, true, true)
|
||||
Recording.file_list(@user).length.should == 0
|
||||
Recording.list(@user)["downloads"].length.should == 0
|
||||
Recording.list(@user)["uploads"].length.should == 1
|
||||
file = Recording.list(@user)["uploads"].first
|
||||
@recorded_track = @recording.recorded_tracks.first
|
||||
file.should == @recorded_track.filename
|
||||
@recorded_track.upload_start(25000, "md5hash")
|
||||
@recorded_track.upload_complete
|
||||
Recording.file_list(@user).length.should == 1
|
||||
file = Recording.file_list(@user).first
|
||||
Recording.list(@user)["downloads"].length.should == 1
|
||||
Recording.list(@user)["uploads"].length.should == 0
|
||||
file = Recording.list(@user)["downloads"].first
|
||||
file[:type].should == "recorded_track"
|
||||
file[:id].should == @recorded_track.id
|
||||
file[:length].should == 25000
|
||||
|
|
@ -219,8 +223,9 @@ describe Recording do
|
|||
@mix = Mix.next('server')
|
||||
@mix.should_not be_nil
|
||||
@mix.finish(50000, "md5hash")
|
||||
Recording.file_list(@user).length.should == 2
|
||||
file = Recording.file_list(@user).last
|
||||
Recording.list(@user)["downloads"].length.should == 2
|
||||
Recording.list(@user)["uploads"].length.should == 0
|
||||
file = Recording.list(@user)["downloads"].last
|
||||
file[:type].should == "mix"
|
||||
file[:id].should == @mix.id
|
||||
file[:length].should == 50000
|
||||
|
|
|
|||
Loading…
Reference in New Issue