projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
BBS: small fixes.
[akkoma]
/
lib
/
pleroma
/
user.ex
diff --git
a/lib/pleroma/user.ex
b/lib/pleroma/user.ex
index 3831588f97e8019f31a75b09b10f12e37284b8bd..1741ce684716fec3e1dfb2a9a16a0dd3fcb2a96f 100644
(file)
--- a/
lib/pleroma/user.ex
+++ b/
lib/pleroma/user.ex
@@
-11,7
+11,6
@@
defmodule Pleroma.User do
alias Comeonin.Pbkdf2
alias Pleroma.Activity
alias Pleroma.Bookmark
alias Comeonin.Pbkdf2
alias Pleroma.Activity
alias Pleroma.Bookmark
- alias Pleroma.Formatter
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Registration
alias Pleroma.Notification
alias Pleroma.Object
alias Pleroma.Registration
@@
-55,8
+54,6
@@
defmodule Pleroma.User do
field(:search_type, :integer, virtual: true)
field(:tags, {:array, :string}, default: [])
field(:last_refreshed_at, :naive_datetime_usec)
field(:search_type, :integer, virtual: true)
field(:tags, {:array, :string}, default: [])
field(:last_refreshed_at, :naive_datetime_usec)
- # TODO: add migration to delete `bookmarks` field from DB
- field(:old_bookmarks, {:array, :string}, default: [], source: :bookmarks)
has_many(:bookmarks, Bookmark)
has_many(:notifications, Notification)
has_many(:registrations, Registration)
has_many(:bookmarks, Bookmark)
has_many(:notifications, Notification)
has_many(:registrations, Registration)
@@
-425,7
+422,7
@@
defmodule Pleroma.User do
Enum.map(
followed_identifiers,
fn followed_identifier ->
Enum.map(
followed_identifiers,
fn followed_identifier ->
- with
%User{} = followed
<- get_or_fetch(followed_identifier),
+ with
{:ok, %User{} = followed}
<- get_or_fetch(followed_identifier),
{:ok, follower} <- maybe_direct_follow(follower, followed),
{:ok, _} <- ActivityPub.follow(follower, followed) do
followed
{:ok, follower} <- maybe_direct_follow(follower, followed),
{:ok, _} <- ActivityPub.follow(follower, followed) do
followed
@@
-509,7
+506,15
@@
defmodule Pleroma.User do
def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}"
def get_cached_by_nickname(nickname) do
key = "nickname:#{nickname}"
- Cachex.fetch!(:user_cache, key, fn _ -> get_or_fetch_by_nickname(nickname) end)
+
+ Cachex.fetch!(:user_cache, key, fn ->
+ user_result = get_or_fetch_by_nickname(nickname)
+
+ case user_result do
+ {:ok, user} -> {:commit, user}
+ {:error, _error} -> {:ignore, nil}
+ end
+ end)
end
def get_cached_by_nickname_or_id(nickname_or_id) do
end
def get_cached_by_nickname_or_id(nickname_or_id) do
@@
-545,7
+550,7
@@
defmodule Pleroma.User do
def get_or_fetch_by_nickname(nickname) do
with %User{} = user <- get_by_nickname(nickname) do
def get_or_fetch_by_nickname(nickname) do
with %User{} = user <- get_by_nickname(nickname) do
- user
+ {:ok, user}
else
_e ->
with [_nick, _domain] <- String.split(nickname, "@"),
else
_e ->
with [_nick, _domain] <- String.split(nickname, "@"),
@@
-555,9
+560,9
@@
defmodule Pleroma.User do
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
- user
+ {:ok, user}
else
else
- _e ->
nil
+ _e ->
{:error, "not found " <> nickname}
end
end
end
end
end
end
@@
-904,7
+909,7
@@
defmodule Pleroma.User do
Enum.map(
blocked_identifiers,
fn blocked_identifier ->
Enum.map(
blocked_identifiers,
fn blocked_identifier ->
- with
%User{} = blocked
<- get_or_fetch(blocked_identifier),
+ with
{:ok, %User{} = blocked}
<- get_or_fetch(blocked_identifier),
{:ok, blocker} <- block(blocker, blocked),
{:ok, _} <- ActivityPub.block(blocker, blocked) do
blocked
{:ok, blocker} <- block(blocker, blocked),
{:ok, _} <- ActivityPub.block(blocker, blocked) do
blocked
@@
-1204,11
+1209,11
@@
defmodule Pleroma.User do
case ap_try do
{:ok, user} ->
case ap_try do
{:ok, user} ->
- user
+ {:ok, user}
_ ->
case OStatus.make_user(ap_id) do
_ ->
case OStatus.make_user(ap_id) do
- {:ok, user} ->
user
+ {:ok, user} ->
{:ok, user}
_ -> {:error, "Could not fetch by AP id"}
end
end
_ -> {:error, "Could not fetch by AP id"}
end
end
@@
-1218,20
+1223,20
@@
defmodule Pleroma.User do
user = get_cached_by_ap_id(ap_id)
if !is_nil(user) and !User.needs_update?(user) do
user = get_cached_by_ap_id(ap_id)
if !is_nil(user) and !User.needs_update?(user) do
- user
+ {:ok, user}
else
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
else
# Whether to fetch initial posts for the user (if it's a new user & the fetching is enabled)
should_fetch_initial = is_nil(user) and Pleroma.Config.get([:fetch_initial_posts, :enabled])
-
user
= fetch_by_ap_id(ap_id)
+
resp
= fetch_by_ap_id(ap_id)
if should_fetch_initial do
if should_fetch_initial do
- with
%User{} = user
do
+ with
{:ok, %User{} = user} = resp
do
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
end
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
end
- user
+ resp
end
end
end
end
@@
-1273,7
+1278,7
@@
defmodule Pleroma.User do
end
def get_public_key_for_ap_id(ap_id) do
end
def get_public_key_for_ap_id(ap_id) do
- with
%User{} = user
<- get_or_fetch_by_ap_id(ap_id),
+ with
{:ok, %User{} = user}
<- get_or_fetch_by_ap_id(ap_id),
{:ok, public_key} <- public_key_from_info(user.info) do
{:ok, public_key}
else
{:ok, public_key} <- public_key_from_info(user.info) do
{:ok, public_key}
else
@@
-1325,18
+1330,15
@@
defmodule Pleroma.User do
end
end
end
end
- def parse_bio(bio, user \\ %User{info: %{source_data: %{}}})
- def parse_bio(nil, _user), do: ""
- def parse_bio(bio, _user) when bio == "", do: bio
+ def parse_bio(bio) when is_binary(bio) and bio != "" do
+ bio
+ |> CommonUtils.format_input("text/plain", mentions_format: :full)
+ |> elem(0)
+ end
- def parse_bio(bio, user) do
- emoji =
- (user.info.source_data["tag"] || [])
- |> Enum.filter(fn %{"type" => t} -> t == "Emoji" end)
- |> Enum.map(fn %{"icon" => %{"url" => url}, "name" => name} ->
- {String.trim(name, ":"), url}
- end)
+ def parse_bio(_), do: ""
+ def parse_bio(bio, user) when is_binary(bio) and bio != "" do
# TODO: get profile URLs other than user.ap_id
profile_urls = [user.ap_id]
# TODO: get profile URLs other than user.ap_id
profile_urls = [user.ap_id]
@@
-1346,9
+1348,10
@@
defmodule Pleroma.User do
rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
)
|> elem(0)
rel: &RelMe.maybe_put_rel_me(&1, profile_urls)
)
|> elem(0)
- |> Formatter.emojify(emoji)
end
end
+ def parse_bio(_, _), do: ""
+
def tag(user_identifiers, tags) when is_list(user_identifiers) do
Repo.transaction(fn ->
for user_identifier <- user_identifiers, do: tag(user_identifier, tags)
def tag(user_identifiers, tags) when is_list(user_identifiers) do
Repo.transaction(fn ->
for user_identifier <- user_identifiers, do: tag(user_identifier, tags)