diff --git a/web/src/server_events.js b/web/src/server_events.js index d78c8a0b44..d7ca38a9bf 100644 --- a/web/src/server_events.js +++ b/web/src/server_events.js @@ -11,6 +11,7 @@ import * as reload from "./reload"; import * as reload_state from "./reload_state"; import * as sent_messages from "./sent_messages"; import * as server_events_dispatch from "./server_events_dispatch"; +import {server_message_schema} from "./server_message"; import * as ui_report from "./ui_report"; import * as watchdog from "./watchdog"; @@ -66,7 +67,7 @@ function get_events_success(events) { const dispatch_event = function dispatch_event(event) { switch (event.type) { case "message": { - const msg = event.message; + const msg = server_message_schema.parse(event.message); msg.flags = event.flags; if (event.local_message_id) { msg.local_id = event.local_message_id; diff --git a/web/tests/server_events.test.js b/web/tests/server_events.test.js index c03a4cb157..87b83c9ad1 100644 --- a/web/tests/server_events.test.js +++ b/web/tests/server_events.test.js @@ -51,14 +51,47 @@ const message_events = mock_esm("../src/message_events", { const server_events = zrequire("server_events"); +const message = { + id: 1, + sender_id: 2, + content: "hello", + recipient_id: 3, + timestamp: 100000000, + client: "website", + subject: "server_test", + topic_links: [], + is_me_message: false, + reactions: [ + { + emoji_name: "foo", + emoji_code: "bar", + reaction_type: "unicode_emoji", + user: { + email: "user1@foo.com", + id: 1, + full_name: "aaron", + is_mirror_dummy: false, + }, + user_id: 1, + }, + ], + submessages: [], + sender_full_name: "user1", + sender_email: "user2@foo.com", + sender_realm_str: "foo", + display_recipient: "test", + type: "stream", + stream_id: 1, + avatar_url: "bar", + content_type: "text/html", +}; + server_events.finished_initial_fetch(); run_test("message_event", ({override}) => { const event = { type: "message", - message: { - content: "hello", - }, + message, flags: [], }; @@ -102,7 +135,7 @@ run_test("event_dispatch_error", () => { run_test("event_new_message_error", () => { setup(); - const data = {events: [{type: "message", id: 1, other: "thing", message: {}}]}; + const data = {events: [{type: "message", id: 1, other: "thing", message}]}; channel.get = (options) => { options.success(data); };