Skip to content
Browse files

Merge branch 'master' of github.com:antirez/lamernews

  • Loading branch information...
2 parents d14dacb + 6e41b9b commit 24b47c2ebed1465f369f452af58a670f1644e4f2 @antirez committed Oct 11, 2012
Showing with 39 additions and 1 deletion.
  1. +39 −1 app.rb
View
40 app.rb
@@ -138,6 +138,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])
@@ -333,7 +358,7 @@
else
top_comment = ""
end
- H.set_title "#{H.entities news["title"]} - #{SiteName}"
+ H.set_title "#{news["title"]} - #{SiteName}"
H.page {
H.section(:id => "newslist") {
news_to_html(news)
@@ -521,6 +546,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
@@ -1693,6 +1724,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 24b47c2

Please sign in to comment.
Something went wrong with that request. Please try again.