Class: Post

Overview

Copyright © 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

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


145
146
147
# File 'app/models/post.rb', line 145

def self.diaspora_initialize(params)
  new(params.to_hash.stringify_keys.slice(*column_names, "author"))
end

.excluding_blocks(user) ⇒ Object


90
91
92
93
94
95
96
97
98
99
# File 'app/models/post.rb', line 90

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


109
110
111
# File 'app/models/post.rb', line 109

def self.excluding_hidden_content(user)
  excluding_blocks(user).excluding_hidden_shareables(user)
end

.excluding_hidden_shareables(user) ⇒ Object


101
102
103
104
105
106
107
# File 'app/models/post.rb', line 101

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


113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'app/models/post.rb', line 113

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


84
85
# File 'app/models/post.rb', line 84

def address
end

#comment_email_subjectObject


149
150
151
# File 'app/models/post.rb', line 149

def comment_email_subject
  I18n.t('notifier.a_post_you_shared')
end

#like_for(user) ⇒ Object


133
134
135
136
# File 'app/models/post.rb', line 133

def like_for(user)
  return unless user
  likes.find_by(author_id: user.person.id)
end

#nsfwObject


153
154
155
# File 'app/models/post.rb', line 153

def nsfw
  self.author.profile.nsfw?
end

#photosObject


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

def photos; []; end

#pollObject


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

def poll
end

#post_typeObject


75
76
77
# File 'app/models/post.rb', line 75

def post_type
  self.class.name
end

#reshare_for(user) ⇒ Object


128
129
130
131
# File 'app/models/post.rb', line 128

def reshare_for(user)
  return unless user
  reshares.find_by(author_id: user.person.id)
end

#rootObject


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

def root; end

#subscribersObject


157
158
159
160
161
# File 'app/models/post.rb', line 157

def subscribers
  super.tap do |subscribers|
    subscribers.concat(resharers).concat(participants) if public?
  end
end

#update_reshares_counterInteger

Returns:

  • (Integer)

141
142
143
# File 'app/models/post.rb', line 141

def update_reshares_counter
  self.class.where(id: id).update_all(reshares_count: reshares.count)
end