diff options
author | multiple creatures <dev@multiple-creature.party> | 2019-08-03 13:47:20 -0500 |
---|---|---|
committer | multiple creatures <dev@multiple-creature.party> | 2019-08-03 13:47:20 -0500 |
commit | b644f1c5050c96fd95b573cac1f406e6d85446c9 (patch) | |
tree | 005c23d9688b5cc3323f6dda060e1d5f1724ba8e /app/models | |
parent | cd52f7500603ab82f18d651161e8ab7ca3565e35 (diff) |
respect 'don't @ me' requests
Diffstat (limited to 'app/models')
-rw-r--r-- | app/models/status.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/app/models/status.rb b/app/models/status.rb index 5fba7b38a..42de5d4c0 100644 --- a/app/models/status.rb +++ b/app/models/status.rb @@ -32,6 +32,7 @@ # imported :boolean # origin :string # boostable :boolean +# reject_replies :boolean # class Status < ApplicationRecord @@ -46,6 +47,7 @@ class Status < ApplicationRecord # match both with and without U+FE0F (the emoji variation selector) LOCAL_ONLY_TOKENS = /(?:#!|\u{1f441}\ufe0f?)\u200b?\z/ + REJECT_REPLIES_TOKENS = /\b(?:\:ms_dont_at_me\:|no replies|(?:don't|do not) (?:@|at|reply)(?: (?:me|us))?)\b/i # If `override_timestamps` is set at creation time, Snowflake ID creation # will be based on current time instead of `created_at` @@ -318,6 +320,7 @@ class Status < ApplicationRecord before_validation :set_visibility before_validation :set_conversation before_validation :set_local + before_validation :infer_reject_replies after_create :set_poll_id after_create :process_bangtags, if: :local? @@ -544,6 +547,13 @@ class Status < ApplicationRecord LOCAL_ONLY_TOKENS.match?(content) end + def marked_reject_replies? + return true if reject_replies + return true if spoiler_text.present? && REJECT_REPLIES_TOKENS.match?(spoiler_text) + return true if content.present? && REJECT_REPLIES_TOKENS.match?(content.lines.first) + content.present? && REJECT_REPLIES_TOKENS.match?(content.lines.last) + end + private def update_status_stat!(attrs) @@ -581,6 +591,10 @@ class Status < ApplicationRecord end end + def infer_reject_replies + self.reject_replies = marked_reject_replies? + end + def process_bangtags Bangtags.new(self).process end |