Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

types: Extract update_message_event_schema.

Anders Kaseorg6dfa1b613812
diff --git a/tools/linter_lib/custom_check.py b/tools/linter_lib/custom_check.py
index 5560b141af5..e04d4039a18 100644
--- a/tools/linter_lib/custom_check.py
+++ b/tools/linter_lib/custom_check.py
@@ -117,7 +117,7 @@ js_rules = RuleList(
"pattern": "subject|SUBJECT",
"exclude": {
"web/src/message_store.ts",
- "web/src/types.ts",
+ "web/src/server_event_types.ts",
"web/src/util.ts",
"web/src/message_events_util.ts",
"web/src/message_helper.ts",
diff --git a/web/src/message_events.ts b/web/src/message_events.ts
index 74e6c80b0dd..64fc7e0a91c 100644
--- a/web/src/message_events.ts
+++ b/web/src/message_events.ts
@@ -31,13 +31,13 @@ import * as pm_list from "./pm_list.ts";
import * as recent_senders from "./recent_senders.ts";
import * as recent_view_ui from "./recent_view_ui.ts";
import * as recent_view_util from "./recent_view_util.ts";
+import type {UpdateMessageEvent} from "./server_event_types.ts";
import * as starred_messages from "./starred_messages.ts";
import * as starred_messages_ui from "./starred_messages_ui.ts";
import {realm} from "./state_data.ts";
import * as stream_list from "./stream_list.ts";
import * as stream_topic_history from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
-import type {UpdateMessageEvent} from "./types.ts";
import * as unread from "./unread.ts";
import * as unread_ui from "./unread_ui.ts";
import * as util from "./util.ts";
diff --git a/web/src/server_event_types.ts b/web/src/server_event_types.ts
index a11f388be39..14ebd91fe73 100644
--- a/web/src/server_event_types.ts
+++ b/web/src/server_event_types.ts
@@ -1,6 +1,6 @@
import {z} from "zod";
-import {group_setting_value_schema} from "./types.ts";
+import {group_setting_value_schema, topic_link_schema} from "./types.ts";
export const user_group_update_event_schema = z.object({
id: z.number(),
@@ -20,3 +20,30 @@ export const user_group_update_event_schema = z.object({
}),
});
export type UserGroupUpdateEvent = z.output<typeof user_group_update_event_schema>;
+
+export const update_message_event_schema = z.object({
+ id: z.number(),
+ type: z.literal("update_message"),
+ user_id: z.nullable(z.number()),
+ rendering_only: z.boolean(),
+ message_id: z.number(),
+ message_ids: z.array(z.number()),
+ flags: z.array(z.string()),
+ edit_timestamp: z.number(),
+ stream_name: z.optional(z.string()),
+ stream_id: z.optional(z.number()),
+ new_stream_id: z.optional(z.number()),
+ propagate_mode: z.optional(z.string()),
+ orig_subject: z.optional(z.string()),
+ subject: z.optional(z.string()),
+ topic_links: z.optional(z.array(topic_link_schema)),
+ orig_content: z.optional(z.string()),
+ orig_rendered_content: z.optional(z.string()),
+ content: z.optional(z.string()),
+ rendered_content: z.optional(z.string()),
+ is_me_message: z.optional(z.boolean()),
+ // The server is still using subject.
+ // This will not be set until it gets fixed.
+ topic: z.optional(z.string()),
+});
+export type UpdateMessageEvent = z.output<typeof update_message_event_schema>;
diff --git a/web/src/types.ts b/web/src/types.ts
index 51ebdb61803..149060b28ca 100644
--- a/web/src/types.ts
+++ b/web/src/types.ts
@@ -8,33 +8,6 @@ export const topic_link_schema = z.object({
export type TopicLink = z.infer<typeof topic_link_schema>;
-// TODO/typescript: Move this to server_events
-export type UpdateMessageEvent = {
- id: number;
- type: string;
- user_id: number | null;
- rendering_only: boolean;
- message_id: number;
- message_ids: number[];
- flags: string[];
- edit_timestamp: number;
- stream_name?: string;
- stream_id?: number;
- new_stream_id?: number;
- propagate_mode?: string;
- orig_subject?: string;
- subject?: string;
- topic_links?: TopicLink[];
- orig_content?: string;
- orig_rendered_content?: string;
- content?: string;
- rendered_content?: string;
- is_me_message?: boolean;
- // The server is still using subject.
- // This will not be set until it gets fixed.
- topic?: string;
-};
-
export type HTMLSelectOneElement = HTMLSelectElement & {type: "select-one"};
export const anonymous_group_schema = z.object({
diff --git a/web/src/unread.ts b/web/src/unread.ts
index fa4853013f4..b51fd3f7be5 100644
--- a/web/src/unread.ts
+++ b/web/src/unread.ts
@@ -6,6 +6,7 @@ import * as message_store from "./message_store.ts";
import type {Message} from "./message_store.ts";
import * as people from "./people.ts";
import * as recent_view_util from "./recent_view_util.ts";
+import type {UpdateMessageEvent} from "./server_event_types.ts";
import * as settings_config from "./settings_config.ts";
import type {
StateData,
@@ -15,7 +16,6 @@ import type {
import * as stream_data from "./stream_data.ts";
import type {TopicHistoryEntry} from "./stream_topic_history.ts";
import * as sub_store from "./sub_store.ts";
-import type {UpdateMessageEvent} from "./types.ts";
import {user_settings} from "./user_settings.ts";
import * as user_topics from "./user_topics.ts";
import * as util from "./util.ts";
diff --git a/web/src/util.ts b/web/src/util.ts
index 410d7c95a90..284a7648aa0 100644
--- a/web/src/util.ts
+++ b/web/src/util.ts
@@ -3,7 +3,7 @@ import _ from "lodash";
import * as blueslip from "./blueslip.ts";
import type {MatchedMessage, Message, RawMessage} from "./message_store.ts";
-import type {UpdateMessageEvent} from "./types.ts";
+import type {UpdateMessageEvent} from "./server_event_types.ts";
import {user_settings} from "./user_settings.ts";
// From MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Math/random