end
def make_friends(%User{} = main_user, %User{} = user) do
- {:ok, _} = User.follow(main_user, user)
- {:ok, _} = User.follow(user, main_user)
+ {:ok, _, _} = User.follow(main_user, user)
+ {:ok, _, _} = User.follow(user, main_user)
end
@spec get_users(User.t(), keyword()) :: [User.t()]
)
users
- |> Enum.each(fn {:ok, follower} -> Pleroma.User.follow(follower, user) end)
+ |> Enum.each(fn {:ok, follower, user} -> Pleroma.User.follow(follower, user) end)
Benchee.run(
%{
follow(follower, following, state)
following_relationship ->
- following_relationship
- |> cast(%{state: state}, [:state])
- |> validate_required([:state])
- |> Repo.update()
+ with {:ok, _following_relationship} <-
+ following_relationship
+ |> cast(%{state: state}, [:state])
+ |> validate_required([:state])
+ |> Repo.update() do
+ after_update(state, follower, following)
+ end
end
end
def follow(%User{} = follower, %User{} = following, state \\ :follow_accept) do
- %__MODULE__{}
- |> changeset(%{follower: follower, following: following, state: state})
- |> Repo.insert(on_conflict: :nothing)
+ with {:ok, _following_relationship} <-
+ %__MODULE__{}
+ |> changeset(%{follower: follower, following: following, state: state})
+ |> Repo.insert(on_conflict: :nothing) do
+ after_update(state, follower, following)
+ end
end
def unfollow(%User{} = follower, %User{} = following) do
case get(follower, following) do
- %__MODULE__{} = following_relationship -> Repo.delete(following_relationship)
- _ -> {:ok, nil}
+ %__MODULE__{} = following_relationship ->
+ with {:ok, _following_relationship} <- Repo.delete(following_relationship) do
+ after_update(:unfollow, follower, following)
+ end
+
+ _ ->
+ {:ok, nil}
+ end
+ end
+
+ defp after_update(state, %User{} = follower, %User{} = following) do
+ with {:ok, following} <- User.update_follower_count(following),
+ {:ok, follower} <- User.update_following_count(follower) do
+ Pleroma.Web.Streamer.stream("relationships:update", %{
+ state: state,
+ following: following,
+ follower: follower
+ })
+
+ {:ok, follower, following}
end
end
if not ap_enabled?(followed) do
follow(follower, followed)
else
- {:ok, follower}
+ {:ok, follower, followed}
end
end
true ->
FollowingRelationship.follow(follower, followed, state)
-
- {:ok, _} = update_follower_count(followed)
-
- follower
- |> update_following_count()
end
end
case get_follow_state(follower, followed) do
state when state in [:follow_pending, :follow_accept] ->
FollowingRelationship.unfollow(follower, followed)
- {:ok, followed} = update_follower_count(followed)
-
- {:ok, follower} = update_following_count(follower)
-
- {:ok, follower, followed}
nil ->
{:error, "Not subscribed!"}
identifiers,
fn identifier ->
with {:ok, %User{} = followed} <- User.get_or_fetch(identifier),
- {:ok, follower} <- User.maybe_direct_follow(follower, followed),
+ {:ok, follower, followed} <- User.maybe_direct_follow(follower, followed),
{:ok, _, _, _} <- CommonAPI.follow(follower, followed) do
followed
else
%User{} = followed <- User.get_cached_by_ap_id(actor),
%User{} = follower <- User.get_cached_by_ap_id(follower_id),
{:ok, follow_activity} <- Utils.update_follow_state_for_all(follow_activity, "accept"),
- {:ok, _relationship} <- FollowingRelationship.update(follower, followed, :follow_accept) do
+ {:ok, _follower, followed} <-
+ FollowingRelationship.update(follower, followed, :follow_accept) do
Notification.update_notification_type(followed, follow_activity)
- User.update_follower_count(followed)
- User.update_following_count(follower)
end
{:ok, object, meta}
) do
with %User{} = follower <- User.get_cached_by_ap_id(following_user),
%User{} = followed <- User.get_cached_by_ap_id(followed_user),
- {_, {:ok, _}, _, _} <-
+ {_, {:ok, _, _}, _, _} <-
{:following, User.follow(follower, followed, :follow_pending), follower, followed} do
if followed.local && !followed.is_locked do
{:ok, accept_data, _} = Builder.accept(followed, object)
) ::
{:ok, topic :: String.t()} | {:error, :bad_topic} | {:error, :unauthorized}
def get_topic_and_add_socket(stream, user, oauth_token, params \\ %{}) do
- case get_topic(stream, user, oauth_token, params) do
- {:ok, topic} -> add_socket(topic, user)
- error -> error
+ with {:ok, topic} <- get_topic(stream, user, oauth_token, params) do
+ add_socket(topic, user)
end
end
def get_topic(
stream,
%User{id: user_id} = user,
- %Token{user_id: token_user_id} = oauth_token,
+ %Token{user_id: user_id} = oauth_token,
_params
)
- when stream in @user_streams and user_id == token_user_id do
+ when stream in @user_streams do
# Note: "read" works for all user streams (not mentioning it since it's an ancestor scope)
required_scopes =
if stream == "user:notification" do
def get_topic(
"list",
%User{id: user_id} = user,
- %Token{user_id: token_user_id} = oauth_token,
+ %Token{user_id: user_id} = oauth_token,
%{"list" => id}
- )
- when user_id == token_user_id do
+ ) do
cond do
OAuthScopesPlug.filter_descendants(["read", "read:lists"], oauth_token.scopes) == [] ->
{:error, :unauthorized}
def stream(topics, items) do
if should_env_send?() do
- List.wrap(topics)
- |> Enum.each(fn topic ->
- List.wrap(items)
- |> Enum.each(fn item ->
- spawn(fn -> do_stream(topic, item) end)
- end)
- end)
+ for topic <- List.wrap(topics), item <- List.wrap(items) do
+ spawn(fn -> do_stream(topic, item) end)
+ end
end
-
- :ok
end
def filtered_by_user?(user, item, streamed_type \\ :activity)
domain_blocks = Pleroma.Web.ActivityPub.MRF.subdomains_regex(user.domain_blocks)
with parent <- Object.normalize(item) || item,
- true <-
- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)),
+ true <- Enum.all?([blocked_ap_ids, muted_ap_ids], &(item.actor not in &1)),
true <- item.data["type"] != "Announce" || item.actor not in reblog_muted_ap_ids,
true <-
!(streamed_type == :activity && item.data["type"] == "Announce" &&
end)
end
+ defp do_stream("relationships:update", item) do
+ text = StreamerView.render("relationships_update.json", item)
+
+ [item.follower, item.following]
+ |> Enum.map(fn %{id: id} -> "user:#{id}" end)
+ |> Enum.each(fn user_topic ->
+ Logger.debug("Trying to push relationships:update to #{user_topic}\n\n")
+
+ Registry.dispatch(@registry, user_topic, fn list ->
+ Enum.each(list, fn {pid, _auth} ->
+ send(pid, {:text, text})
+ end)
+ end)
+ end)
+ end
+
defp do_stream("participation", participation) do
user_topic = "direct:#{participation.user_id}"
Logger.debug("Trying to push a conversation participation to #{user_topic}\n\n")
|> Jason.encode!()
end
+ def render("relationships_update.json", item) do
+ %{
+ event: "pleroma:relationships_update",
+ payload:
+ %{
+ state: item.state,
+ follower: %{
+ id: item.follower.id,
+ follower_count: item.follower.follower_count,
+ following_count: item.follower.following_count
+ },
+ following: %{
+ id: item.following.id,
+ follower_count: item.following.follower_count,
+ following_count: item.following.following_count
+ }
+ }
+ |> Jason.encode!()
+ }
+ |> Jason.encode!()
+ end
+
def render("conversation.json", %Participation{} = participation) do
%{
event: "conversation",
describe "running update_users_following_followers_counts" do
test "following and followers count are updated" do
[user, user2] = insert_pair(:user)
- {:ok, %User{} = user} = User.follow(user, user2)
+ {:ok, %User{} = user, _user2} = User.follow(user, user2)
following = User.following(user)
moot = insert(:user, nickname: "moot")
kawen = insert(:user, nickname: "kawen", name: "fediverse expert moon")
- {:ok, user} = User.follow(user, moon)
+ {:ok, user, moon} = User.follow(user, moon)
assert [moon.id, kawen.id] == User.Search.search("moon") |> Enum.map(& &1.id)
user = insert(:user)
followed = insert(:user)
- {:ok, user} = User.follow(user, followed)
+ {:ok, user, followed} = User.follow(user, followed)
{:ok, _first} = CommonAPI.post(user, %{status: "hey"})
{:ok, _second} = CommonAPI.post(followed, %{status: "hello"})
other_user = insert(:user)
{:ok, other_user} = User.block_domain(other_user, blocked_domain)
- {:ok, other_user} = User.follow(other_user, user)
+ {:ok, other_user, user} = User.follow(other_user, user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{other_user.nickname}!"})
blocked = insert(:user, ap_id: "http://some-domain.com")
{:ok, user} = User.block_domain(user, "some-domain.com")
- {:ok, _} = User.follow(user, blocked)
+ {:ok, _, _} = User.follow(user, blocked)
{:ok, _activity} = CommonAPI.post(blocked, %{status: "hey @#{user.nickname}"})
assert {:ok, result} = ObanHelpers.perform(job)
assert is_list(result)
- assert result == [user2, user3]
+ assert result == [refresh_record(user2), refresh_record(user3)]
assert User.following?(user1, user2)
assert User.following?(user1, user3)
end
follower = insert(:user, %{name: "Doe"})
friend = insert(:user, %{name: "Doe"})
- {:ok, follower} = User.follow(follower, u1)
- {:ok, u1} = User.follow(u1, friend)
+ {:ok, follower, u1} = User.follow(follower, u1)
+ {:ok, u1, friend} = User.follow(u1, friend)
assert [friend.id, follower.id, u2.id] --
Enum.map(User.search("doe", resolve: false, for_user: u1), & &1.id) == []
following_jimi = insert(:user, %{name: "Lizz Wright"})
follower_lizz = insert(:user, %{name: "Jimi"})
- {:ok, lizz} = User.follow(lizz, following_lizz)
- {:ok, _jimi} = User.follow(jimi, following_jimi)
- {:ok, _follower_lizz} = User.follow(follower_lizz, lizz)
+ {:ok, lizz, following_lizz} = User.follow(lizz, following_lizz)
+ {:ok, _jimi, _following_jimi} = User.follow(jimi, following_jimi)
+ {:ok, _follower_lizz, _lizz} = User.follow(follower_lizz, lizz)
assert Enum.map(User.search("jimi", following: true, for_user: lizz), & &1.id) == [
following_lizz.id
{:ok, _user_relationship} = User.block(user, blocked)
{:ok, _user_relationship} = User.block(reverse_blocked, user)
- {:ok, user} = User.follow(user, followed_zero)
+ {:ok, user, followed_zero} = User.follow(user, followed_zero)
{:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
user = insert(:user)
followed = insert(:user)
- {:ok, user} = User.follow(user, followed)
+ {:ok, user, followed} = User.follow(user, followed)
user = User.get_cached_by_id(user.id)
followed = User.get_cached_by_ap_id(followed.ap_id)
follower = insert(:user, is_locked: true)
followed = insert(:user, is_locked: true)
- {:ok, follower} = User.maybe_direct_follow(follower, followed)
+ {:ok, follower, followed} = User.maybe_direct_follow(follower, followed)
refute User.following?(follower, followed)
end
following_address: "http://localhost:4001/users/fuser2/following"
})
- {:ok, user} = User.follow(user, followed, :follow_accept)
+ {:ok, user, followed} = User.follow(user, followed, :follow_accept)
{:ok, user, _activity} = User.unfollow(user, followed)
followed = insert(:user)
user = insert(:user)
- {:ok, user} = User.follow(user, followed, :follow_accept)
+ {:ok, user, followed} = User.follow(user, followed, :follow_accept)
assert User.following(user) == [user.follower_address, followed.follower_address]
follower_two = insert(:user)
not_follower = insert(:user)
- {:ok, follower_one} = User.follow(follower_one, user)
- {:ok, follower_two} = User.follow(follower_two, user)
+ {:ok, follower_one, user} = User.follow(follower_one, user)
+ {:ok, follower_two, user} = User.follow(follower_two, user)
res = User.get_followers(user)
followed_two = insert(:user)
not_followed = insert(:user)
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
+ {:ok, user, followed_one} = User.follow(user, followed_one)
+ {:ok, user, followed_two} = User.follow(user, followed_two)
res = User.get_friends(user)
blocker = insert(:user)
blocked = insert(:user)
- {:ok, blocker} = User.follow(blocker, blocked)
- {:ok, blocked} = User.follow(blocked, blocker)
+ {:ok, blocker, blocked} = User.follow(blocker, blocked)
+ {:ok, blocked, blocker} = User.follow(blocked, blocker)
assert User.following?(blocker, blocked)
assert User.following?(blocked, blocker)
blocker = insert(:user)
blocked = insert(:user)
- {:ok, blocker} = User.follow(blocker, blocked)
+ {:ok, blocker, blocked} = User.follow(blocker, blocked)
assert User.following?(blocker, blocked)
refute User.following?(blocked, blocker)
blocker = insert(:user)
blocked = insert(:user)
- {:ok, blocked} = User.follow(blocked, blocker)
+ {:ok, blocked, blocker} = User.follow(blocked, blocker)
refute User.following?(blocker, blocked)
assert User.following?(blocked, blocker)
good_eggo = insert(:user, %{ap_id: "https://meanies.social/user/cuteposter"})
{:ok, user} = User.block_domain(user, "meanies.social")
- {:ok, user} = User.follow(user, good_eggo)
+ {:ok, user, good_eggo} = User.follow(user, good_eggo)
refute User.blocks?(user, good_eggo)
end
assert Enum.map([actor, addressed], & &1.ap_id) --
Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
- {:ok, user} = User.follow(user, actor)
- {:ok, _user_two} = User.follow(user_two, actor)
+ {:ok, user, actor} = User.follow(user, actor)
+ {:ok, _user_two, _actor} = User.follow(user_two, actor)
recipients = User.get_recipients_from_activity(activity)
assert length(recipients) == 3
assert user in recipients
assert Enum.map([actor, addressed], & &1.ap_id) --
Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
- {:ok, _actor} = User.follow(actor, user)
- {:ok, _actor} = User.follow(actor, user_two)
+ {:ok, _actor, _user} = User.follow(actor, user)
+ {:ok, _actor, _user_two} = User.follow(actor, user_two)
recipients = User.get_recipients_from_activity(activity)
assert length(recipients) == 2
assert addressed in recipients
user = insert(:user)
user2 = insert(:user)
- {:ok, user} = User.follow(user, user2)
+ {:ok, user, user2} = User.follow(user, user2)
{:ok, _user} = User.deactivate(user)
user2 = User.get_cached_by_id(user2.id)
user = insert(:user)
user2 = insert(:user)
- {:ok, user2} = User.follow(user2, user)
+ {:ok, user2, user} = User.follow(user2, user)
assert user2.following_count == 1
assert User.following_count(user2) == 1
user = insert(:user)
user2 = insert(:user)
- {:ok, user2} = User.follow(user2, user)
+ {:ok, user2, user} = User.follow(user2, user)
{:ok, activity} = CommonAPI.post(user, %{status: "hey @#{user2.nickname}"})
test "it deactivates a user, all follow relationships and all activities", %{user: user} do
follower = insert(:user)
- {:ok, follower} = User.follow(follower, user)
+ {:ok, follower, user} = User.follow(follower, user)
locked_user = insert(:user, name: "locked", is_locked: true)
- {:ok, _} = User.follow(user, locked_user, :follow_pending)
+ {:ok, _, _} = User.follow(user, locked_user, :follow_pending)
object = insert(:note, user: user)
activity = insert(:note_activity, user: user, note: object)
follower2 = insert(:user)
follower3 = insert(:user)
- {:ok, follower} = User.follow(follower, user)
- {:ok, _follower2} = User.follow(follower2, user)
- {:ok, _follower3} = User.follow(follower3, user)
+ {:ok, follower, user} = User.follow(follower, user)
+ {:ok, _follower2, _user} = User.follow(follower2, user)
+ {:ok, _follower3, _user} = User.follow(follower3, user)
{:ok, _user_relationship} = User.block(user, follower)
user = refresh_record(user)
assert other_user.following_count == 0
assert other_user.follower_count == 0
- {:ok, user} = Pleroma.User.follow(user, other_user)
- other_user = Pleroma.User.get_by_id(other_user.id)
+ {:ok, user, other_user} = Pleroma.User.follow(user, other_user)
assert user.following_count == 1
assert other_user.follower_count == 1
assert other_user.follower_count == 0
Pleroma.Config.put([:instance, :external_user_synchronization], true)
- {:ok, _user} = User.follow(user, other_user)
- other_user = User.get_by_id(other_user.id)
+ {:ok, _user, other_user} = User.follow(user, other_user)
assert other_user.follower_count == 437
end
assert other_user.follower_count == 0
Pleroma.Config.put([:instance, :external_user_synchronization], true)
- {:ok, other_user} = User.follow(other_user, user)
+ {:ok, other_user, _user} = User.follow(other_user, user)
assert other_user.following_count == 152
end
recipient = insert(:user)
actor = insert(:user, %{ap_id: "http://mastodon.example.org/users/actor"})
- {:ok, recipient} = User.follow(recipient, actor)
+ {:ok, recipient, actor} = User.follow(recipient, actor)
object =
data["object"]
domain_user = insert(:user, %{ap_id: "https://#{domain}/@pundit"})
blocker = insert(:user)
- {:ok, blocker} = User.follow(blocker, domain_user)
+ {:ok, blocker, domain_user} = User.follow(blocker, domain_user)
{:ok, blocker} = User.block_domain(blocker, domain)
assert User.following?(blocker, domain_user)
user = insert(:user)
booster = insert(:user)
- {:ok, user} = User.follow(user, booster)
+ {:ok, user, booster} = User.follow(user, booster)
{:ok, announce} = CommonAPI.repeat(activity_three.id, booster)
user2 = insert(:user)
user3 = insert(:user)
- {:ok, user1} = User.follow(user1, user3)
+ {:ok, user1, user3} = User.follow(user1, user3)
assert User.following?(user1, user3)
- {:ok, user2} = User.follow(user2, user3)
+ {:ok, user2, user3} = User.follow(user2, user3)
assert User.following?(user2, user3)
- {:ok, user3} = User.follow(user3, user2)
+ {:ok, user3, user2} = User.follow(user3, user2)
assert User.following?(user3, user2)
{:ok, public_activity} = CommonAPI.post(user3, %{status: "hi 1"})
defp public_messages(_) do
[u1, u2, u3, u4] = insert_list(4, :user)
- {:ok, u1} = User.follow(u1, u2)
- {:ok, u2} = User.follow(u2, u1)
- {:ok, u1} = User.follow(u1, u4)
- {:ok, u4} = User.follow(u4, u1)
+ {:ok, u1, u2} = User.follow(u1, u2)
+ {:ok, u2, u1} = User.follow(u2, u1)
+ {:ok, u1, u4} = User.follow(u1, u4)
+ {:ok, u4, u1} = User.follow(u4, u1)
- {:ok, u2} = User.follow(u2, u3)
- {:ok, u3} = User.follow(u3, u2)
+ {:ok, u2, u3} = User.follow(u2, u3)
+ {:ok, u3, u2} = User.follow(u3, u2)
{:ok, a1} = CommonAPI.post(u1, %{status: "Status"})
defp private_messages(_) do
[u1, u2, u3, u4] = insert_list(4, :user)
- {:ok, u1} = User.follow(u1, u2)
- {:ok, u2} = User.follow(u2, u1)
- {:ok, u1} = User.follow(u1, u3)
- {:ok, u3} = User.follow(u3, u1)
- {:ok, u1} = User.follow(u1, u4)
- {:ok, u4} = User.follow(u4, u1)
-
- {:ok, u2} = User.follow(u2, u3)
- {:ok, u3} = User.follow(u3, u2)
+ {:ok, u1, u2} = User.follow(u1, u2)
+ {:ok, u2, u1} = User.follow(u2, u1)
+ {:ok, u1, u3} = User.follow(u1, u3)
+ {:ok, u3, u1} = User.follow(u3, u1)
+ {:ok, u1, u4} = User.follow(u1, u4)
+ {:ok, u4, u1} = User.follow(u4, u1)
+
+ {:ok, u2, u3} = User.follow(u2, u3)
+ {:ok, u3, u2} = User.follow(u3, u2)
{:ok, a1} = CommonAPI.post(u1, %{status: "Status", visibility: "private"})
actor = insert(:user, follower_address: follower.ap_id)
user = insert(:user)
- {:ok, _follower_one} = Pleroma.User.follow(follower, actor)
- actor = refresh_record(actor)
+ {:ok, follower, actor} = Pleroma.User.follow(follower, actor)
note_activity =
insert(:note_activity,
follower = insert(:user)
followed = insert(:user)
- {:ok, follower} = User.follow(follower, followed)
+ {:ok, follower, followed} = User.follow(follower, followed)
assert User.following?(follower, followed) == true
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
|> Map.put("object", blocked.ap_id)
|> Map.put("actor", blocker.ap_id)
- {:ok, blocker} = User.follow(blocker, blocked)
- {:ok, blocked} = User.follow(blocked, blocker)
+ {:ok, blocker, blocked} = User.follow(blocker, blocked)
+ {:ok, blocked, blocker} = User.follow(blocked, blocker)
assert User.following?(blocker, blocked)
assert User.following?(blocked, blocker)
follower = insert(:user)
followed = insert(:user, is_locked: true)
- {:ok, follower} = User.follow(follower, followed)
+ {:ok, follower, followed} = User.follow(follower, followed)
{:ok, _, _, follow_activity} = CommonAPI.follow(follower, followed)
assert User.following?(follower, followed) == true
mentioned = insert(:user)
following = insert(:user)
unrelated = insert(:user)
- {:ok, following} = Pleroma.User.follow(following, user)
+ {:ok, following, user} = Pleroma.User.follow(following, user)
{:ok, list} = Pleroma.List.create("foo", user)
Pleroma.List.follow(list, unrelated)
user_two = insert(:user)
user_three = insert(:user)
- {:ok, _user_three} = User.follow(user_three, user_one)
+ {:ok, _user_three, _user_one} = User.follow(user_three, user_one)
{:ok, activity} = CommonAPI.post(user_one, %{status: "HI!!!"})
test "getting followers", %{user: user, conn: conn} do
other_user = insert(:user)
- {:ok, %{id: user_id}} = User.follow(user, other_user)
+ {:ok, %{id: user_id}, other_user} = User.follow(user, other_user)
conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
test "getting followers, hide_followers", %{user: user, conn: conn} do
other_user = insert(:user, hide_followers: true)
- {:ok, _user} = User.follow(user, other_user)
+ {:ok, _user, _other_user} = User.follow(user, other_user)
conn = get(conn, "/api/v1/accounts/#{other_user.id}/followers")
test "getting followers, hide_followers, same user requesting" do
user = insert(:user)
other_user = insert(:user, hide_followers: true)
- {:ok, _user} = User.follow(user, other_user)
+ {:ok, _user, _other_user} = User.follow(user, other_user)
conn =
build_conn()
end
test "getting followers, pagination", %{user: user, conn: conn} do
- {:ok, %User{id: follower1_id}} = :user |> insert() |> User.follow(user)
- {:ok, %User{id: follower2_id}} = :user |> insert() |> User.follow(user)
- {:ok, %User{id: follower3_id}} = :user |> insert() |> User.follow(user)
+ {:ok, %User{id: follower1_id}, _user} = :user |> insert() |> User.follow(user)
+ {:ok, %User{id: follower2_id}, _user} = :user |> insert() |> User.follow(user)
+ {:ok, %User{id: follower3_id}, _user} = :user |> insert() |> User.follow(user)
assert [%{"id" => ^follower3_id}, %{"id" => ^follower2_id}] =
conn
test "getting following", %{user: user, conn: conn} do
other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
+ {:ok, user, other_user} = User.follow(user, other_user)
conn = get(conn, "/api/v1/accounts/#{user.id}/following")
test "getting following, hide_follows, other user requesting" do
user = insert(:user, hide_follows: true)
other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
+ {:ok, user, other_user} = User.follow(user, other_user)
conn =
build_conn()
test "getting following, hide_follows, same user requesting" do
user = insert(:user, hide_follows: true)
other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
+ {:ok, user, _other_user} = User.follow(user, other_user)
conn =
build_conn()
following1 = insert(:user)
following2 = insert(:user)
following3 = insert(:user)
- {:ok, _} = User.follow(user, following1)
- {:ok, _} = User.follow(user, following2)
- {:ok, _} = User.follow(user, following3)
+ {:ok, _, _} = User.follow(user, following1)
+ {:ok, _, _} = User.follow(user, following2)
+ {:ok, _, _} = User.follow(user, following3)
res_conn = get(conn, "/api/v1/accounts/#{user.id}/following?since_id=#{following1.id}")
test "returns the relationships for the current user", %{user: user, conn: conn} do
%{id: other_user_id} = other_user = insert(:user)
- {:ok, _user} = User.follow(user, other_user)
+ {:ok, _user, _other_user} = User.follow(user, other_user)
assert [%{"id" => ^other_user_id}] =
conn
user_two = insert(:user)
user_three = insert(:user)
- {:ok, user_two} = User.follow(user_two, user_one)
+ {:ok, user_two, user_one} = User.follow(user_two, user_one)
{:ok, %{user: user_one, user_two: user_two, user_three: user_three, conn: conn}}
end
other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
- {:ok, other_user} = User.follow(other_user, user, :follow_pending)
+ {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
assert User.following?(other_user, user) == false
other_user = insert(:user)
{:ok, _, _, _activity} = CommonAPI.follow(other_user, user)
- {:ok, other_user} = User.follow(other_user, user, :follow_pending)
+ {:ok, other_user, user} = User.follow(other_user, user, :follow_pending)
user = User.get_cached_by_id(user.id)
other_user = User.get_cached_by_id(other_user.id)
test "doesn't return replies if follower is posting with blocked user" do
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
[blockee, friend] = insert_list(2, :user)
- {:ok, blocker} = User.follow(blocker, friend)
+ {:ok, blocker, friend} = User.follow(blocker, friend)
{:ok, _} = User.block(blocker, blockee)
conn = assign(conn, :user, blocker)
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
friend = insert(:user)
blockee = insert(:user, ap_id: "https://example.com/users/blocked")
- {:ok, blocker} = User.follow(blocker, friend)
+ {:ok, blocker, friend} = User.follow(blocker, friend)
{:ok, blocker} = User.block_domain(blocker, "example.com")
conn = assign(conn, :user, blocker)
user_one = insert(:user)
user_two = insert(:user)
- {:ok, user_two} = User.follow(user_two, user_one)
+ {:ok, user_two, user_one} = User.follow(user_two, user_one)
{:ok, direct} =
CommonAPI.post(user_one, %{
test "returns ok if user already followed" do
follower = insert(:user)
user = insert(:user)
- {:ok, follower} = User.follow(follower, user)
+ {:ok, follower, user} = User.follow(follower, user)
{:ok, follower} = MastodonAPI.follow(follower, refresh_record(user))
assert User.following?(follower, user)
end
follower1_user = insert(:user)
follower2_user = insert(:user)
user = insert(:user)
- {:ok, _follower1_user} = User.follow(follower1_user, user)
- {:ok, follower2_user} = User.follow(follower2_user, user)
+ {:ok, _follower1_user, _user} = User.follow(follower1_user, user)
+ {:ok, follower2_user, _user} = User.follow(follower2_user, user)
assert MastodonAPI.get_followers(user, %{"limit" => 1}) == [follower2_user]
end
followed_two = insert(:user)
followed_three = insert(:user)
- {:ok, user} = User.follow(user, followed_one)
- {:ok, user} = User.follow(user, followed_two)
- {:ok, user} = User.follow(user, followed_three)
+ {:ok, user, followed_one} = User.follow(user, followed_one)
+ {:ok, user, followed_two} = User.follow(user, followed_two)
+ {:ok, user, followed_three} = User.follow(user, followed_three)
res = MastodonAPI.get_friends(user)
assert length(res) == 3
user = insert(:user)
other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
- {:ok, other_user} = User.follow(other_user, user)
+ {:ok, user, other_user} = User.follow(user, other_user)
+ {:ok, other_user, user} = User.follow(other_user, user)
{:ok, _subscription} = User.subscribe(user, other_user)
{:ok, _user_relationships} = User.mute(user, other_user, %{notifications: true})
{:ok, _reblog_mute} = CommonAPI.hide_reblogs(user, other_user)
user = insert(:user)
other_user = insert(:user)
- {:ok, user} = User.follow(user, other_user)
+ {:ok, user, other_user} = User.follow(user, other_user)
{:ok, _subscription} = User.subscribe(user, other_user)
{:ok, _user_relationship} = User.block(user, other_user)
{:ok, _user_relationship} = User.block(other_user, user)
|> json_response_and_validate_schema(200)
assert [{:ok, job_result}] = ObanHelpers.perform_all()
- assert job_result == [user2]
+ assert job_result == [refresh_record(user2)]
+ assert [%Pleroma.User{follower_count: 1}] = job_result
end
end
|> json_response_and_validate_schema(200)
assert [{:ok, job_result}] = ObanHelpers.perform_all()
- assert job_result == users
+ assert job_result == Enum.map(users, &refresh_record/1)
end
end
assert notif.activity.id == follow_activity.id
refute Streamer.filtered_by_user?(user, notif)
end
+
+ test "it sends relationships updates to the 'user' stream", %{
+ user: user,
+ token: oauth_token
+ } do
+ user_id = user.id
+ user_url = user.ap_id
+ follower = insert(:user)
+ follower_token = insert(:oauth_token, user: follower)
+ follower_id = follower.id
+
+ body =
+ File.read!("test/fixtures/users_mock/localhost.json")
+ |> String.replace("{{nickname}}", user.nickname)
+ |> Jason.encode!()
+
+ Tesla.Mock.mock_global(fn
+ %{method: :get, url: ^user_url} ->
+ %Tesla.Env{status: 200, body: body}
+ end)
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ Streamer.get_topic_and_add_socket("user", follower, follower_token)
+ {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(follower, user)
+
+ # follow_pending event sent to both follower and following
+ assert_receive {:text, event}
+ assert_receive {:text, ^event}
+
+ assert %{"event" => "pleroma:relationships_update", "payload" => payload} =
+ Jason.decode!(event)
+
+ assert %{
+ "follower" => %{
+ "follower_count" => 0,
+ "following_count" => 0,
+ "id" => ^follower_id
+ },
+ "following" => %{
+ "follower_count" => 0,
+ "following_count" => 0,
+ "id" => ^user_id
+ },
+ "state" => "follow_pending"
+ } = Jason.decode!(payload)
+
+ # follow_accept event sent to both follower and following
+ assert_receive {:text, event}
+ assert_receive {:text, ^event}
+
+ assert %{"event" => "pleroma:relationships_update", "payload" => payload} =
+ Jason.decode!(event)
+
+ assert %{
+ "follower" => %{
+ "follower_count" => 0,
+ "following_count" => 1,
+ "id" => ^follower_id
+ },
+ "following" => %{
+ "follower_count" => 1,
+ "following_count" => 0,
+ "id" => ^user_id
+ },
+ "state" => "follow_accept"
+ } = Jason.decode!(payload)
+ end
end
describe "public streams" do
user_b = insert(:user)
user_c = insert(:user)
- {:ok, user_a} = User.follow(user_a, user_b)
+ {:ok, user_a, user_b} = User.follow(user_a, user_b)
{:ok, list} = List.create("Test", user_a)
{:ok, list} = List.follow(list, user_b)
test "it sends wanted private posts to list", %{user: user_a, token: user_a_token} do
user_b = insert(:user)
- {:ok, user_a} = User.follow(user_a, user_b)
+ {:ok, user_a, user_b} = User.follow(user_a, user_b)
{:ok, list} = List.create("Test", user_a)
{:ok, list} = List.follow(list, user_b)