mirror of
https://github.com/diaspora/diaspora.git
synced 2026-01-09 15:18:11 -05:00
Merge branch 'next-minor' into develop
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
# frozen_string_literal: true
|
||||
|
||||
module Diaspora::Mentionable
|
||||
@@ -55,8 +54,9 @@ module Diaspora::Mentionable
|
||||
#
|
||||
# @param [String] message text
|
||||
# @param [Array] allowed_people ids of people that are allowed to stay
|
||||
# @param [Boolean] absolute_links (false) render mentions with absolute links
|
||||
# @return [String] message text with filtered mentions
|
||||
def self.filter_people(msg_text, allowed_people)
|
||||
def self.filter_people(msg_text, allowed_people, absolute_links: false)
|
||||
mentioned_ppl = people_from_string(msg_text)
|
||||
|
||||
msg_text.to_s.gsub(REGEX) {|match_str|
|
||||
@@ -66,7 +66,7 @@ module Diaspora::Mentionable
|
||||
if person && allowed_people.include?(person.id)
|
||||
match_str
|
||||
else
|
||||
"@#{MentionsInternal.profile_link(person, name, diaspora_id)}"
|
||||
"@#{MentionsInternal.profile_link(person, name, diaspora_id, absolute: absolute_links)}"
|
||||
end
|
||||
}
|
||||
end
|
||||
@@ -79,7 +79,7 @@ module Diaspora::Mentionable
|
||||
|
||||
# inline module for namespacing
|
||||
module MentionsInternal
|
||||
extend ::PeopleHelper
|
||||
extend ERB::Util
|
||||
|
||||
# output a formatted mention link as defined by the given arguments.
|
||||
# if the display name is blank, falls back to the person's name.
|
||||
@@ -91,10 +91,15 @@ module Diaspora::Mentionable
|
||||
def self.mention_link(person, display_name, diaspora_id, opts)
|
||||
return display_name || diaspora_id unless person.present?
|
||||
|
||||
display_name ||= person.name
|
||||
if opts[:plain_text]
|
||||
display_name || person.name
|
||||
display_name
|
||||
else
|
||||
person_link(person, class: PERSON_HREF_CLASS, display_name: display_name)
|
||||
# rubocop:disable Rails/OutputSafety
|
||||
remote_or_hovercard_link = Rails.application.routes.url_helpers.person_path(person).html_safe
|
||||
"<a data-hovercard=\"#{remote_or_hovercard_link}\" href=\"#{remote_or_hovercard_link}\" " \
|
||||
"class=\"#{PERSON_HREF_CLASS}\">#{html_escape_once(display_name)}</a>".html_safe
|
||||
# rubocop:enable Rails/OutputSafety
|
||||
end
|
||||
end
|
||||
|
||||
@@ -103,11 +108,14 @@ module Diaspora::Mentionable
|
||||
#
|
||||
# @param [Person] AR Person
|
||||
# @param [String] display name
|
||||
# @param [String] diaspora_id
|
||||
# @param [Boolean] absolute (false) render absolute link
|
||||
# @return [String] markdown person link
|
||||
def self.profile_link(person, display_name, diaspora_id)
|
||||
def self.profile_link(person, display_name, diaspora_id, absolute: false)
|
||||
return display_name || diaspora_id unless person.present?
|
||||
|
||||
"[#{display_name || person.name}](#{local_or_remote_person_path(person)})"
|
||||
url_helper = Rails.application.routes.url_helpers
|
||||
"[#{display_name || person.name}](#{absolute ? url_helper.person_url(person) : url_helper.person_path(person)})"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -56,8 +56,8 @@ module Diaspora
|
||||
@message = renderer.render(message).strip
|
||||
end
|
||||
|
||||
def markdownify
|
||||
renderer = Diaspora::Markdownify::HTML.new options[:markdown_render_options]
|
||||
def markdownify(renderer_class=Diaspora::Markdownify::HTML)
|
||||
renderer = renderer_class.new options[:markdown_render_options]
|
||||
markdown = Redcarpet::Markdown.new renderer, options[:markdown_options]
|
||||
|
||||
@message = markdown.render message
|
||||
@@ -76,8 +76,8 @@ module Diaspora
|
||||
@message = Diaspora::Mentionable.format message, options[:mentioned_people]
|
||||
end
|
||||
|
||||
if options[:disable_hovercards] || options[:link_all_mentions]
|
||||
@message = Diaspora::Mentionable.filter_people message, []
|
||||
if options[:disable_hovercards]
|
||||
@message = Diaspora::Mentionable.filter_people(message, [], absolute_links: true)
|
||||
else
|
||||
make_mentions_plain_text
|
||||
end
|
||||
@@ -108,7 +108,6 @@ module Diaspora
|
||||
end
|
||||
|
||||
DEFAULTS = {mentioned_people: [],
|
||||
link_all_mentions: false,
|
||||
disable_hovercards: false,
|
||||
truncate: false,
|
||||
append: nil,
|
||||
@@ -137,12 +136,8 @@ module Diaspora
|
||||
# @param [Hash] opts Global options affecting output
|
||||
# @option opts [Array<Person>] :mentioned_people ([]) List of people
|
||||
# allowed to mention
|
||||
# @option opts [Boolean] :link_all_mentions (false) Whether to link
|
||||
# all mentions. This makes plain links to profiles for people not in
|
||||
# :mentioned_people
|
||||
# @option opts [Boolean] :disable_hovercards (true) Render all mentions
|
||||
# as profile links. This implies :link_all_mentions and ignores
|
||||
# :mentioned_people
|
||||
# as absolute profile links. This ignores :mentioned_people
|
||||
# @option opts [#to_i, Boolean] :truncate (false) Truncate message to
|
||||
# the specified length
|
||||
# @option opts [String] :append (nil) Append text to the end of
|
||||
@@ -205,7 +200,7 @@ module Diaspora
|
||||
render_tags
|
||||
squish
|
||||
append_and_truncate
|
||||
}.html_safe
|
||||
}.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
# @param [Hash] opts Override global output options, see {#initialize}
|
||||
@@ -220,7 +215,20 @@ module Diaspora
|
||||
render_tags
|
||||
squish
|
||||
append_and_truncate
|
||||
}.html_safe
|
||||
}.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
def markdownified_for_mail
|
||||
process(disable_hovercards: true) {
|
||||
process_newlines
|
||||
normalize
|
||||
diaspora_links
|
||||
camo_urls if AppConfig.privacy.camo.proxy_markdown_images?
|
||||
render_mentions
|
||||
markdownify(Diaspora::Markdownify::Email)
|
||||
squish
|
||||
append_and_truncate
|
||||
}.html_safe # rubocop:disable Rails/OutputSafety
|
||||
end
|
||||
|
||||
# Get a short summary of the message
|
||||
|
||||
Reference in New Issue
Block a user