1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
# Copyright (c) 2010, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
class StatusMessagesController < ApplicationController
before_filter :authenticate_user!
respond_to :html
respond_to :mobile
respond_to :json, :only => :show
# Called when a user clicks "Mention" on a profile page
# @option [Integer] person_id The id of the person to be mentioned
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
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
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
@status_message = current_user.build_post(:status_message, params[:status_message])
aspects = current_user.aspects_from_ids(params[:aspect_ids])
if !photos.empty?
@status_message.photos << photos
end
if @status_message.save
Rails.logger.info("event=create type=status_message chars=#{params[:status_message][:text].length}")
current_user.add_to_streams(@status_message, aspects)
receiving_services = params[:services].map{|s| current_user.services.where(
:type => "Services::"+s.titleize).first} if params[:services]
current_user.dispatch_post(@status_message, :url => post_url(@status_message), :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 => @status_message.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 = @status_message.errors.full_messages.collect { |msg| msg.gsub(/^Text/, "") }
render :json =>{:errors => errors}, :status => 422
}
format.html {redirect_to :back}
end
end
end
def destroy
@status_message = current_user.posts.where(:id => params[:id]).first
if @status_message
current_user.retract(@status_message)
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
def show
@status_message = current_user.find_visible_post_by_id params[:id]
if @status_message
# mark corresponding notification as read
if notification = Notification.where(:recipient_id => current_user.id, :target_id => @status_message.id).first
notification.unread = false
notification.save
end
respond_with @status_message
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
helper_method :comments_expanded
def comments_expanded
true
end
end
|