akkoma/lib/pleroma/web/thread_mute.ex

28 lines
852 B
Elixir
Raw Normal View History

2019-02-05 12:35:24 +00:00
# Pleroma: A lightweight social networking server
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ThreadMute do
use Ecto.Schema
alias Pleroma.{Activity, Repo, User}
require Ecto.Query
2019-02-05 12:35:24 +00:00
schema "thread_mutes" do
2019-02-07 21:25:07 +00:00
belongs_to(:user, User, type: Pleroma.FlakeId)
2019-02-05 12:35:24 +00:00
field(:context, :string)
end
def add_mute(user, id) do
%{data: %{"context" => context}} = Activity.get_by_id(id)
mute = %Pleroma.Web.ThreadMute{user_id: user.id, context: context}
Repo.insert(mute)
2019-02-05 12:35:24 +00:00
end
def remove_mute(user, id) do
user_id = Pleroma.FlakeId.from_string(user.id)
%{data: %{"context" => context}} = Activity.get_by_id(id)
Ecto.Query.from(m in "thread_mutes", where: m.user_id == ^user_id and m.context == ^context)
|> Repo.delete_all
2019-02-05 12:35:24 +00:00
end
end