+ {inbox1, inbox2} =
+ {"https://domain.com/users/nick1/inbox", "https://domain2.com/users/nick2/inbox"}
+
+ insert(:user, %{
+ local: false,
+ nickname: "nick1@domain.com",
+ ap_id: "https://domain.com/users/nick1",
+ info: %{ap_enabled: true, source_data: %{"inbox" => inbox1}}
+ })
+
+ insert(:user, %{
+ local: false,
+ nickname: "nick2@domain2.com",
+ ap_id: "https://domain2.com/users/nick2",
+ info: %{ap_enabled: true, source_data: %{"inbox" => inbox2}}
+ })
+
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(inbox1, dt)
+
+ Instances.set_consistently_unreachable(URI.parse(inbox2).host)
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
+
+ assert called(
+ Pleroma.Web.ActivityPub.Publisher.publish_one(%{
+ inbox: inbox1,
+ unreachable_since: dt
+ })
+ )
+
+ refute called(Pleroma.Web.ActivityPub.Publisher.publish_one(%{inbox: inbox2}))
+ end
+
+ test_with_mock "it federates only to reachable instances via Websub",
+ Pleroma.Web.Websub,
+ [:passthrough],
+ [] do
+ user = insert(:user)
+ websub_topic = Pleroma.Web.OStatus.feed_path(user)
+
+ sub1 =
+ insert(:websub_subscription, %{
+ topic: websub_topic,
+ state: "active",
+ callback: "http://pleroma.soykaf.com/cb"
+ })
+
+ sub2 =
+ insert(:websub_subscription, %{
+ topic: websub_topic,
+ state: "active",
+ callback: "https://pleroma2.soykaf.com/cb"
+ })
+
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(sub2.callback, dt)
+
+ Instances.set_consistently_unreachable(sub1.callback)
+
+ {:ok, _activity} = CommonAPI.post(user, %{"status" => "HI"})
+
+ assert called(
+ Pleroma.Web.Websub.publish_one(%{
+ callback: sub2.callback,
+ unreachable_since: dt
+ })
+ )
+
+ refute called(Pleroma.Web.Websub.publish_one(%{callback: sub1.callback}))
+ end
+
+ test_with_mock "it federates only to reachable instances via Salmon",
+ Pleroma.Web.Salmon,
+ [:passthrough],
+ [] do
+ user = insert(:user)
+
+ remote_user1 =
+ insert(:user, %{
+ local: false,
+ nickname: "nick1@domain.com",
+ ap_id: "https://domain.com/users/nick1",
+ info: %{salmon: "https://domain.com/salmon"}
+ })
+
+ remote_user2 =
+ insert(:user, %{
+ local: false,
+ nickname: "nick2@domain2.com",
+ ap_id: "https://domain2.com/users/nick2",
+ info: %{salmon: "https://domain2.com/salmon"}
+ })
+
+ dt = NaiveDateTime.utc_now()
+ Instances.set_unreachable(remote_user2.ap_id, dt)
+
+ Instances.set_consistently_unreachable("domain.com")
+
+ {:ok, _activity} =
+ CommonAPI.post(user, %{"status" => "HI @nick1@domain.com, @nick2@domain2.com!"})
+
+ assert called(
+ Pleroma.Web.Salmon.publish_one(%{
+ recipient: remote_user2,
+ unreachable_since: dt
+ })
+ )
+
+ refute called(Pleroma.Web.Salmon.publish_one(%{recipient: remote_user1}))