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

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

Merged
merged 1 commit into from Oct 11, 2012
Merged
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
38 changes: 38 additions & 0 deletions app.rb
Expand Up @@ -137,6 +137,31 @@
} }
end 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 get '/usercomments/:username/:start' do
start = params[:start].to_i start = params[:start].to_i
user = get_user_by_username(params[:username]) user = get_user_by_username(params[:username])
Expand Down Expand Up @@ -451,6 +476,12 @@ def render_comment_subthread(comment,sep="")
"/0") { "/0") {
"user comments" "user comments"
} }
}+
H.li {
H.a(:href=>"/usernews/"+H.urlencode(user['username'])+
"/0") {
"user news"
}
} }
} }
}+if owner }+if owner
Expand Down Expand Up @@ -1515,6 +1546,13 @@ def get_saved_news(user_id,start,count)
return get_news_by_id(news_ids),numitems return get_news_by_id(news_ids),numitems
end 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 # Comments
############################################################################### ###############################################################################
Expand Down