types: Extract update_message_event_schema.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2024-12-19 16:44:13 -08:00
committed by Tim Abbott
parent 2548430af3
commit 6dfa1b6138
6 changed files with 32 additions and 32 deletions

View File

@@ -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",

View File

@@ -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";

View File

@@ -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>;

View File

@@ -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({

View File

@@ -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";

View File

@@ -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