def run(["rm", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
User.delete(user)
Mix.shell().info("User #{nickname} deleted.")
else
def run(["toggle_activated", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
{:ok, user} = User.deactivate(user, !user.info.deactivated)
Mix.shell().info(
def run(["reset_password", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname),
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname),
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
Mix.shell().info("Generated password reset token for #{user.nickname}")
def run(["unsubscribe", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
Mix.shell().info("Deactivating #{user.nickname}")
User.deactivate(user)
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
:timer.sleep(500)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
if Enum.empty?(user.following) do
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
]
)
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
user =
case Keyword.get(options, :moderator) do
nil -> user
def run(["tag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.tag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
def run(["untag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
user = user |> User.untag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
def run(["delete_activities", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_cached_by_nickname(nickname) do
User.delete_user_activities(user)
Mix.shell().info("User #{nickname} statuses deleted.")
else
def reset_password(token, data) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
- %User{} = user <- User.get_by_id(token.user_id),
+ %User{} = user <- User.get_cached_by_id(token.user_id),
{:ok, _user} <- User.reset_password(user, data),
{:ok, token} <- Repo.update(used_changeset(token)) do
{:ok, token}
# Get lists to which the account belongs.
def get_lists_account_belongs(%User{} = owner, account_id) do
- user = User.get_by_id(account_id)
+ user = User.get_cached_by_id(account_id)
query =
from(
def skip?(:follows, activity, %{info: %{notification_settings: %{"follows" => false}}} = user) do
actor = activity.data["actor"]
- followed = User.get_by_ap_id(actor)
+ followed = User.get_cached_by_ap_id(actor)
User.following?(user, followed)
end
def register(%Ecto.Changeset{} = changeset) do
with {:ok, user} <- Repo.insert(changeset),
{:ok, user} <- autofollow_users(user),
+ {:ok, user} <- set_cache(user),
{:ok, _} <- Pleroma.User.WelcomeMessage.post_welcome_message_to_user(user),
{:ok, _} <- try_send_confirmation_email(user) do
{:ok, user}
name = List.last(String.split(ap_id, "/"))
nickname = "#{name}@#{domain}"
- get_by_nickname(nickname)
+ get_cached_by_nickname(nickname)
end
- def set_cache(user) do
+ def set_cache({:ok, user}), do: set_cache(user)
+ def set_cache({:error, err}), do: {:error, err}
+
+ def set_cache(%User{} = user) do
Cachex.put(:user_cache, "ap_id:#{user.ap_id}", user)
Cachex.put(:user_cache, "nickname:#{user.nickname}", user)
Cachex.put(:user_cache, "user_info:#{user.id}", user_info(user))
with [_nick, _domain] <- String.split(nickname, "@"),
{:ok, user} <- fetch_by_nickname(nickname) do
if Pleroma.Config.get([:fetch_initial_posts, :enabled]) do
+ # TODO turn into job
{:ok, _} = Task.start(__MODULE__, :fetch_initial_posts, [user])
end
# helper to handle the block given only an actor's AP id
def block(blocker, %{ap_id: ap_id}) do
- block(blocker, User.get_by_ap_id(ap_id))
+ block(blocker, get_cached_by_ap_id(ap_id))
end
def unblock(blocker, %{ap_id: ap_id}) do
end
def subscribed_to?(user, %{ap_id: ap_id}) do
- with %User{} = target <- User.get_by_ap_id(ap_id) do
+ with %User{} = target <- get_cached_by_ap_id(ap_id) do
Enum.member?(target.info.subscribers, user.ap_id)
end
end
end
def get_or_fetch_by_ap_id(ap_id) do
- user = get_by_ap_id(ap_id)
+ user = get_cached_by_ap_id(ap_id)
if !is_nil(user) and !User.needs_update?(user) do
user
def get_or_create_instance_user do
relay_uri = "#{Pleroma.Web.Endpoint.url()}/relay"
- if user = get_by_ap_id(relay_uri) do
+ if user = get_cached_by_ap_id(relay_uri) do
user
else
changes =
defp blank?(n), do: n
def insert_or_update_user(data) do
- data =
- data
- |> Map.put(:name, blank?(data[:name]) || data[:nickname])
-
- cs = User.remote_user_creation(data)
-
- Repo.insert(cs, on_conflict: :replace_all, conflict_target: :nickname)
+ data
+ |> Map.put(:name, blank?(data[:name]) || data[:nickname])
+ |> remote_user_creation()
+ |> Repo.insert(on_conflict: :replace_all, conflict_target: :nickname)
+ |> set_cache()
end
def ap_enabled?(%User{local: true}), do: true
# this is because we have synchronous follow APIs and need to simulate them
# with an async handshake
def wait_and_refresh(_, %User{local: true} = a, %User{local: true} = b) do
- with %User{} = a <- User.get_by_id(a.id),
- %User{} = b <- User.get_by_id(b.id) do
+ with %User{} = a <- User.get_cached_by_id(a.id),
+ %User{} = b <- User.get_cached_by_id(b.id) do
{:ok, a, b}
else
_e ->
def wait_and_refresh(timeout, %User{} = a, %User{} = b) do
with :ok <- :timer.sleep(timeout),
- %User{} = a <- User.get_by_id(a.id),
- %User{} = b <- User.get_by_id(b.id) do
+ %User{} = a <- User.get_cached_by_id(a.id),
+ %User{} = b <- User.get_cached_by_id(b.id) do
{:ok, a, b}
else
_e ->
end
def tag(nickname, tags) when is_binary(nickname),
- do: tag(User.get_by_nickname(nickname), tags)
+ do: tag(get_by_nickname(nickname), tags)
def tag(%User{} = user, tags),
do: update_tags(user, Enum.uniq((user.tags || []) ++ normalize_tags(tags)))
end
def untag(nickname, tags) when is_binary(nickname),
- do: untag(User.get_by_nickname(nickname), tags)
+ do: untag(get_by_nickname(nickname), tags)
def untag(%User{} = user, tags),
do: update_tags(user, (user.tags || []) -- normalize_tags(tags))
if !Enum.member?(activity.data["cc"] || [], public) &&
!Enum.member?(
activity.data["to"],
- User.get_by_ap_id(activity.data["actor"]).follower_address
+ User.get_cached_by_ap_id(activity.data["actor"]).follower_address
),
do: Pleroma.Web.Streamer.stream("direct", activity)
end
end
def make_user_from_ap_id(ap_id) do
- if _user = User.get_by_ap_id(ap_id) do
+ if _user = User.get_cached_by_ap_id(ap_id) do
Transmogrifier.upgrade_user_from_ap_id(ap_id)
else
with {:ok, data} <- fetch_and_prepare_user_from_ap_id(ap_id) do
data
)
when object_type in ["Person", "Application", "Service", "Organization"] do
- with %User{ap_id: ^actor_id} = actor <- User.get_by_ap_id(object["id"]) do
+ with %User{ap_id: ^actor_id} = actor <- User.get_cached_by_ap_id(object["id"]) do
{:ok, new_user_data} = ActivityPub.user_data_from_user_object(object)
banner = new_user_data[:info]["banner"]
end
def upgrade_user_from_ap_id(ap_id) do
- with %User{local: false} = user <- User.get_by_ap_id(ap_id),
+ with %User{local: false} = user <- User.get_cached_by_ap_id(ap_id),
{:ok, data} <- ActivityPub.fetch_and_prepare_user_from_ap_id(ap_id),
already_ap <- User.ap_enabled?(user),
{:ok, user} <- user |> User.upgrade_changeset(data) |> User.update_and_set_cache() do
action_fallback(:errors)
def user_delete(conn, %{"nickname" => nickname}) do
- User.get_by_nickname(nickname)
+ User.get_cached_by_nickname(nickname)
|> User.delete()
conn
end
def user_follow(conn, %{"follower" => follower_nick, "followed" => followed_nick}) do
- with %User{} = follower <- User.get_by_nickname(follower_nick),
- %User{} = followed <- User.get_by_nickname(followed_nick) do
+ with %User{} = follower <- User.get_cached_by_nickname(follower_nick),
+ %User{} = followed <- User.get_cached_by_nickname(followed_nick) do
User.follow(follower, followed)
end
end
def user_unfollow(conn, %{"follower" => follower_nick, "followed" => followed_nick}) do
- with %User{} = follower <- User.get_by_nickname(follower_nick),
- %User{} = followed <- User.get_by_nickname(followed_nick) do
+ with %User{} = follower <- User.get_cached_by_nickname(follower_nick),
+ %User{} = followed <- User.get_cached_by_nickname(followed_nick) do
User.unfollow(follower, followed)
end
end
def user_show(conn, %{"nickname" => nickname}) do
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_cached_by_nickname(nickname) do
conn
|> json(AccountView.render("show.json", %{user: user}))
else
end
def user_toggle_activation(conn, %{"nickname" => nickname}) do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
{:ok, updated_user} = User.deactivate(user, !user.info.deactivated)
def right_add(conn, %{"permission_group" => permission_group, "nickname" => nickname})
when permission_group in ["moderator", "admin"] do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
info =
%{}
end
def right_get(conn, %{"nickname" => nickname}) do
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
conn
|> json(%{
|> put_status(403)
|> json(%{error: "You can't revoke your own admin status."})
else
- user = User.get_by_nickname(nickname)
+ user = User.get_cached_by_nickname(nickname)
info =
%{}
def set_activation_status(conn, %{"nickname" => nickname, "status" => status}) do
with {:ok, status} <- Ecto.Type.cast(:boolean, status),
- %User{} = user <- User.get_by_nickname(nickname),
+ %User{} = user <- User.get_cached_by_nickname(nickname),
{:ok, _} <- User.deactivate(user, !status),
do: json_response(conn, :no_content, "")
end
@doc "Get a password reset token (base64 string) for given nickname"
def get_password_reset(conn, %{"nickname" => nickname}) do
- (%User{local: true} = user) = User.get_by_nickname(nickname)
+ (%User{local: true} = user) = User.get_cached_by_nickname(nickname)
{:ok, token} = Pleroma.PasswordResetToken.create_token(user)
conn
def connect(%{"token" => token}, socket) do
with true <- Pleroma.Config.get([:chat, :enabled]),
{:ok, user_id} <- Phoenix.Token.verify(socket, "user socket", token, max_age: 84_600),
- %User{} = user <- Pleroma.User.get_by_id(user_id) do
+ %User{} = user <- Pleroma.User.get_cached_by_id(user_id) do
{:ok, assign(socket, :user_name, user.nickname)}
else
_e -> :error
def report(user, data) do
with {:account_id, %{"account_id" => account_id}} <- {:account_id, data},
- {:account, %User{} = account} <- {:account, User.get_by_id(account_id)},
+ {:account, %User{} = account} <- {:account, User.get_cached_by_id(account_id)},
{:ok, {content_html, _, _}} <- make_report_content_html(data["comment"]),
{:ok, statuses} <- get_report_statuses(account, data),
{:ok, activity} <-
end
def confirm_current_password(user, password) do
- with %User{local: true} = db_user <- User.get_by_id(user.id),
+ with %User{local: true} = db_user <- User.get_cached_by_id(user.id),
true <- Pbkdf2.checkpw(password, db_user.password_hash) do
{:ok, db_user}
else
end
def ap_enabled_actor(id) do
- user = User.get_by_ap_id(id)
+ user = User.get_cached_by_ap_id(id)
if User.ap_enabled?(user) do
{:ok, user}
end
def user_statuses(%{assigns: %{user: reading_user}} = conn, params) do
- with %User{} = user <- User.get_by_id(params["id"]) do
+ with %User{} = user <- User.get_cached_by_id(params["id"]) do
activities = ActivityPub.fetch_user_activities(user, reading_user, params)
conn
def bookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
%Object{} = object <- Object.normalize(activity),
- %User{} = user <- User.get_by_nickname(user.nickname),
+ %User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
{:ok, user} <- User.bookmark(user, object.data["id"]) do
conn
def unbookmark_status(%{assigns: %{user: user}} = conn, %{"id" => id}) do
with %Activity{} = activity <- Activity.get_by_id_with_object(id),
%Object{} = object <- Object.normalize(activity),
- %User{} = user <- User.get_by_nickname(user.nickname),
+ %User{} = user <- User.get_cached_by_nickname(user.nickname),
true <- Visibility.visible_for_user?(activity, user),
{:ok, user} <- User.unbookmark(user, object.data["id"]) do
conn
end
def followers(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
- with %User{} = user <- User.get_by_id(id),
+ with %User{} = user <- User.get_cached_by_id(id),
followers <- MastodonAPI.get_followers(user, params) do
followers =
cond do
end
def following(%{assigns: %{user: for_user}} = conn, %{"id" => id} = params) do
- with %User{} = user <- User.get_by_id(id),
+ with %User{} = user <- User.get_cached_by_id(id),
followers <- MastodonAPI.get_friends(user, params) do
followers =
cond do
end
def authorize_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
- with %User{} = follower <- User.get_by_id(id),
+ with %User{} = follower <- User.get_cached_by_id(id),
{:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
conn
|> put_view(AccountView)
end
def reject_follow_request(%{assigns: %{user: followed}} = conn, %{"id" => id}) do
- with %User{} = follower <- User.get_by_id(id),
+ with %User{} = follower <- User.get_cached_by_id(id),
{:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
conn
|> put_view(AccountView)
end
def mute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
- with %User{} = muted <- User.get_by_id(id),
+ with %User{} = muted <- User.get_cached_by_id(id),
{:ok, muter} <- User.mute(muter, muted) do
conn
|> put_view(AccountView)
end
def unmute(%{assigns: %{user: muter}} = conn, %{"id" => id}) do
- with %User{} = muted <- User.get_by_id(id),
+ with %User{} = muted <- User.get_cached_by_id(id),
{:ok, muter} <- User.unmute(muter, muted) do
conn
|> put_view(AccountView)
end
def block(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
- with %User{} = blocked <- User.get_by_id(id),
+ with %User{} = blocked <- User.get_cached_by_id(id),
{:ok, blocker} <- User.block(blocker, blocked),
{:ok, _activity} <- ActivityPub.block(blocker, blocked) do
conn
end
def unblock(%{assigns: %{user: blocker}} = conn, %{"id" => id}) do
- with %User{} = blocked <- User.get_by_id(id),
+ with %User{} = blocked <- User.get_cached_by_id(id),
{:ok, blocker} <- User.unblock(blocker, blocked),
{:ok, _activity} <- ActivityPub.unblock(blocker, blocked) do
conn
end
def bookmarks(%{assigns: %{user: user}} = conn, _) do
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
activities =
user.bookmarks
accounts
|> Enum.each(fn account_id ->
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
- %User{} = followed <- User.get_by_id(account_id) do
+ %User{} = followed <- User.get_cached_by_id(account_id) do
Pleroma.List.follow(list, followed)
end
end)
accounts
|> Enum.each(fn account_id ->
with %Pleroma.List{} = list <- Pleroma.List.get(id, user),
- %User{} = followed <- Pleroma.User.get_by_id(account_id) do
+ %User{} = followed <- Pleroma.User.get_cached_by_id(account_id) do
Pleroma.List.unfollow(list, followed)
end
end)
def relationship_noop(%{assigns: %{user: user}} = conn, %{"id" => id}) do
Logger.debug("Unimplemented, returning unmodified relationship")
- with %User{} = target <- User.get_by_id(id) do
+ with %User{} = target <- User.get_cached_by_id(id) do
conn
|> put_view(AccountView)
|> render("relationship.json", %{user: user, target: target})
defp do_render("account.json", %{user: user} = opts) do
image = User.avatar_url(user) |> MediaProxy.url()
header = User.banner_url(user) |> MediaProxy.url()
- user_info = User.user_info(user)
+ user_info = User.get_cached_user_info(user)
bot = (user.info.source_data["type"] || "Person") in ["Application", "Service"]
emojis =
# Authenticated streams.
defp allow_request(stream, {"access_token", access_token}) when stream in @streams do
with %Token{user_id: user_id} <- Repo.get_by(Token, token: access_token),
- user = %User{} <- User.get_by_id(user_id) do
+ user = %User{} <- User.get_cached_by_id(user_id) do
{:ok, user}
else
_ -> {:error, 403}
fixed_token = fix_padding(params["code"]),
%Authorization{} = auth <-
Repo.get_by(Authorization, token: fixed_token, app_id: app.id),
- %User{} = user <- User.get_by_id(auth.user_id),
+ %User{} = user <- User.get_cached_by_id(auth.user_id),
{:ok, token} <- Token.exchange_token(app, auth),
{:ok, inserted_at} <- DateTime.from_naive(token.inserted_at, "Etc/UTC") do
response = %{
def exchange_token(app, auth) do
with {:ok, auth} <- Authorization.use_token(auth),
true <- auth.app_id == app.id do
- create_token(app, User.get_by_id(auth.user_id), auth.scopes)
+ create_token(app, User.get_cached_by_id(auth.user_id), auth.scopes)
end
end
}
with false <- update,
- %User{} = user <- User.get_by_ap_id(data.ap_id) do
+ %User{} = user <- User.get_cached_by_ap_id(data.ap_id) do
{:ok, user}
else
_e -> User.insert_or_update_user(data)
_ ->
Pleroma.List.get_lists_from_activity(item)
|> Enum.filter(fn list ->
- owner = User.get_by_id(list.user_id)
+ owner = User.get_cached_by_id(list.user_id)
Visibility.visible_for_user?(item, owner)
end)
def show_password_reset(conn, %{"token" => token}) do
with %{used: false} = token <- Repo.get_by(PasswordResetToken, %{token: token}),
- %User{} = user <- User.get_by_id(token.user_id) do
+ %User{} = user <- User.get_cached_by_id(token.user_id) do
render(conn, "password_reset.html", %{
token: token,
user: user
def do_remote_follow(conn, %{
"authorization" => %{"name" => username, "password" => password, "id" => id}
}) do
- followee = User.get_by_id(id)
+ followee = User.get_cached_by_id(id)
avatar = User.avatar_url(followee)
name = followee.nickname
with %User{} = user <- User.get_cached_by_nickname(username),
true <- Pbkdf2.checkpw(password, user.password_hash),
- %User{} = _followed <- User.get_by_id(id),
+ %User{} = _followed <- User.get_cached_by_id(id),
{:ok, follower} <- User.follow(user, followee),
{:ok, _activity} <- ActivityPub.follow(follower, followee) do
conn
end
def do_remote_follow(%{assigns: %{user: user}} = conn, %{"user" => %{"id" => id}}) do
- with %User{} = followee <- User.get_by_id(id),
+ with %User{} = followee <- User.get_cached_by_id(id),
{:ok, follower} <- User.follow(user, followee),
{:ok, _activity} <- ActivityPub.follow(follower, followee) do
conn
end
%{"screen_name" => nickname} ->
- case User.get_by_nickname(nickname) do
+ case User.get_cached_by_nickname(nickname) do
nil -> {:error, "No user with such screen_name"}
target -> {:ok, target}
end
end
def confirm_email(conn, %{"user_id" => uid, "token" => token}) do
- with %User{} = user <- User.get_by_id(uid),
+ with %User{} = user <- User.get_cached_by_id(uid),
true <- user.local,
true <- user.info.confirmation_pending,
true <- user.info.confirmation_token == token,
def approve_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
- %User{} = follower <- User.get_by_id(uid),
+ %User{} = follower <- User.get_cached_by_id(uid),
{:ok, follower} <- CommonAPI.accept_follow_request(follower, followed) do
conn
|> put_view(UserView)
def deny_friend_request(conn, %{"user_id" => uid} = _params) do
with followed <- conn.assigns[:user],
- %User{} = follower <- User.get_by_id(uid),
+ %User{} = follower <- User.get_cached_by_id(uid),
{:ok, follower} <- CommonAPI.reject_follow_request(follower, followed) do
conn
|> put_view(UserView)
regex = ~r/(acct:)?(?<username>\w+)@#{host}/
with %{"username" => username} <- Regex.named_captures(regex, resource),
- %User{} = user <- User.get_by_nickname(username) do
+ %User{} = user <- User.get_cached_by_nickname(username) do
{:ok, represent_user(user, fmt)}
else
_e ->
describe "create_notification" do
test "it doesn't create a notification for user if the user blocks the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
user = insert(:user)
{:ok, user} = User.block(user, author)
test "it doesn't create a notification for user if he is the activity author" do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
assert nil == Notification.create_notification(activity, author)
end
local_user = Relay.get_actor()
assert local_user.ap_id =~ "/relay"
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
refute target_user.local
activity = Utils.fetch_latest_follow(local_user, target_user)
Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
%User{ap_id: follower_id} = local_user = Relay.get_actor()
- target_user = User.get_by_ap_id(target_instance)
+ target_user = User.get_cached_by_ap_id(target_instance)
follow_activity = Utils.fetch_latest_follow(local_user, target_user)
Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
assert_received {:mix_shell, :info, [message]}
assert message =~ "created"
- user = User.get_by_nickname(unsaved.nickname)
+ user = User.get_cached_by_nickname(unsaved.nickname)
assert user.name == unsaved.name
assert user.email == unsaved.email
assert user.bio == unsaved.bio
assert_received {:mix_shell, :info, [message]}
assert message =~ "will not be created"
- refute User.get_by_nickname(unsaved.nickname)
+ refute User.get_cached_by_nickname(unsaved.nickname)
end
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " deleted"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " deactivated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ " activated"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ "Successfully unsubscribed"
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert Enum.empty?(user.following)
assert user.info.deactivated
end
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* true/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
assert user.info.is_moderator
assert user.info.locked
assert user.info.is_admin
assert_received {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* false/
- user = User.get_by_nickname(user.nickname)
+ user = User.get_cached_by_nickname(user.nickname)
refute user.info.is_moderator
refute user.info.locked
refute user.info.is_admin
{:ok, user} = User.follow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
assert User.ap_followers(followed) in user.following
{:ok, user, _activity} = User.unfollow(user, followed)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == []
end
{:error, _} = User.unfollow(user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.following == [user.ap_id]
end
{:ok, res} = User.get_friends(user)
- followed_one = User.get_by_ap_id(followed_one.ap_id)
- followed_two = User.get_by_ap_id(followed_two.ap_id)
+ followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
+ followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
assert Enum.member?(res, followed_one)
assert Enum.member?(res, followed_two)
refute Enum.member?(res, not_followed)
test "it sets the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
test "it increases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
test "it decreases the info->note_count property" do
note = insert(:note)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
assert user.info.note_count == 0
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
refute User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
assert User.following?(blocked, blocker)
{:ok, blocker} = User.block(blocker, blocked)
- blocked = User.get_by_id(blocked.id)
+ blocked = User.get_cached_by_id(blocked.id)
assert User.blocks?(blocker, blocked)
{:ok, _} = User.delete(user)
- followed = User.get_by_id(followed.id)
- follower = User.get_by_id(follower.id)
- user = User.get_by_id(user.id)
+ followed = User.get_cached_by_id(followed.id)
+ follower = User.get_cached_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated
results = User.search("http://mastodon.example.org/users/admin", resolve: true)
result = results |> List.first()
- user = User.get_by_ap_id("http://mastodon.example.org/users/admin")
+ user = User.get_cached_by_ap_id("http://mastodon.example.org/users/admin")
assert length(results) == 1
assert user == result |> Map.put(:search_rank, nil) |> Map.put(:search_type, nil)
|> put_req_header("accept", "application/json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
|> put_req_header("accept", "application/activity+json")
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
)
|> get("/users/#{user.nickname}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert json_response(conn, 200) == UserView.render("user.json", %{user: user})
end
user = insert(:user)
Enum.each(1..15, fn _ ->
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
other_user = insert(:user)
User.follow(user, other_user)
end)
user = insert(:user)
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "1", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "1",
+ "visibility" => "public"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "unlisted"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "2",
+ "visibility" => "private"
+ })
{:ok, _} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "3", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "3",
+ "visibility" => "direct"
+ })
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 2
end
user = insert(:user, info: %{note_count: 10})
{:ok, a1} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "public"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "public"
+ })
{:ok, a2} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "unlisted"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "unlisted"
+ })
{:ok, a3} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "private"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "private"
+ })
{:ok, a4} =
- CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "direct"})
+ CommonAPI.post(User.get_cached_by_id(user.id), %{
+ "status" => "yeah",
+ "visibility" => "direct"
+ })
{:ok, _} = Object.normalize(a1) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a2) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a3) |> ActivityPub.delete()
{:ok, _} = Object.normalize(a4) |> ActivityPub.delete()
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 10
end
assert object["sensitive"] == true
- user = User.get_by_ap_id(object["actor"])
+ user = User.get_cached_by_ap_id(object["actor"])
assert user.info.note_count == 1
end
assert data["actor"] == "http://mastodon.example.org/users/admin"
assert data["type"] == "Follow"
assert data["id"] == "http://mastodon.example.org/users/admin#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming follow requests from hubzilla" do
assert data["actor"] == "https://hubzilla.example.org/channel/kaniini"
assert data["type"] == "Follow"
assert data["id"] == "https://hubzilla.example.org/channel/kaniini#follows/2"
- assert User.following?(User.get_by_ap_id(data["actor"]), user)
+ assert User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming likes" do
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- refute User.following?(User.get_by_ap_id(data["actor"]), user)
+ refute User.following?(User.get_cached_by_ap_id(data["actor"]), user)
end
test "it works for incoming blocks" do
assert data["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
assert User.blocks?(blocker, user)
end
assert data["object"] == blocked.ap_id
assert data["actor"] == blocker.ap_id
- blocker = User.get_by_ap_id(data["actor"])
- blocked = User.get_by_ap_id(data["object"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
+ blocked = User.get_cached_by_ap_id(data["object"])
assert User.blocks?(blocker, blocked)
assert data["object"]["object"] == user.ap_id
assert data["actor"] == "http://mastodon.example.org/users/admin"
- blocker = User.get_by_ap_id(data["actor"])
+ blocker = User.get_cached_by_ap_id(data["actor"])
refute User.blocks?(blocker, user)
end
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
{:ok, activity} = Transmogrifier.handle_incoming(accept_data)
assert activity.data["object"] == follow_activity.data["id"]
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == true
end
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
:error = Transmogrifier.handle_incoming(accept_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, followed) == true
end
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
refute activity.local
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
{:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data)
- follower = User.get_by_id(follower.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, followed) == false
end
{:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})
assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
{:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye")
assert user.info.note_count == 1
assert user.follower_address == "https://niu.moe/users/rye/followers"
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.note_count == 1
activity = Activity.get_by_id(activity.id)
unrelated_activity = Activity.get_by_id(unrelated_activity.id)
refute user.follower_address in unrelated_activity.recipients
- user_two = User.get_by_id(user_two.id)
+ user_two = User.get_cached_by_id(user_two.id)
assert user.follower_address in user_two.following
refute "..." in user_two.following
end
defmodule Pleroma.Web.ActivityPub.UtilsTest do
use Pleroma.DataCase
alias Pleroma.Activity
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.ActivityPub.Utils
describe "fetch the latest Follow" do
test "fetches the latest Follow activity" do
%Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity)
- follower = Repo.get_by(User, ap_id: activity.data["actor"])
- followed = Repo.get_by(User, ap_id: activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert activity == Utils.fetch_latest_follow(follower, followed)
end
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
assert User.following?(follower, user)
end
"followed" => user.nickname
})
- user = User.get_by_id(user.id)
- follower = User.get_by_id(follower.id)
+ user = User.get_cached_by_id(user.id)
+ follower = User.get_cached_by_id(follower.id)
refute User.following?(follower, user)
end
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == ["x", "foo", "bar"]
- assert User.get_by_id(user2.id).tags == ["y", "foo", "bar"]
+ assert User.get_cached_by_id(user1.id).tags == ["x", "foo", "bar"]
+ assert User.get_cached_by_id(user2.id).tags == ["y", "foo", "bar"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
user2: user2
} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user1.id).tags == []
- assert User.get_by_id(user2.id).tags == ["y"]
+ assert User.get_cached_by_id(user1.id).tags == []
+ assert User.get_cached_by_id(user2.id).tags == ["y"]
end
test "it does not modify tags of not specified users", %{conn: conn, user3: user3} do
assert json_response(conn, :no_content)
- assert User.get_by_id(user3.id).tags == ["unchanged"]
+ assert User.get_cached_by_id(user3.id).tags == ["unchanged"]
end
end
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: false})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == true
assert json_response(conn, :no_content)
end
conn
|> put("/api/pleroma/admin/activation_status/#{user.nickname}", %{status: true})
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
assert user.info.deactivated == false
assert json_response(conn, :no_content)
end
test "represent an embedded relationship" do
user =
insert(:user, %{
- info: %{note_count: 5, follower_count: 3, source_data: %{"type" => "Service"}},
+ info: %{note_count: 5, follower_count: 0, source_data: %{"type" => "Service"}},
nickname: "shp@shitposter.club",
inserted_at: ~N[2017-08-15 15:47:06.597036]
})
other_user = insert(:user)
-
{:ok, other_user} = User.follow(other_user, user)
{:ok, other_user} = User.block(other_user, user)
+ {:ok, _} = User.follow(insert(:user), user)
expected = %{
id: to_string(user.id),
display_name: user.name,
locked: false,
created_at: "2017-08-15T15:47:06.000Z",
- followers_count: 3,
+ followers_count: 1,
following_count: 0,
statuses_count: 5,
note: user.bio,
describe "deleting a status" do
test "when you created it", %{conn: conn} do
activity = insert(:note_activity)
- author = User.get_by_ap_id(activity.data["actor"])
+ author = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
test "unimplemented pinned statuses feature", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
conn =
conn
test "gets an users media", %{conn: conn} do
note = insert(:note_activity)
- user = User.get_by_ap_id(note.data["actor"])
+ user = User.get_cached_by_ap_id(note.data["actor"])
file = %Plug.Upload{
content_type: "image/jpg",
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == true
end
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
assert relationship = json_response(conn, 200)
assert to_string(other_user.id) == relationship["id"]
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
end
assert %{"id" => _id, "following" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
assert %{"id" => _id, "following" => false} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
assert %{"id" => _id, "muting" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
assert %{"id" => _id, "blocking" => true} = json_response(conn, 200)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
conn =
build_conn()
{:ok, _} = TwitterAPI.create_status(user, %{"status" => "cofe"})
# Stats should count users with missing or nil `info.deactivated` value
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
info_change = Changeset.change(user.info, %{deactivated: nil})
{:ok, _user} =
mentioned_user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"})
{:ok, [notification]} = Notification.create_notifications(activity)
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
expected = %{
id: to_string(notification.id),
status = StatusView.render("status.json", %{activity: activity})
- actor = User.get_by_ap_id(activity.actor)
+ actor = User.get_cached_by_ap_id(activity.actor)
assert status.mentions ==
Enum.map([user, actor], fn u -> AccountView.render("mention.json", %{user: u}) end)
use Pleroma.Web.ConnCase
import Pleroma.Factory
alias Pleroma.Object
- alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.OStatus.ActivityRepresenter
assert response(conn, 200)
# Set a wrong magic-key for a user so it has to refetch
- salmon_user = User.get_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+ salmon_user = User.get_cached_by_ap_id("http://gs.example.org:4040/index.php/user/1")
+
# Wrong key
info_cng =
User.Info.remote_user_creation(salmon_user.info, %{
salmon_user
|> Ecto.Changeset.change()
|> Ecto.Changeset.put_embed(:info, info_cng)
- |> Repo.update()
+ |> User.update_and_set_cache()
conn =
build_conn()
test "gets an object", %{conn: conn} do
note_activity = insert(:note_activity)
- user = User.get_by_ap_id(note_activity.data["actor"])
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
[_, uuid] = hd(Regex.scan(~r/.+\/([\w-]+)$/, note_activity.data["object"]["id"]))
url = "/objects/#{uuid}"
{:ok, [activity]} = OStatus.handle_incoming(incoming)
object = Object.normalize(activity.data["object"])
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
assert user.info.note_count == 1
assert activity.data["type"] == "Create"
assert object.data["type"] == "Note"
assert activity.data["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"])
assert User.following?(follower, followed)
end
assert activity.data["object"]["object"] == "https://pawoo.net/users/pekorino"
refute activity.local
- follower = User.get_by_ap_id(activity.data["actor"])
- followed = User.get_by_ap_id(activity.data["object"]["object"])
+ follower = User.get_cached_by_ap_id(activity.data["actor"])
+ followed = User.get_cached_by_ap_id(activity.data["object"]["object"])
refute User.following?(follower, followed)
end
{:ok, user} = OStatus.find_or_make_user(uri)
- user = Pleroma.User.get_by_id(user.id)
+ user = Pleroma.User.get_cached_by_id(user.id)
assert user.name == "Constance Variable"
assert user.nickname == "lambadalambda@social.heldscal.la"
assert user.local == false
}
{:ok, activity} = Repo.insert(%Activity{data: activity_data, recipients: activity_data["to"]})
- user = User.get_by_ap_id(activity.data["actor"])
+ user = User.get_cached_by_ap_id(activity.data["actor"])
{:ok, user} = Pleroma.Web.WebFinger.ensure_keys_present(user)
poster = fn url, _data, _headers ->
test "returns one status", %{conn: conn} do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "Hey!"})
- actor = Repo.get_by!(User, ap_id: activity.data["actor"])
+ actor = User.get_cached_by_ap_id(activity.data["actor"])
conn =
conn
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.ap_followers(followed) in current_user.following
assert json_response(conn, 200) ==
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/create.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
- followed = User.get_by_id(followed.id)
+ current_user = User.get_cached_by_id(current_user.id)
+ followed = User.get_cached_by_id(followed.id)
refute User.ap_followers(followed) in current_user.following
|> with_credentials(current_user.nickname, "test")
|> post("/api/friendships/destroy.json", %{user_id: followed.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.following == [current_user.ap_id]
assert json_response(conn, 200) ==
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/create.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert User.blocks?(current_user, blocked)
assert json_response(conn, 200) ==
|> with_credentials(current_user.nickname, "test")
|> post("/api/blocks/destroy.json", %{user_id: blocked.id})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert current_user.info.blocks == []
assert json_response(conn, 200) ==
|> with_credentials(current_user.nickname, "test")
|> post("/api/qvitter/update_avatar.json", %{img: avatar_image})
- current_user = User.get_by_id(current_user.id)
+ current_user = User.get_cached_by_id(current_user.id)
assert is_map(current_user.avatar)
assert json_response(conn, 200) ==
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
|> post(request_path)
activity = Activity.get_by_id(note_activity.id)
- activity_user = User.get_by_ap_id(note_activity.data["actor"])
+ activity_user = User.get_cached_by_ap_id(note_activity.data["actor"])
assert json_response(response, 200) ==
ActivityView.render("activity.json", %{
user = json_response(conn, 200)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert user == UserView.render("show.json", %{user: fetched_user})
end
test "it confirms the user account", %{conn: conn, user: user} do
get(conn, "/api/account/confirm_email/#{user.id}/#{user.info.confirmation_token}")
- user = User.get_by_id(user.id)
+ user = User.get_cached_by_id(user.id)
refute user.info.confirmation_pending
refute user.info.confirmation_token
})
assert json_response(conn, 200) == %{"status" => "success"}
- fetched_user = User.get_by_id(current_user.id)
+ fetched_user = User.get_cached_by_id(current_user.id)
assert Pbkdf2.checkpw("newpass", fetched_user.password_hash) == true
end
end
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
{:ok, _activity} = ActivityPub.follow(other_user, user)
- user = User.get_by_id(user.id)
- other_user = User.get_by_id(other_user.id)
+ user = User.get_cached_by_id(user.id)
+ other_user = User.get_cached_by_id(other_user.id)
assert User.following?(other_user, user) == false
describe "POST /api/media/metadata/create" do
setup do
object = insert(:note)
- user = User.get_by_ap_id(object.data["actor"])
+ user = User.get_cached_by_ap_id(object.data["actor"])
%{object: object, user: user}
end
assert activity.data["object"] == object.data["id"]
- user = User.get_by_ap_id(user.ap_id)
+ user = User.get_cached_by_ap_id(user.ap_id)
assert user.info.note_count == 1
end
assert User.ap_followers(followed) in user.following
- followed = User.get_by_ap_id(followed.ap_id)
+ followed = User.get_cached_by_ap_id(followed.ap_id)
assert followed.info.follower_count == 1
{:error, msg} = TwitterAPI.follow(user, %{"screen_name" => followed.nickname})
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("lain")
+ fetched_user = User.get_cached_by_nickname("lain")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Invalid token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on expired token" do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
check_fn = fn invite ->
data = Map.put(data, "token", invite.token)
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
assert UserView.render("show.json", %{user: user}) ==
UserView.render("show.json", %{user: fetched_user})
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("vinny")
+ refute User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
refute invite.used
}
{:ok, user} = TwitterAPI.register_user(data)
- fetched_user = User.get_by_nickname("vinny")
+ fetched_user = User.get_cached_by_nickname("vinny")
invite = Repo.get_by(UserInviteToken, token: invite.token)
assert invite.used == true
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on overdue date" do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
test "returns error on with overdue date and after max" do
{:error, msg} = TwitterAPI.register_user(data)
assert msg == "Expired token"
- refute User.get_by_nickname("GrimReaper")
+ refute User.get_cached_by_nickname("GrimReaper")
end
end
{:error, error_object} = TwitterAPI.register_user(data)
assert is_binary(error_object[:error])
- refute User.get_by_nickname("lain")
+ refute User.get_cached_by_nickname("lain")
end
test "it assigns an integer conversation_id" do
id = "https://mastodon.social/users/lambadalambda"
user = insert(:user)
{:ok, represented} = TwitterAPI.get_external_profile(user, id)
- remote = User.get_by_ap_id(id)
+ remote = User.get_cached_by_ap_id(id)
assert represented["id"] == UserView.render("show.json", %{user: remote, for: user})["id"]
}
}
- blocker = User.get_by_id(blocker.id)
+ blocker = User.get_cached_by_id(blocker.id)
assert represented == UserView.render("show.json", %{user: user, for: blocker})
end