Permalink
Browse files

Add a page that lists the news posted by a user.

  • Loading branch information...
1 parent bb45013 commit c4393ec78b216030eb72d93666427e8583b3d8f9 @nrk nrk committed Nov 1, 2011
Showing with 38 additions and 0 deletions.
  1. +38 −0 app.rb
View
38 app.rb
@@ -137,6 +137,31 @@
}
end
+get '/usernews/:username/:start' do
+ start = params[:start].to_i
+ user = get_user_by_username(params[:username])
+ halt(404,"Non existing user") if !user
+
+ page_title = "News posted by #{H.entities user['username']}"
+
+ H.set_title "#{page_title} - #{SiteName}"
+ paginate = {
+ :get => Proc.new {|start,count|
+ get_posted_news(user['id'],start,count)
+ },
+ :render => Proc.new {|item| news_to_html(item)},
+ :start => start,
+ :perpage => SavedNewsPerPage,
+ :link => "/usernews/#{H.urlencode user['username']}/$"
+ }
+ H.page {
+ H.h2 {page_title}+
+ H.section(:id => "newslist") {
+ list_items(paginate)
+ }
+ }
+end
+
get '/usercomments/:username/:start' do
start = params[:start].to_i
user = get_user_by_username(params[:username])
@@ -451,6 +476,12 @@ def render_comment_subthread(comment,sep="")
"/0") {
"user comments"
}
+ }+
+ H.li {
+ H.a(:href=>"/usernews/"+H.urlencode(user['username'])+
+ "/0") {
+ "user news"
+ }
}
}
}+if owner
@@ -1515,6 +1546,13 @@ def get_saved_news(user_id,start,count)
return get_news_by_id(news_ids),numitems
end
+# Get news posted by the specified user
+def get_posted_news(user_id,start,count)
+ numitems = $r.zcard("user.posted:#{user_id}").to_i
+ news_ids = $r.zrevrange("user.posted:#{user_id}",start,start+(count-1))
+ return get_news_by_id(news_ids),numitems
+end
+
###############################################################################
# Comments
###############################################################################

0 comments on commit c4393ec

Please sign in to comment.