aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/user_controller.rb
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-05-14 18:21:42 +0100
committerSeb Bacon <seb.bacon@gmail.com>2012-05-30 13:50:38 +0100
commit53ea4e4232375395e67050aec4d57a6cd4082d8d (patch)
tree86770b666462deb36eac0c5e0fb2668d0b2d2ede /app/controllers/user_controller.rb
parentfe09c8da70967ea591a3b01d7a70fc80490f3d8f (diff)
Support "following" functionality:
* Change "email me about stuff" wording to "follow" throughout * Introduce a new flag that the user can set, which controls if they get email alerts * Add a new link to a "wall" for logged in users where they can see a feed of all the things they're following
Diffstat (limited to 'app/controllers/user_controller.rb')
-rw-r--r--app/controllers/user_controller.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 76c56c442..18fae7024 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -6,6 +6,8 @@
#
# $Id: user_controller.rb,v 1.71 2009-09-17 07:51:47 francis Exp $
+require 'set'
+
class UserController < ApplicationController
layout :select_layout
@@ -89,6 +91,50 @@ class UserController < ApplicationController
end
+ # Show the user's wall
+ def wall
+ long_cache
+ @display_user = User.find(:first, :conditions => [ "url_name = ? and email_confirmed = ?", params[:url_name], true ])
+ if not @display_user
+ raise ActiveRecord::RecordNotFound.new("user not found, url_name=" + params[:url_name])
+ end
+ @is_you = !@user.nil? && @user.id == @display_user.id
+ feed_results = Set.new
+ # Use search query for this so can collapse and paginate easily
+ # XXX really should just use SQL query here rather than Xapian.
+ begin
+ requests_query = 'requested_by:' + @display_user.url_name
+ comments_query = 'commented_by:' + @display_user.url_name
+ # XXX combine these as OR query
+ @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse')
+ @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil)
+ rescue
+ @xapian_requests = nil
+ @xapian_comments = nil
+ end
+
+ feed_results += @xapian_requests.results.map {|x| x[:model]} if !@xapian_requests.nil?
+ feed_results += @xapian_comments.results.map {|x| x[:model]} if !@xapian_comments.nil?
+
+ # All tracks for the user
+ if @is_you
+ @track_things = TrackThing.find(:all, :conditions => ["tracking_user_id = ? and track_medium = ?", @display_user.id, 'email_daily'], :order => 'created_at desc')
+ end
+ for track_thing in @track_things
+ # XXX factor out of track_mailer.rb
+ xapian_object = InfoRequest.full_search([InfoRequestEvent], track_thing.track_query, 'described_at', true, nil, 100, 1)
+ feed_results += xapian_object.results.map {|x| x[:model]}
+ end
+
+ @feed_results = Array(feed_results).sort {|x,y| y.created_at <=> x.created_at}
+
+ respond_to do |format|
+ format.html { @has_json = true }
+ format.json { render :json => @display_user.json_for_api }
+ end
+
+ end
+
# Login form
def signin
work_out_post_redirect
@@ -533,6 +579,18 @@ class UserController < ApplicationController
end
end
+ # Change about me text on your profile page
+ def set_receive_email_alerts
+ if authenticated_user.nil?
+ flash[:error] = _("You need to be logged in to edit your profile.")
+ redirect_to frontpage_url
+ return
+ end
+ @user.receive_email_alerts = params[:receive_email_alerts]
+ @user.save!
+ redirect_to request.headers['HTTP_REFERER']
+ end
+
private
def is_modal_dialog