From: lain Date: Thu, 8 Aug 2019 14:04:20 +0000 (+0200) Subject: Merge remote-tracking branch 'origin/develop' into pleroma-conversations X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=a2b98f6d58218c5806247743aa0a2a600c9959ab;p=akkoma Merge remote-tracking branch 'origin/develop' into pleroma-conversations --- a2b98f6d58218c5806247743aa0a2a600c9959ab diff --cc lib/pleroma/web/common_api/utils.ex index 425b6d656,22c44a0a3..61b96aba9 --- a/lib/pleroma/web/common_api/utils.ex +++ b/lib/pleroma/web/common_api/utils.ex @@@ -60,26 -74,21 +75,33 @@@ defmodule Pleroma.Web.CommonAPI.Utils d def attachments_from_ids_descs(ids, descs_str) do {_, descs} = Jason.decode(descs_str) - Enum.map(ids || [], fn media_id -> - Map.put(Repo.get(Object, media_id).data, "name", descs[media_id]) + Enum.map(ids, fn media_id -> + case Repo.get(Object, media_id) do + %Object{data: data} = _ -> + Map.put(data, "name", descs[media_id]) + + _ -> + nil + end end) + |> Enum.filter(& &1) end - @spec get_to_and_cc(User.t(), list(String.t()), Activity.t() | nil, String.t()) :: + @spec get_to_and_cc( + User.t(), + list(String.t()), + Activity.t() | nil, + String.t(), + Participation.t() | nil + ) :: {list(String.t()), list(String.t())} - def get_to_and_cc(user, mentioned_users, inReplyTo, "public") do + + def get_to_and_cc(_, _, _, _, %Participation{} = participation) do + participation = Repo.preload(participation, :recipients) + {Enum.map(participation.recipients, & &1.ap_id), []} + end + + def get_to_and_cc(user, mentioned_users, inReplyTo, "public", _) do to = [Pleroma.Constants.as_public() | mentioned_users] cc = [user.follower_address] diff --cc test/web/common_api/common_api_utils_test.exs index 7510c8def,5989d7d29..c281dd1f1 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@@ -305,8 -305,7 +305,7 @@@ defmodule Pleroma.Web.CommonAPI.UtilsTe mentioned_user = insert(:user) mentions = [mentioned_user.ap_id] - {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private") + {to, cc} = Utils.get_to_and_cc(user, mentions, nil, "private", nil) - assert length(to) == 2 assert length(cc) == 0