Class: StatusMessagesController
- Inherits:
-
ApplicationController
- Object
- ActionController::Base
- ApplicationController
- StatusMessagesController
- Defined in:
- app/controllers/status_messages_controller.rb
Overview
Copyright © 2010, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See the COPYRIGHT file.
Instance Method Summary (collapse)
Methods inherited from ApplicationController
#after_sign_in_path_for, #clear_gc_stats, #ensure_http_referer_is_set, #ensure_page, #grammatical_gender, #redirect_unless_admin, #set_git_header, #set_grammatical_gender, #set_header_data, #set_invites, #set_locale, #which_action_and_user
Instance Method Details
- (Object) bookmarklet
28 29 30 31 32 33 |
# File 'app/controllers/status_messages_controller.rb', line 28 def bookmarklet @aspects = current_user.aspects @selected_contacts = @aspects.map { |aspect| aspect.contacts }.flatten.uniq @aspect_ids = @aspects.map{|x| x.id} render :layout => nil end |
- (Object) create
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'app/controllers/status_messages_controller.rb', line 35 def create params[:status_message][:aspect_ids] = params[:aspect_ids] photos = Photo.where(:id => [*params[:photos]], :diaspora_handle => current_user.person.diaspora_handle) public_flag = params[:status_message][:public] public_flag.to_s.match(/(true)|(on)/) ? public_flag = true : public_flag = false params[:status_message][:public] = public_flag = current_user.build_post(:status_message, params[:status_message]) aspects = current_user.aspects_from_ids(params[:aspect_ids]) if !photos.empty? .photos << photos end if .save Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}") current_user.add_to_streams(, aspects) receiving_services = params[:services].map{|s| current_user.services.where( :type => "Services::"+s.titleize).first} if params[:services] current_user.dispatch_post(, :url => post_url(), :services => receiving_services) if !photos.empty? for photo in photos was_pending = photo.pending if was_pending current_user.add_to_streams(photo, aspects) current_user.dispatch_post(photo) end end photos.update_all(:pending => false, :public => public_flag) end if request.env['HTTP_REFERER'].include?("people") flash[:notice] = t('status_messages.create.success', :names => .mentions.includes(:person => :profile).map{ |mention| mention.person.name }.join(', ')) end respond_to do |format| format.js { render :create, :status => 201} format.html { redirect_to :back} format.mobile{ redirect_to root_url} end else if !photos.empty? photos.update_all(:status_message_guid => nil) end respond_to do |format| format.js { errors = .errors..collect { |msg| msg.gsub(/^Text/, "") } render :json =>{:errors => errors}, :status => 422 } format.html {redirect_to :back} end end end |
- (Object) destroy
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/controllers/status_messages_controller.rb', line 91 def destroy = current_user.posts.where(:id => params[:id]).first if current_user.retract() respond_to do |format| format.js {render 'destroy'} format.all {redirect_to root_url} end else Rails.logger.info "event=post_destroy status=failure user=#{current_user.diaspora_handle} reason='User does not own post'" render :nothing => true, :status => 404 end end |
- (Object) new
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'app/controllers/status_messages_controller.rb', line 12 def new @person = Person.find(params[:person_id]) @aspect = :profile @contact = current_user.contact_for(@person) @aspects_with_person = [] if @contact @aspects_with_person = @contact.aspects @aspect_ids = @aspects_with_person.map(&:id) @contacts_of_contact = @contact.contacts render :layout => nil else redirect_to :back end end |
- (Object) show
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'app/controllers/status_messages_controller.rb', line 105 def show = current_user.find_visible_post_by_id params[:id] if @object_aspect_ids = .aspects.map{|a| a.id} # mark corresponding notification as read if notification = Notification.where(:recipient_id => current_user.id, :target_id => .id).first notification.unread = false notification.save end respond_with else Rails.logger.info(:event => :link_to_nonexistent_post, :ref => request.env['HTTP_REFERER'], :user_id => current_user.id, :post_id => params[:id]) flash[:error] = I18n.t('status_messages.show.not_found') redirect_to :back end end |