Fix adding quotes and dashes in codeblocks (#557)

* Fix adding quotes and dashes in codeblocks

* Use find_by for all remove_from_feed methods (#558)

* Destroy memberships when chat channel is destroyed
This commit is contained in:
Andy Zhao 2018-07-10 13:41:54 -04:00 committed by Ben Halpern
parent 2a38f14fb7
commit 6dfcf2e856
7 changed files with 29 additions and 25 deletions

View file

@ -10,21 +10,24 @@ class MarkdownFixer
end
def add_quotes_to_title(markdown)
markdown.gsub(/title:\s?(.*?)(\r\n|\n)/m) do |target|
# $1 is the captured group (.*?)
captured_title = $1
# The query below checks if the whole title is wrapped in
# either single or double quotes.
match = captured_title.scan(/(^".*"$|^'.*'$)/)
if match.empty?
# Double quotes that aren't already escaped will get esacped.
# Then the whole title get warped in double quotes.
parsed_title = captured_title.gsub(/(?<![\\])["]/, "\\\"")
"title: \"#{parsed_title}\"\n"
else
# if the title comes pre-warped in either single or doublequotes,
# no more processing is done
target
# Only add quotes to front matter, or text between triple dashes
markdown.gsub(/-{3}.*?-{3}/m) do |front_matter|
front_matter.gsub(/title:\s?(.*?)(\r\n|\n)/m) do |target|
# $1 is the captured group (.*?)
captured_title = $1
# The query below checks if the whole title is wrapped in
# either single or double quotes.
match = captured_title.scan(/(^".*"$|^'.*'$)/)
if match.empty?
# Double quotes that aren't already escaped will get esacped.
# Then the whole title get warped in double quotes.
parsed_title = captured_title.gsub(/(?<![\\])["]/, "\\\"")
"title: \"#{parsed_title}\"\n"
else
# if the title comes pre-warped in either single or doublequotes,
# no more processing is done
target
end
end
end
end
@ -32,7 +35,9 @@ class MarkdownFixer
# This turns --- into ------- after the first two,
# because --- messes with front matter
def modify_hr_tags(markdown)
markdown.gsub(/^---/).with_index { |m, i| i > 1 ? "#{m}-----" : m }
markdown.gsub(/-{3}.*?-{3}/m) do |front_matter|
front_matter.gsub(/^---/).with_index { |m, i| i > 1 ? "#{m}-----" : m }
end
end
def convert_new_lines(markdown)

View file

@ -48,7 +48,7 @@ class BadgeAchievement < ApplicationRecord
def remove_from_feed
super
if user.class.name == "User"
User.find(user.id)&.touch(:last_notification_activity)
User.find_by(id: user.id)&.touch(:last_notification_activity)
end
end

View file

@ -3,9 +3,9 @@ class ChatChannel < ApplicationRecord
attr_accessor :current_user
has_many :messages
has_many :chat_channel_memberships
has_many :chat_channel_memberships, dependent: :destroy
has_many :users, through: :chat_channel_memberships
has_many :active_memberships, -> { where status: "active" }, class_name: 'ChatChannelMembership'
has_many :pending_memberships, -> { where status: "pending" }, class_name: 'ChatChannelMembership'
has_many :rejected_memberships, -> { where status: "rejected" }, class_name: 'ChatChannelMembership'

View file

@ -175,14 +175,14 @@ class Comment < ApplicationRecord
def remove_from_feed
super
if ancestors.empty? && user != commentable.user
[User.find(commentable.user.id)&.touch(:last_notification_activity)]
[User.find_by(id: commentable.user.id)&.touch(:last_notification_activity)]
elsif ancestors
user_ids = ancestors.map { |comment| comment.user.id }
user_ids = user_ids.uniq.reject { |uid| uid == commentable.user.id }
user_ids = user_ids.uniq.reject { |uid| uid == self.user_id }
# filters out article author and duplicate users
user_ids.map do |id|
User.find(id)&.touch(:last_notification_activity)
User.find_by(id: id)&.touch(:last_notification_activity)
end
end
end

View file

@ -64,7 +64,7 @@ class Mention < ApplicationRecord
def remove_from_feed
super
User.find(user.id)&.touch(:last_notification_activity)
User.find_by(id: user.id)&.touch(:last_notification_activity)
end
def send_email_notification

View file

@ -73,7 +73,6 @@ class Notification < ApplicationRecord
def remove_from_feed
super
User.find(user_id)&.touch(:last_notification_activity)
User.find_by(id: user_id)&.touch(:last_notification_activity)
end
end

View file

@ -56,7 +56,7 @@ class Reaction < ApplicationRecord
def remove_from_feed
super
User.find(reactable.user.id)&.touch(:last_notification_activity)
User.find_by(id: reactable.user.id)&.touch(:last_notification_activity)
end
def self.cached_any_reactions_for?(reactable, user, category)