- [[actor, recipient], [recipient, actor]]
- |> Enum.each(fn [user, other_user] ->
- if user.local do
- {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
- {:ok, cm_ref} = ChatMessageReference.create(chat, object, user.ap_id != actor.ap_id)
-
- # We add a cache of the unread value here so that it
- # doesn't change when being streamed out
- chat =
- chat
- |> Map.put(:unread, ChatMessageReference.unread_count_for_chat(chat))
-
- Streamer.stream(
- ["user", "user:pleroma_chat"],
- {user, %{cm_ref | chat: chat, object: object}}
- )
- end
- end)
+ streamables =
+ [[actor, recipient], [recipient, actor]]
+ |> Enum.map(fn [user, other_user] ->
+ if user.local do
+ {:ok, chat} = Chat.bump_or_create(user.id, other_user.ap_id)
+ {:ok, cm_ref} = MessageReference.create(chat, object, user.ap_id != actor.ap_id)
+
+ {
+ ["user", "user:pleroma_chat"],
+ {user, %{cm_ref | chat: chat, object: object}}
+ }
+ end
+ end)
+ |> Enum.filter(& &1)
+
+ meta =
+ meta
+ |> add_streamables(streamables)