Class: Post

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
ApplicationHelper, Diaspora::Commentable, Diaspora::Federated::Shareable, Diaspora::Likeable, Diaspora::Shareable
Defined in:
app/models/post.rb

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::Shareable

included, #update_reshares_counter

Methods included from Diaspora::Commentable

included, #last_three_comments, #update_comments_counter

Methods included from Diaspora::Likeable

included, #update_likes_counter

Methods included from Diaspora::Federated::Shareable

included

Methods included from ApplicationHelper

#all_services_connected?, #bookmarklet, #changelog_url, #contacts_link, #jquery_include_tag, #magic_bookmarklet_link, #pod_name, #pod_version, #popover_with_close_html, #raw_bookmarklet, #timeago

Instance Attribute Details

#user_likeObject

Returns the value of attribute user_like


17
18
19
# File 'app/models/post.rb', line 17

def user_like
  @user_like
end

Class Method Details

.diaspora_initialize(params) ⇒ Object


122
123
124
125
126
127
128
129
# File 'app/models/post.rb', line 122

def self.diaspora_initialize(params)
  new_post = self.new params.to_hash.stringify_keys.slice(*self.column_names)
  new_post.author = params[:author]
  new_post.public = params[:public] if params[:public]
  new_post.pending = params[:pending] if params[:pending]
  new_post.diaspora_handle = new_post.author.diaspora_handle
  new_post
end

.excluding_blocks(user) ⇒ Object


78
79
80
81
82
83
84
85
86
87
# File 'app/models/post.rb', line 78

def self.excluding_blocks(user)
  people = user.blocks.map{|b| b.person_id}
  scope = scoped

  if people.any?
    scope = scope.where("posts.author_id NOT IN (?)", people)
  end

  scope
end

.excluding_hidden_content(user) ⇒ Object


97
98
99
# File 'app/models/post.rb', line 97

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

.excluding_hidden_shareables(user) ⇒ Object


89
90
91
92
93
94
95
# File 'app/models/post.rb', line 89

def self.excluding_hidden_shareables(user)
  scope = scoped
  if user.has_hidden_shareables_of_type?
    scope = scope.where('posts.id NOT IN (?)', user.hidden_shareables["#{self.base_class}"])
  end
  scope
end

.find_by_guid_or_id_with_user(id, user = nil) ⇒ Object


148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'app/models/post.rb', line 148

def self.find_by_guid_or_id_with_user(id, user=nil)
  key = id.to_s.length <= 8 ? :id : :guid
  post = if user
           user.find_visible_shareable_by_id(Post, id, :key => key)
         else
           Post.where(key => id).includes(:author, :comments => :author).first
         end

  # is that a private post?
  raise(Diaspora::NonPublic) unless user || post.try(:public?)

  post || raise(ActiveRecord::RecordNotFound.new("could not find a post with id #{id}"))
end

.for_a_stream(max_time, order, user = nil) ⇒ Object


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

def self.for_a_stream(max_time, order, user=nil)
  scope = self.for_visible_shareable_sql(max_time, order).
    includes_for_a_stream

  scope = scope.excluding_hidden_content(user) if user.present?

  scope
end

.newer(post) ⇒ Object


45
46
47
# File 'app/models/post.rb', line 45

def self.newer(post)
  where("posts.created_at > ?", post.created_at).reorder('posts.created_at ASC').first
end

.older(post) ⇒ Object


49
50
51
# File 'app/models/post.rb', line 49

def self.older(post)
  where("posts.created_at < ?", post.created_at).reorder('posts.created_at DESC').first
end

.visible_from_author(author, current_user = nil) ⇒ Object


53
54
55
56
57
58
59
# File 'app/models/post.rb', line 53

def self.visible_from_author(author, current_user=nil)
  if current_user.present?
    current_user.posts_from(author)
  else
    author.posts.all_public
  end
end

Instance Method Details

#activity_streams?Boolean


136
137
138
# File 'app/models/post.rb', line 136

def activity_streams?
  false
end

#addressObject

prevents error when trying to access @post.address in a post different than Reshare and StatusMessage types; check PostPresenter


72
73
# File 'app/models/post.rb', line 72

def address
end

#comment_email_subjectObject


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

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

#like_for(user) ⇒ Object


115
116
117
118
# File 'app/models/post.rb', line 115

def like_for(user)
  return unless user
  likes.where(:author_id => user.person.id).first
end

#mentioned_peopleObject


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

def mentioned_people; []; end

#mutable?Boolean


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

def mutable?
  false
end

#nsfwObject


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

def nsfw
  self.author.profile.nsfw?
end

#photosObject


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

def photos; []; end

#pollObject


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

def poll
end

#post_typeObject


61
62
63
# File 'app/models/post.rb', line 61

def post_type
  self.class.name
end

#raw_messageObject


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

def raw_message; ""; end

#reshare_for(user) ⇒ Object


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

def reshare_for(user)
  return unless user
  reshares.where(:author_id => user.person.id).first
end

#rootObject


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

def root; end