Class: Post
Overview
Copyright (c) 2010-2011, Diaspora Inc. This file is
licensed under the Affero General Public License version 3 or later. See
the COPYRIGHT file.
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#add_mention_subscribers?, #create_mentions, #mentioned_people, #message
included, #receive, #subscribed_pods_uris
#comments_authors, included, #last_three_comments, #update_comments_counter
included, #update_likes_counter
#object_to_receive
#all_services_connected?, #bookmarklet_code, #changelog_url, #donations_enabled?, #jquery_include_tag, #pod_name, #pod_version, #popover_with_close_html, #qrcode_uri, #service_unconnected?, #source_url, #timeago, #uri_with_username
Instance Attribute Details
#user_like ⇒ Object
Returns the value of attribute user_like.
23
24
25
|
# File 'app/models/post.rb', line 23
def user_like
@user_like
end
|
Class Method Details
.diaspora_initialize(params) ⇒ Object
152
153
154
|
# File 'app/models/post.rb', line 152
def self.diaspora_initialize(params)
new(params.to_hash.stringify_keys.slice(*column_names, "author"))
end
|
.excluding_blocks(user) ⇒ Object
97
98
99
100
101
102
103
104
105
106
|
# File 'app/models/post.rb', line 97
def self.excluding_blocks(user)
people = user.blocks.map{|b| b.person_id}
scope = all
if people.any?
scope = scope.where("posts.author_id NOT IN (?)", people)
end
scope
end
|
.excluding_hidden_content(user) ⇒ Object
116
117
118
|
# File 'app/models/post.rb', line 116
def self.excluding_hidden_content(user)
excluding_blocks(user).excluding_hidden_shareables(user)
end
|
.excluding_hidden_shareables(user) ⇒ Object
108
109
110
111
112
113
114
|
# File 'app/models/post.rb', line 108
def self.excluding_hidden_shareables(user)
scope = all
if user.has_hidden_shareables_of_type?
scope = scope.where('posts.id NOT IN (?)', user.hidden_shareables["#{self.base_class}"])
end
scope
end
|
.for_a_stream(max_time, order, user = nil, ignore_blocks = false) ⇒ Object
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'app/models/post.rb', line 120
def self.for_a_stream(max_time, order, user=nil, ignore_blocks=false)
scope = self.for_visible_shareable_sql(max_time, order).
includes_for_a_stream
if user.present?
if ignore_blocks
scope = scope.excluding_hidden_shareables(user)
else
scope = scope.excluding_hidden_content(user)
end
end
scope
end
|
Instance Method Details
#address ⇒ Object
prevents error when trying to access @post.address in a post different than Reshare and StatusMessage types;
check PostPresenter
91
92
|
# File 'app/models/post.rb', line 91
def address
end
|
156
157
158
|
# File 'app/models/post.rb', line 156
def
I18n.t('notifier.a_post_you_shared')
end
|
#like_for(user) ⇒ Object
140
141
142
143
|
# File 'app/models/post.rb', line 140
def like_for(user)
return unless user
likes.find_by(author_id: user.person.id)
end
|
#nsfw ⇒ Object
160
161
162
|
# File 'app/models/post.rb', line 160
def nsfw
self.author.profile.nsfw?
end
|
#photos ⇒ Object
87
|
# File 'app/models/post.rb', line 87
def photos; []; end
|
#poll ⇒ Object
94
95
|
# File 'app/models/post.rb', line 94
def poll
end
|
#post_type ⇒ Object
82
83
84
|
# File 'app/models/post.rb', line 82
def post_type
self.class.name
end
|
#reshare_for(user) ⇒ Object
135
136
137
138
|
# File 'app/models/post.rb', line 135
def reshare_for(user)
return unless user
reshares.find_by(author_id: user.person.id)
end
|
#root ⇒ Object
86
|
# File 'app/models/post.rb', line 86
def root; end
|
#subscribers ⇒ Object
164
165
166
167
168
|
# File 'app/models/post.rb', line 164
def subscribers
super.tap do |subscribers|
subscribers.concat(resharers).concat(participants) if public?
end
end
|
#update_reshares_counter ⇒ Integer
148
149
150
|
# File 'app/models/post.rb', line 148
def update_reshares_counter
self.class.where(id: id).update_all(reshares_count: reshares.count)
end
|