Class: StatusMessage

Inherits:
Post
  • Object
show all
Includes:
Diaspora::Taggable, PeopleHelper
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_href, #person_image_link, #person_image_tag, #person_link, #profile_buttons_class, #search_header, #sharing_message

Methods included from Diaspora::Taggable

#build_tags, format_tags, included, #tag_strings

Methods inherited from Post

#activity_streams?, diaspora_initialize, excluding_blocks, excluding_hidden_content, excluding_hidden_shareables, find_by_guid_or_id_with_user, for_a_stream, #like_for, #mutable?, newer, older, #photos, #poll, #post_type, #reshare_for, #root, visible_from_author

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

#oembed_urlObject

Returns the value of attribute oembed_url


34
35
36
# File 'app/models/status_message.rb', line 34

def oembed_url
  @oembed_url
end

#open_graph_urlObject

Returns the value of attribute open_graph_url


35
36
37
# File 'app/models/status_message.rb', line 35

def open_graph_url
  @open_graph_url
end

Class Method Details

.guids_for_author(person) ⇒ Object


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

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

.public_tag_stream(tag_ids) ⇒ Object


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

def self.public_tag_stream(tag_ids)
  all_public.
    tag_stream(tag_ids)
end

.user_tag_stream(user, tag_ids) ⇒ Object


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

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

Instance Method Details

#addressObject


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

def address
  location.try(:address)
end

#after_dispatch(sender) ⇒ Object


113
114
115
# File 'app/models/status_message.rb', line 113

def after_dispatch(sender)
  self.update_and_dispatch_attached_photos(sender)
end

#attach_photos_by_ids(photo_ids) ⇒ Object


69
70
71
72
# File 'app/models/status_message.rb', line 69

def attach_photos_by_ids(photo_ids)
  return [] unless photo_ids.present?
  self.photos << Photo.where(:id => photo_ids, :author_id => self.author_id).all
end

#comment_email_subjectObject


130
131
132
# File 'app/models/status_message.rb', line 130

def comment_email_subject
  message.title length: 70
end

#contains_oembed_url_in_text?Boolean


150
151
152
153
# File 'app/models/status_message.rb', line 150

def contains_oembed_url_in_text?
  urls = URI.extract(self.raw_message, ['http', 'https'])
  self.oembed_url = urls.find{ |url| !TRUSTED_OEMBED_PROVIDERS.find(url).nil? }
end

#contains_open_graph_url_in_text?Boolean


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

def contains_open_graph_url_in_text?
  return nil if self.contains_oembed_url_in_text?
  self.open_graph_url = URI.extract(self.raw_message, ['http', 'https'])[0]
end

#create_mentionsObject

—- —-


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

def create_mentions
  ppl = Diaspora::Mentionable.people_from_string(self.raw_message)
  ppl.each do |person|
    self.mentions.find_or_create_by_person_id(person.id)
  end
end

#first_photo_url(*args) ⇒ Object


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

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

#mentioned_peopleObject


82
83
84
85
86
87
88
89
# File 'app/models/status_message.rb', line 82

def mentioned_people
  if self.persisted?
    create_mentions if self.mentions.empty?
    self.mentions.includes(:person => :profile).map{ |mention| mention.person }
  else
    Diaspora::Mentionable.people_from_string(self.raw_message)
  end
end

#mentioned_people_namesObject

TODO —- don't put presentation logic in the model!


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

def mentioned_people_names
  self.mentioned_people.map(&:name).join(', ')
end

#mentions?(person) ⇒ Boolean


105
106
107
# File 'app/models/status_message.rb', line 105

def mentions?(person)
  mentioned_people.include? person
end

#messageObject


78
79
80
# File 'app/models/status_message.rb', line 78

def message
  @message ||= Diaspora::MessageRenderer.new raw_message, mentioned_people: mentioned_people
end

#notify_person(person) ⇒ Object


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

def notify_person(person)
  self.mentions.where(:person_id => person.id).first.try(:notify_recipient)
end

#nsfwObject


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

def nsfw
  self.raw_message.match(/#nsfw/i) || super
end

#queue_gather_oembed_dataObject


142
143
144
# File 'app/models/status_message.rb', line 142

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

#queue_gather_open_graph_dataObject


146
147
148
# File 'app/models/status_message.rb', line 146

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

#raw_messageObject


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

def raw_message
  read_attribute(:text)
end

#raw_message=(text) ⇒ Object


65
66
67
# File 'app/models/status_message.rb', line 65

def raw_message=(text)
  write_attribute(:text, text)
end

#text_and_photos_blank?Boolean


138
139
140
# File 'app/models/status_message.rb', line 138

def text_and_photos_blank?
  self.raw_message.blank? && self.photos.blank?
end

#update_and_dispatch_attached_photos(sender) ⇒ Object


117
118
119
120
121
122
123
124
125
126
127
128
# File 'app/models/status_message.rb', line 117

def update_and_dispatch_attached_photos(sender)
  if self.photos.any?
    self.photos.update_all(:public => self.public)
    self.photos.each do |photo|
      if photo.pending
        sender.add_to_streams(photo, self.aspects)
        sender.dispatch_post(photo)
      end
    end
    self.photos.update_all(:pending => false)
  end
end