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.

Direct Known Subclasses

Reshare, StatusMessage

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Diaspora::MentionsContainer

#add_mention_subscribers?, #create_mentions, #mentioned_people, #message

Methods included from Diaspora::Shareable

included, #receive, #subscribed_pods_uris

Methods included from Diaspora::Commentable

#comments_authors, included, #last_three_comments, #update_comments_counter

Methods included from Diaspora::Likeable

included, #update_likes_counter

Methods included from Diaspora::Federated::Base

#object_to_receive

Methods included from ApplicationHelper

#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_likeObject

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

#addressObject

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

#comment_email_subjectObject



156
157
158
# File 'app/models/post.rb', line 156

def comment_email_subject
  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

#nsfwObject



160
161
162
# File 'app/models/post.rb', line 160

def nsfw
  self.author.profile.nsfw?
end

#photosObject



87
# File 'app/models/post.rb', line 87

def photos; []; end

#pollObject



94
95
# File 'app/models/post.rb', line 94

def poll
end

#post_typeObject



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

#rootObject



86
# File 'app/models/post.rb', line 86

def root; end

#subscribersObject



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_counterInteger

Returns:

  • (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