Remove _misskey_reaction matching (#500)
[akkoma] / lib / pleroma / web / plugs / plug_helper.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.Plugs.PlugHelper do
6 @moduledoc "Pleroma Plug helper"
7
8 @called_plugs_list_id :called_plugs
9 def called_plugs_list_id, do: @called_plugs_list_id
10
11 @skipped_plugs_list_id :skipped_plugs
12 def skipped_plugs_list_id, do: @skipped_plugs_list_id
13
14 @doc "Returns `true` if specified plug was called."
15 def plug_called?(conn, plug_module) do
16 contained_in_private_list?(conn, @called_plugs_list_id, plug_module)
17 end
18
19 @doc "Returns `true` if specified plug was explicitly marked as skipped."
20 def plug_skipped?(conn, plug_module) do
21 contained_in_private_list?(conn, @skipped_plugs_list_id, plug_module)
22 end
23
24 @doc "Returns `true` if specified plug was either called or explicitly marked as skipped."
25 def plug_called_or_skipped?(conn, plug_module) do
26 plug_called?(conn, plug_module) || plug_skipped?(conn, plug_module)
27 end
28
29 # Appends plug to known list (skipped, called). Intended to be used from within plug code only.
30 def append_to_private_list(conn, list_id, value) do
31 list = conn.private[list_id] || []
32 modified_list = Enum.uniq(list ++ [value])
33 Plug.Conn.put_private(conn, list_id, modified_list)
34 end
35
36 defp contained_in_private_list?(conn, private_variable, value) do
37 list = conn.private[private_variable] || []
38 value in list
39 end
40 end