jam-cloud/web/app/helpers/recording_helper.rb

63 lines
1.9 KiB
Ruby

module RecordingHelper
def facebook_image_for_claimed_recording(claimed_recording)
if claimed_recording.recording.band
path = !claimed_recording.recording.band.large_photo_url.blank? ? claimed_recording.recording.band.large_photo_url : "/assets/web/logo-256.png"
else
path = "/assets/web/logo-256.png"
end
request.protocol + request.host_with_port + path
end
# careful; this mirrors logic of facebook_image_for_music_session
def facebook_image_size_for_claimed_recording(claimed_recording)
if claimed_recording.recording.band
!claimed_recording.recording.band.large_photo_url.blank? ? 200 : 256
else
256
end
end
def title_for_claimed_recording(claimed_recording, sharer = nil)
if claimed_recording.recording.band
"RECORDING: #{claimed_recording.recording.band.name}"
else
unique_users = claimed_recording.recording.users.uniq
if sharer && unique_users.include?(sharer)
"RECORDING: #{sharer.name}#{additional_member_count(unique_users, sharer)}"
else
"RECORDING: #{claimed_recording.user.name}#{additional_member_count(unique_users, claimed_recording.user)}"
end
end
end
def additional_member_count(unique_users, target_user)
length = unique_users.length
if length < 2
""
else
other_length = length - 1
if other_length == 1
other_user_in_array = unique_users - [target_user]
other_user = other_user_in_array[0]
" & #{other_user.name}"
else
" & #{length - 1} OTHERS"
end
end
end
def description_for_claimed_recording(claimed_recording)
truncate(claimed_recording.name, length:250)
end
def listen_mix_url(recording)
{
mp3_url: claimed_recording_download_url(recording.candidate_claimed_recording.id, 'mp3'),
ogg_url: claimed_recording_download_url(recording.candidate_claimed_recording.id, 'ogg')
}
end
end