summaryrefslogtreecommitdiff
path: root/lib/pleroma/web/mastodon_api/views/filter_view.ex
blob: 8e8798c1e312035dc57ad22b29537e4004714b70 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.FilterView do
  use Pleroma.Web, :view
  alias Pleroma.Web.CommonAPI.Utils
  alias Pleroma.Web.MastodonAPI.FilterView

  def render("index.json", %{filters: filters}) do
    render_many(filters, FilterView, "show.json")
  end

  def render("show.json", %{filter: filter}) do
    expires_at =
      if filter.expires_at do
        Utils.to_masto_date(filter.expires_at)
      else
        nil
      end

    %{
      id: to_string(filter.filter_id),
      phrase: filter.phrase,
      context: filter.context,
      expires_at: expires_at,
      irreversible: filter.hide,
      whole_word: filter.whole_word
    }
  end
end