SideEffects: don't stream Create/ChatMessage in an 'update' event

This commit is contained in:
Alex Gleason 2022-02-28 14:56:20 -06:00
parent 4bdd365b6f
commit 1db95a1677
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7
2 changed files with 14 additions and 1 deletions

View file

@ -226,7 +226,11 @@ def handle(%{data: %{"type" => "Create"}} = activity, meta) do
meta
|> add_notifications(notifications)
ap_streamer().stream_out(activity)
# ChatMessages are special, as they get streamed in handle_object_creation/3
# TODO: maybe whitelist allowed object types to stream?
if object.data["type"] != "ChatMessage" do
ap_streamer().stream_out(activity)
end
{:ok, activity, meta}
else

View file

@ -298,6 +298,15 @@ test "it sends chat messages to the 'user' stream", %{user: user, token: oauth_t
assert_receive {:text, ^text}
end
test "it does not send 'update' events for chat messages", %{user: user, token: oauth_token} do
other_user = insert(:user)
Streamer.get_topic_and_add_socket("user", user, oauth_token)
{:ok, activity} = CommonAPI.post_chat_message(other_user, user, "hey")
refute_receive {:render_with_user, _, _, ^activity}
end
test "it sends chat message notifications to the 'user:notification' stream", %{
user: user,
token: oauth_token