diff options
author | Mark Felder <feld@FreeBSD.org> | 2020-08-26 16:37:57 -0500 |
---|---|---|
committer | Mark Felder <feld@FreeBSD.org> | 2020-08-26 16:37:57 -0500 |
commit | 2cfe2dc81b82f0ab30d82763f2874010966acae6 (patch) | |
tree | 5797622349e3abd454014ff3a755cb31a55f331f /lib | |
parent | eead2276e79f29c4d0e10d23eb7524a9ee5f5045 (diff) | |
parent | 6f17aea066498bf070f0decb3ac0508c6b04e3b8 (diff) | |
download | pleroma-2cfe2dc81b82f0ab30d82763f2874010966acae6.tar.gz |
Merge branch 'develop' into feld-2168-media-preview-proxy
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/notification.ex | 7 | ||||
-rw-r--r-- | lib/pleroma/web/common_api/common_api.ex | 2 | ||||
-rw-r--r-- | lib/pleroma/web/web_finger/web_finger.ex | 24 |
3 files changed, 22 insertions, 11 deletions
diff --git a/lib/pleroma/notification.ex b/lib/pleroma/notification.ex index 0b171563b..c1825f810 100644 --- a/lib/pleroma/notification.ex +++ b/lib/pleroma/notification.ex @@ -15,6 +15,7 @@ defmodule Pleroma.Notification do alias Pleroma.Repo alias Pleroma.ThreadMute alias Pleroma.User + alias Pleroma.Web.CommonAPI alias Pleroma.Web.CommonAPI.Utils alias Pleroma.Web.Push alias Pleroma.Web.Streamer @@ -441,6 +442,7 @@ defmodule Pleroma.Notification do |> Multi.insert(:notification, %Notification{ user_id: user.id, activity: activity, + seen: mark_as_read?(activity, user), type: type_from_activity(activity) }) |> Marker.multi_set_last_read_id(user, "notifications") @@ -634,6 +636,11 @@ defmodule Pleroma.Notification do def skip?(_, _, _), do: false + def mark_as_read?(activity, target_user) do + user = Activity.user_actor(activity) + User.mutes_user?(target_user, user) || CommonAPI.thread_muted?(target_user, activity) + end + def for_user_and_activity(user, activity) do from(n in __MODULE__, where: n.user_id == ^user.id, diff --git a/lib/pleroma/web/common_api/common_api.ex b/lib/pleroma/web/common_api/common_api.ex index a8141b28f..5ad2b91c2 100644 --- a/lib/pleroma/web/common_api/common_api.ex +++ b/lib/pleroma/web/common_api/common_api.ex @@ -465,7 +465,7 @@ defmodule Pleroma.Web.CommonAPI do end def thread_muted?(%User{id: user_id}, %{data: %{"context" => context}}) - when is_binary("context") do + when is_binary(context) do ThreadMute.exists?(user_id, context) end diff --git a/lib/pleroma/web/web_finger/web_finger.ex b/lib/pleroma/web/web_finger/web_finger.ex index 71ccf251a..c4051e63e 100644 --- a/lib/pleroma/web/web_finger/web_finger.ex +++ b/lib/pleroma/web/web_finger/web_finger.ex @@ -149,6 +149,18 @@ defmodule Pleroma.Web.WebFinger do end end + defp get_address_from_domain(domain, encoded_account) when is_binary(domain) do + case find_lrdd_template(domain) do + {:ok, template} -> + String.replace(template, "{uri}", encoded_account) + + _ -> + "https://#{domain}/.well-known/webfinger?resource=#{encoded_account}" + end + end + + defp get_address_from_domain(_, _), do: nil + @spec finger(String.t()) :: {:ok, map()} | {:error, any()} def finger(account) do account = String.trim_leading(account, "@") @@ -163,16 +175,8 @@ defmodule Pleroma.Web.WebFinger do encoded_account = URI.encode("acct:#{account}") - address = - case find_lrdd_template(domain) do - {:ok, template} -> - String.replace(template, "{uri}", encoded_account) - - _ -> - "https://#{domain}/.well-known/webfinger?resource=#{encoded_account}" - end - - with response <- + with address when is_binary(address) <- get_address_from_domain(domain, encoded_account), + response <- HTTP.get( address, [{"accept", "application/xrd+xml,application/jrd+json"}] |