Class: StatusMessage

Inherits:
Post show all
Includes:
Diaspora::Taggable, PeopleHelper, Reference::Source, Reference::Target
Defined in:
app/models/status_message.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.

Instance Attribute Summary collapse

Attributes inherited from Post

#user_like

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PeopleHelper

#birthday_format, #local_or_remote_person_path, #person_image_link, #person_image_tag, #person_link, #search_header

Methods included from Reference::Source

#create_references

Methods included from Diaspora::Taggable

#build_tags, format_tags, format_tags_for_mail, included, #tag_strings

Methods inherited from Post

#address, diaspora_initialize, excluding_blocks, excluding_hidden_content, excluding_hidden_shareables, for_a_stream, #like_for, #photos, #poll, #post_type, #reshare_for, #root, #subscribers, #update_reshares_counter

Methods included from Diaspora::MentionsContainer

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

Methods included from Diaspora::Shareable

included, #subscribed_pods_uris, #subscribers

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, #subscribers

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

#oembed_urlObject

Returns the value of attribute oembed_url


29
30
31
# File 'app/models/status_message.rb', line 29

def oembed_url
  @oembed_url
end

#open_graph_urlObject

Returns the value of attribute open_graph_url


30
31
32
# File 'app/models/status_message.rb', line 30

def open_graph_url
  @open_graph_url
end

Class Method Details

.guids_for_author(person) ⇒ Object


44
45
46
# File 'app/models/status_message.rb', line 44

def self.guids_for_author(person)
  Post.connection.select_values(Post.where(:author_id => person.id).select('posts.guid').to_sql)
end

.model_nameObject


40
41
42
# File 'app/models/status_message.rb', line 40

def self.model_name
  Post.model_name
end

.public_tag_stream(tag_ids) ⇒ Object


52
53
54
# File 'app/models/status_message.rb', line 52

def self.public_tag_stream(tag_ids)
  all_public.select("DISTINCT #{table_name}.*").tag_stream(tag_ids)
end

.tag_stream(tag_ids) ⇒ Object


56
57
58
# File 'app/models/status_message.rb', line 56

def self.tag_stream(tag_ids)
  joins(:taggings).where("taggings.tag_id IN (?)", tag_ids)
end

.user_tag_stream(user, tag_ids) ⇒ Object


48
49
50
# File 'app/models/status_message.rb', line 48

def self.user_tag_stream(user, tag_ids)
  owned_or_visible_by_user(user).tag_stream(tag_ids)
end

Instance Method Details

#comment_email_subjectObject


64
65
66
67
68
69
70
# File 'app/models/status_message.rb', line 64

def comment_email_subject
  if message.present?
    message.title
  elsif photos.present?
    I18n.t("posts.show.photos_by", count: photos.size, author: author_name)
  end
end

#contains_oembed_url_in_text?Boolean

Returns:

  • (Boolean)

88
89
90
91
# File 'app/models/status_message.rb', line 88

def contains_oembed_url_in_text?
  urls = self.message.urls
  self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? }
end

#contains_open_graph_url_in_text?Boolean

Returns:

  • (Boolean)

93
94
95
96
# File 'app/models/status_message.rb', line 93

def contains_open_graph_url_in_text?
  return nil if self.contains_oembed_url_in_text?
  self.open_graph_url = self.message.urls[0]
end

#filter_mentionsObject


125
126
127
128
# File 'app/models/status_message.rb', line 125

def filter_mentions
  return if people_allowed_to_be_mentioned == :all
  update(text: Diaspora::Mentionable.filter_people(text, people_allowed_to_be_mentioned))
end

#first_photo_url(*args) ⇒ Object


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

def first_photo_url(*args)
  photos.first.url(*args)
end

#nsfwObject


60
61
62
# File 'app/models/status_message.rb', line 60

def nsfw
  !!(text.try(:match, /#nsfw/i) || super) # rubocop:disable Style/DoubleNegation
end

#people_allowed_to_be_mentionedObject

Note: the next two methods can be safely removed once changes from #6818 are deployed on every pod see StatusMessageCreationService#dispatch Only includes those people, to whom we're going to send a federation entity (and doesn't define exhaustive list of people who can receive it)


116
117
118
119
120
121
122
123
# File 'app/models/status_message.rb', line 116

def people_allowed_to_be_mentioned
  @aspects_ppl ||=
    if public?
      :all
    else
      Contact.joins(:aspect_memberships).where(aspect_memberships: {aspect: aspects}).distinct.pluck(:person_id)
    end
end

#post_locationObject


98
99
100
101
102
103
104
# File 'app/models/status_message.rb', line 98

def post_location
  {
    address: location.try(:address),
    lat:     location.try(:lat),
    lng:     location.try(:lng)
  }
end

#queue_gather_oembed_dataObject


80
81
82
# File 'app/models/status_message.rb', line 80

def queue_gather_oembed_data
  Workers::GatherOEmbedData.perform_async(self.id, self.oembed_url)
end

#queue_gather_open_graph_dataObject


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

def queue_gather_open_graph_data
  Workers::GatherOpenGraphData.perform_async(self.id, self.open_graph_url)
end

#receive(recipient_user_ids) ⇒ Object


106
107
108
109
110
# File 'app/models/status_message.rb', line 106

def receive(recipient_user_ids)
  super(recipient_user_ids)

  photos.each {|photo| photo.receive(recipient_user_ids) }
end

#text_and_photos_blank?Boolean

Returns:

  • (Boolean)

76
77
78
# File 'app/models/status_message.rb', line 76

def text_and_photos_blank?
  text.blank? && photos.blank?
end