Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Merged
merged 1 commit into from

4 participants

@nrk
nrk commented

I noticed that someone asked for this on LN so I implemented it since it was quite trivial after all.

Actually, in the user profile, I'd move the links to the user comments and user news pages directly in the labels of the posted news and posted comments counters, leaving only the link for the saved news when the user is logged in. Let me know if you are interested in this change, I can push a new commit on this pull request.

@sgoodwin

+1 for this feature.

@jellomaster
  • 1 for the feature with link from the user's profile (next to posted news)
@antirez
Owner

Thanks, merging in the next days.

@antirez antirez merged commit 1fc42af into antirez:master
@antirez
Owner

Merged, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 1, 2011
  1. @nrk
This page is out of date. Refresh to see the latest.
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
###############################################################################
Something went wrong with that request. Please try again.