Class: Note
Constant Summary
collapse
19
20
21
22
StringLengthLimit::STRING_LIMIT
Instance Attribute Summary
Attributes included from ContentBase
#just_changed_published_status
Instance Method Summary
collapse
#canonicalize, included
#create_guid
Methods inherited from Content
#author=, #author_name, find_already_published, #rss_description, search_with, #short_url, #shorten_url, #whiteboard
#default_text_filter, #excerpt_text, #generate_html, #html, #html_map, included, #really_send_notifications, #send_notification_to_user, #text_filter
Instance Method Details
#access_by?(user) ⇒ Boolean
108
109
110
|
# File 'app/models/note.rb', line 108
def access_by?(user)
user.admin? || user_id == user.id
end
|
#categories ⇒ Object
38
39
40
|
# File 'app/models/note.rb', line 38
def categories
[]
end
|
#html_postprocess(field, html) ⇒ Object
#password_protected? ⇒ Boolean
104
105
106
|
# File 'app/models/note.rb', line 104
def password_protected?
false
end
|
#permalink_url(anchor = nil, only_path = false) ⇒ Object
112
113
114
115
116
117
118
119
|
# File 'app/models/note.rb', line 112
def permalink_url(anchor = nil, only_path = false)
blog.url_for(
controller: "/notes",
action: "show",
permalink: permalink,
anchor: anchor,
only_path: only_path)
end
|
#prefix ⇒ Object
126
127
128
|
# File 'app/models/note.rb', line 126
def prefix
blog.shortener_url.sub(%r{^https?://}, "")
end
|
#published? ⇒ Boolean
130
131
132
|
# File 'app/models/note.rb', line 130
def published?
state == "published"
end
|
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'app/models/note.rb', line 73
def
return false unless blog.
return false unless user.
= Twitter::REST::Client.new do |config|
config.consumer_key = blog.
config.consumer_secret = blog.
config.access_token = user.
config.access_token_secret = user.
end
begin
options = {}
if in_reply_to_status_id && in_reply_to_status_id != ""
options = { in_reply_to_status_id: in_reply_to_status_id }
self.in_reply_to_message = .status(in_reply_to_status_id).to_json
end
= .update(, options)
self. = .attrs[:id_str]
save
user.(.attrs[:user][:profile_image_url])
true
rescue StandardError => e
Rails.logger.error("Error while sending to twitter: #{e}")
errors.add(:message, e)
false
end
end
|
#set_permalink ⇒ Object
33
34
35
36
|
# File 'app/models/note.rb', line 33
def set_permalink
self.permalink = "#{id}-#{body.to_permalink[0..79]}" if permalink.blank?
save
end
|
#short_link ⇒ Object
121
122
123
124
|
# File 'app/models/note.rb', line 121
def short_link
path = redirect.from_path
"#{prefix} #{path}"
end
|
42
43
44
|
# File 'app/models/note.rb', line 42
def tags
[]
end
|
#truncate(message, length) ⇒ Object
50
51
52
53
54
55
56
|
# File 'app/models/note.rb', line 50
def truncate(message, length)
if message[length + 1] == " "
message[0..length]
else
message[0..(message[0..length].rindex(" ") - 1)]
end
end
|
58
59
60
61
62
63
64
65
66
|
# File 'app/models/note.rb', line 58
def
base_message = body.strip_html
if too_long?("#{base_message} (#{short_link})")
max_length = 140 - "... (#{redirect.from_url})".length - 1
"#{truncate(base_message, max_length)}... (#{redirect.from_url})"
else
"#{base_message} (#{short_link})"
end
end
|
FIXME: This breaks if the user changes or deletes their handle.
69
70
71
|
# File 'app/models/note.rb', line 69
def
File.join("https://twitter.com", user., "status", )
end
|