X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fuser.ex;h=da25a91c8d08f5457519c102dc47de63336f25a6;hb=092b1b145335d530d7343116eb452e37cc112a9e;hp=ff84e7b0ab63cf8956b18689cd665fbe353e8fb8;hpb=833161b5d21f85e2276cd0cee3e148ecbe6e1f05;p=akkoma diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index ff84e7b0a..da25a91c8 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -237,6 +237,7 @@ defmodule Pleroma.User do changeset |> put_change(:password_hash, hashed) |> put_change(:ap_id, ap_id) + |> unique_constraint(:ap_id) |> put_change(:following, [followers]) |> put_change(:follower_address, followers) else @@ -887,6 +888,24 @@ defmodule Pleroma.User do ) end + def mute(muter, %User{ap_id: ap_id} = muted) do + mutes = muter.info["mutes"] || [] + new_mutes = Enum.uniq([ap_id | mutes]) + new_info = Map.put(muter.info, "mutes", new_mutes) + + cs = User.info_changeset(muter, %{info: new_info}) + update_and_set_cache(cs) + end + + def unmute(user, %{ap_id: ap_id}) do + mutes = user.info["mutes"] || [] + new_mutes = List.delete(mutes, ap_id) + new_info = Map.put(user.info, "mutes", new_mutes) + + cs = User.info_changeset(user, %{info: new_info}) + update_and_set_cache(cs) + end + def block(blocker, %User{ap_id: ap_id} = blocked) do # sever any follow relationships to prevent leaks per activitypub (Pleroma issue #213) blocker = @@ -929,6 +948,8 @@ defmodule Pleroma.User do update_and_set_cache(cng) end + def mutes?(user, %{ap_id: ap_id}), do: Enum.member?(user.info["mutes"] || [], ap_id) + def blocks?(user, %{ap_id: ap_id}) do blocks = user.info.blocks domain_blocks = user.info.domain_blocks @@ -1200,7 +1221,7 @@ defmodule Pleroma.User do {:ok, updated_user} = user |> change(%{tags: new_tags}) - |> Repo.update() + |> update_and_set_cache() updated_user end