1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.ConversationTest do
7 alias Pleroma.Conversation
8 alias Pleroma.Web.CommonAPI
10 import Pleroma.Factory
12 test "it creates a conversation for given ap_id" do
13 assert {:ok, %Conversation{} = conversation} =
14 Conversation.create_for_ap_id("https://some_ap_id")
16 # Inserting again returns the same
17 assert {:ok, conversation_two} = Conversation.create_for_ap_id("https://some_ap_id")
18 assert conversation_two.id == conversation.id
21 test "public posts don't create conversations" do
23 {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey"})
25 context = activity.data["object"]["context"]
27 conversation = Conversation.get_for_ap_id(context)
32 test "it creates or updates a conversation and participations for a given DM" do
34 jafnhar = insert(:user, local: false)
38 CommonAPI.post(har, %{"status" => "Hey @#{jafnhar.nickname}", "visibility" => "direct"})
40 context = activity.data["object"]["context"]
43 Conversation.get_for_ap_id(context)
44 |> Repo.preload(:participations)
48 assert Enum.find(conversation.participations, fn %{user_id: user_id} -> har.id == user_id end)
50 assert Enum.find(conversation.participations, fn %{user_id: user_id} ->
55 CommonAPI.post(jafnhar, %{
56 "status" => "Hey @#{har.nickname}",
57 "visibility" => "direct",
58 "in_reply_to_status_id" => activity.id
61 context = activity.data["object"]["context"]
64 Conversation.get_for_ap_id(context)
65 |> Repo.preload(:participations)
67 assert conversation_two.id == conversation.id
69 assert Enum.find(conversation_two.participations, fn %{user_id: user_id} ->
73 assert Enum.find(conversation_two.participations, fn %{user_id: user_id} ->
78 CommonAPI.post(tridi, %{
79 "status" => "Hey @#{har.nickname}",
80 "visibility" => "direct",
81 "in_reply_to_status_id" => activity.id
84 context = activity.data["object"]["context"]
87 Conversation.get_for_ap_id(context)
88 |> Repo.preload([:participations, :users])
90 assert conversation_three.id == conversation.id
92 assert Enum.find(conversation_three.participations, fn %{user_id: user_id} ->
96 assert Enum.find(conversation_three.participations, fn %{user_id: user_id} ->
100 assert Enum.find(conversation_three.participations, fn %{user_id: user_id} ->
104 assert Enum.find(conversation_three.users, fn %{id: user_id} ->
108 assert Enum.find(conversation_three.users, fn %{id: user_id} ->
109 jafnhar.id == user_id
112 assert Enum.find(conversation_three.users, fn %{id: user_id} ->