server_events: Parse `message` recieved from server.

This commit is contained in:
Varun Singh 2024-07-16 23:11:41 +05:30 committed by Tim Abbott
parent 7d0ea7e1e3
commit 3d01ccbbd5
2 changed files with 39 additions and 5 deletions

View File

@ -11,6 +11,7 @@ import * as reload from "./reload";
import * as reload_state from "./reload_state"; import * as reload_state from "./reload_state";
import * as sent_messages from "./sent_messages"; import * as sent_messages from "./sent_messages";
import * as server_events_dispatch from "./server_events_dispatch"; 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 ui_report from "./ui_report";
import * as watchdog from "./watchdog"; import * as watchdog from "./watchdog";
@ -66,7 +67,7 @@ function get_events_success(events) {
const dispatch_event = function dispatch_event(event) { const dispatch_event = function dispatch_event(event) {
switch (event.type) { switch (event.type) {
case "message": { case "message": {
const msg = event.message; const msg = server_message_schema.parse(event.message);
msg.flags = event.flags; msg.flags = event.flags;
if (event.local_message_id) { if (event.local_message_id) {
msg.local_id = event.local_message_id; msg.local_id = event.local_message_id;

View File

@ -51,14 +51,47 @@ const message_events = mock_esm("../src/message_events", {
const server_events = zrequire("server_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(); server_events.finished_initial_fetch();
run_test("message_event", ({override}) => { run_test("message_event", ({override}) => {
const event = { const event = {
type: "message", type: "message",
message: { message,
content: "hello",
},
flags: [], flags: [],
}; };
@ -102,7 +135,7 @@ run_test("event_dispatch_error", () => {
run_test("event_new_message_error", () => { run_test("event_new_message_error", () => {
setup(); setup();
const data = {events: [{type: "message", id: 1, other: "thing", message: {}}]}; const data = {events: [{type: "message", id: 1, other: "thing", message}]};
channel.get = (options) => { channel.get = (options) => {
options.success(data); options.success(data);
}; };