Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
stream_topic_history_util: Convert module to typescript.
evykassirer4b14f0efadce
diff --git a/web/src/stream_topic_history_util.js b/web/src/stream_topic_history_util.tssimilarity index 62%rename from web/src/stream_topic_history_util.jsrename to web/src/stream_topic_history_util.tsindex 377af8e7d72..44d46061210 100644--- a/web/src/stream_topic_history_util.js+++ b/web/src/stream_topic_history_util.ts@@ -1,7 +1,18 @@+import {z} from "zod";+import * as channel from "./channel";import * as stream_topic_history from "./stream_topic_history";-export function get_server_history(stream_id, on_success) {+const stream_topic_history_response_schema = z.object({+ topics: z.array(+ z.object({+ name: z.string(),+ max_id: z.number(),+ }),+ ),+});++export function get_server_history(stream_id: number, on_success: () => void): void {if (stream_topic_history.has_history_for(stream_id)) {on_success();return;@@ -13,11 +24,12 @@ export function get_server_history(stream_id, on_success) {stream_topic_history.add_request_pending_for(stream_id);const url = "/json/users/me/" + stream_id + "/topics";- channel.get({+ void channel.get({url,data: {},success(data) {- const server_history = data.topics;+ const clean_data = stream_topic_history_response_schema.parse(data);+ const server_history = clean_data.topics;stream_topic_history.add_history(stream_id, server_history);stream_topic_history.remove_request_pending_for(stream_id);on_success();