Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guest comments off homepage & Users can control guest comments for their tracks #2

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/assets_controller.rb
Expand Up @@ -247,6 +247,19 @@ def stats
end
end

FEED_SQL = <<-ESQL
SELECT DISTINCT a.* FROM assets a INNER JOIN users u ON (a.user_id = u.id) INNER JOIN followings f ON (f.user_id = u.id) WHERE f.follower_id = :user_id ORDER BY a.created_at DESC LIMIT 15
ESQL

def listen_feed
# Note that there is a method User#new_tracks_from_followees. Ideally that method should be refactored
# to use this query kind rather than a double-query and IN subquery and then this method can call it.
@tracks = Asset.find_by_sql( [FEED_SQL,{:user_id => @user.id}] )
respond_to do |format|
format.rss
end
end

protected

def not_found
Expand Down
24 changes: 24 additions & 0 deletions app/views/assets/listen_feed.rss.builder
@@ -0,0 +1,24 @@
xml = ::Builder::XmlMarkup.new( :indent => 2 )

xml.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
xml.rss :version => "2.0", "xmlns:media" => "http://search.yahoo.com/mrss/" do
xml.channel do
xml.title "Listen feed for #{@user.login}"
xml.description "A podcast feed of new tracks by artists followed by #{@user.login}"
xml.link user_url( @user )
xml.generator "alonetone.com"

@tracks.each do |track|
xml.item do
xml.title "#{track.title} by #{track.user.login}"
xml.link user_track_url( track.user, track )
xml.pubDate track.created_at.rfc822
xml.description do |description|
description.cdata!( track.description )
end
xml.tag!( "enclosure", :url => track.public_mp3, :length => track.size, :type => "audio/mpeg" )
xml.tag!( "media:content", :duration => track.length )
end
end
end
end
2 changes: 2 additions & 0 deletions config/routes.rb
Expand Up @@ -33,6 +33,8 @@
# latest mp3s uploaded site-wide
map.latest '/latest/:latest', :controller => 'assets', :action => 'latest'

map.listen_feed '/users/:login/listenfeed.:format', :controller => 'assets', :action => 'listen_feed'

map.radio_home 'radio', :controller => 'assets', :action => 'radio'
map.radio 'radio/:source/:per_page/:page', :controller => 'assets', :action => 'radio', :defaults =>{:per_page => 5, :page => 1}

Expand Down