Skip to content

Commit

Permalink
Merge branch 'master' of github.com:antirez/lamernews
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Oct 11, 2012
2 parents d14dacb + 6e41b9b commit 24b47c2
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion app.rb
Expand Up @@ -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])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
###############################################################################
Expand Down

0 comments on commit 24b47c2

Please sign in to comment.