SideEffects: Correctly handle chat messages sent to yourself
authorlain <lain@soykaf.club>
Thu, 22 Oct 2020 10:22:08 +0000 (12:22 +0200)
committerlain <lain@soykaf.club>
Thu, 22 Oct 2020 10:22:08 +0000 (12:22 +0200)
lib/pleroma/web/activity_pub/side_effects.ex
test/pleroma/web/common_api_test.exs

index d421ca7af59c713f6cba366bbecfbbd273f91d27..0fff5faf2d4a138978f6ff8c85097574e7f0320d 100644 (file)
@@ -306,6 +306,7 @@ defmodule Pleroma.Web.ActivityPub.SideEffects do
 
       streamables =
         [[actor, recipient], [recipient, actor]]
+        |> Enum.uniq()
         |> Enum.map(fn [user, other_user] ->
           if user.local do
             {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
index f5d09f39657eabd614de0491b3a665a445a7df3f..d8dc90173fd75154fbaca6516451daf698eaa771 100644 (file)
@@ -95,6 +95,20 @@ defmodule Pleroma.Web.CommonAPITest do
   describe "posting chat messages" do
     setup do: clear_config([:instance, :chat_limit])
 
+    test "it posts a self-chat" do
+      author = insert(:user)
+      recipient = author
+
+      {:ok, activity} =
+        CommonAPI.post_chat_message(
+          author,
+          recipient,
+          "remember to buy milk when milk truk arive"
+        )
+
+      assert activity.data["type"] == "Create"
+    end
+
     test "it posts a chat message without content but with an attachment" do
       author = insert(:user)
       recipient = insert(:user)