@@ -79,11 +79,16 @@ defmodule Mobilizon.Service.Activity.Conversation do
|
||||
defp send_participant_notifications(_, _, _, _), do: {:ok, :skipped}
|
||||
|
||||
defp event_subject_params(%Conversation{
|
||||
event: %Event{id: conversation_event_id, title: conversation_event_title}
|
||||
event: %Event{
|
||||
id: conversation_event_id,
|
||||
title: conversation_event_title,
|
||||
uuid: conversation_event_uuid
|
||||
}
|
||||
}),
|
||||
do: %{
|
||||
conversation_event_id: conversation_event_id,
|
||||
conversation_event_title: conversation_event_title
|
||||
conversation_event_title: conversation_event_title,
|
||||
conversation_event_uuid: conversation_event_uuid
|
||||
}
|
||||
|
||||
defp event_subject_params(_), do: %{}
|
||||
|
||||
@@ -14,6 +14,8 @@ defmodule Mobilizon.Service.Formatter.HTML do
|
||||
|
||||
def filter_tags(html), do: Sanitizer.scrub(html, DefaultScrubbler)
|
||||
|
||||
defdelegate basic_html(html), to: FastSanitize
|
||||
|
||||
@spec strip_tags(String.t()) :: String.t() | no_return()
|
||||
def strip_tags(html) do
|
||||
case FastSanitize.strip_tags(html) do
|
||||
@@ -39,5 +41,17 @@ defmodule Mobilizon.Service.Formatter.HTML do
|
||||
|
||||
def strip_tags_and_insert_spaces(html), do: html
|
||||
|
||||
@spec html_to_text(String.t()) :: String.t()
|
||||
def html_to_text(html) do
|
||||
html
|
||||
|> String.replace(~r/<li>/, "\\g{1}- ", global: true)
|
||||
|> String.replace(
|
||||
~r/<\/?\s?br>|<\/\s?p>|<\/\s?li>|<\/\s?div>|<\/\s?h.>/,
|
||||
"\\g{1}\n\r",
|
||||
global: true
|
||||
)
|
||||
|> strip_tags()
|
||||
end
|
||||
|
||||
def filter_tags_for_oembed(html), do: Sanitizer.scrub(html, OEmbed)
|
||||
end
|
||||
|
||||
37
lib/service/formatter/text.ex
Normal file
37
lib/service/formatter/text.ex
Normal file
@@ -0,0 +1,37 @@
|
||||
defmodule Mobilizon.Service.Formatter.Text do
|
||||
@moduledoc """
|
||||
Helps to format text blocks
|
||||
|
||||
Inspired from https://elixirforum.com/t/is-there-are-text-wrapping-library-for-elixir/21733/4
|
||||
Using the Knuth-Plass Line Wrapping Algorithm https://www.students.cs.ubc.ca/~cs-490/2015W2/lectures/Knuth.pdf
|
||||
"""
|
||||
|
||||
def quote_paragraph(string, max_line_length) do
|
||||
paragraph(string, max_line_length, "> ")
|
||||
end
|
||||
|
||||
def paragraph(string, max_line_length, prefix \\ "") do
|
||||
string
|
||||
|> String.split("\n\n", trim: true)
|
||||
|> Enum.map(&subparagraph(&1, max_line_length, prefix))
|
||||
|> Enum.join("\n#{prefix}\n")
|
||||
end
|
||||
|
||||
defp subparagraph(string, max_line_length, prefix) do
|
||||
[word | rest] = String.split(string, ~r/\s+/, trim: true)
|
||||
|
||||
lines_assemble(rest, max_line_length - String.length(prefix), String.length(word), word, [])
|
||||
|> Enum.map(&"#{prefix}#{&1}")
|
||||
|> Enum.join("\n")
|
||||
end
|
||||
|
||||
defp lines_assemble([], _, _, line, acc), do: [line | acc] |> Enum.reverse()
|
||||
|
||||
defp lines_assemble([word | rest], max, line_length, line, acc) do
|
||||
if line_length + 1 + String.length(word) > max do
|
||||
lines_assemble(rest, max, String.length(word), word, [line | acc])
|
||||
else
|
||||
lines_assemble(rest, max, line_length + 1 + String.length(word), line <> " " <> word, acc)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -22,6 +22,13 @@ defmodule Mobilizon.Service.Workers.LegacyNotifierBuilder do
|
||||
notify_anonymous_participants(get_in(args, ["subject_params", "event_id"]), activity)
|
||||
end
|
||||
|
||||
if args["subject"] == "conversation_created" do
|
||||
notify_anonymous_participants(
|
||||
get_in(args, ["subject_params", "conversation_event_id"]),
|
||||
activity
|
||||
)
|
||||
end
|
||||
|
||||
args
|
||||
|> users_to_notify(author_id: args["author_id"], group_id: Map.get(args, "group_id"))
|
||||
|> Enum.each(¬ify_user(&1, activity))
|
||||
|
||||
Reference in New Issue
Block a user