Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
abstract_network_gif: Introduce an abstract base class.
apoorvapendseacf300bac337
diff --git a/web/src/abstract_gif_network.ts b/web/src/abstract_gif_network.tsindex 8b8eca11541..bd06464785a 100644--- a/web/src/abstract_gif_network.ts+++ b/web/src/abstract_gif_network.ts@@ -4,3 +4,34 @@ export type GifInfoUrl = {};export type RenderGifsCallback = (urls: GifInfoUrl[], next_page: boolean) => void;++// When a user clicks on the gif icon either while composing a+// message in the normal compose box or while editing a+// message, the UI will need to talk to a third party+// vendor such as tenor to get gifs.++// The network class will need to support this protocol.++// Typically, the UI will instantiate an object from a derived subclass+// of `GifNetwork`.+// Then they will make one or more calls to ask_for_*() to ask the+// third party to send back gif urls. See the callback+// type definition as well (RenderGifsCallback).++// The final piece of the contract is that if the user abandons the UI+// (typically the picker is a popover, but we don't care here), then+// the UI should call `abandon()` below. And then they should+// obviously never call the object again.+export abstract class GifNetwork {+ abstract is_loading_more_gifs(): boolean;+ abstract ask_for_default_gifs(+ next_page: boolean,+ render_gifs_callback: RenderGifsCallback,+ ): void;+ abstract ask_for_search_gifs(+ search_term: string,+ next_page: boolean,+ render_gifs_callback: RenderGifsCallback,+ ): void;+ abstract abandon(): void;+}diff --git a/web/src/tenor.ts b/web/src/tenor.tsindex c31ccab222c..0348365f94c 100644--- a/web/src/tenor.ts+++ b/web/src/tenor.ts@@ -5,7 +5,7 @@ import type * as tippy from "tippy.js";import render_tenor_gif from "../templates/tenor_gif.hbs";-import type {GifInfoUrl} from "./abstract_gif_network.ts";+import type {GifInfoUrl, GifNetwork} from "./abstract_gif_network.ts";import {ComposeIconSession} from "./compose_icon_session.ts";import * as gif_picker_popover_content from "./gif_picker_popover_content.ts";import * as popover_menus from "./popover_menus.ts";@@ -18,7 +18,7 @@ let tenor_popover_instance: tippy.Instance | undefined;let current_search_term: undefined | string;// Stores the index of the last GIF that is part of the grid.let last_gif_index = -1;-let network: tenor_network.TenorNetwork;+let network: GifNetwork;function is_editing_existing_message(): boolean {if (compose_icon_session === undefined) {diff --git a/web/src/tenor_network.ts b/web/src/tenor_network.tsindex 3d85b68fbe6..6d88e345bb1 100644--- a/web/src/tenor_network.ts+++ b/web/src/tenor_network.ts@@ -1,11 +1,11 @@import assert from "minimalistic-assert";import * as z from "zod/mini";+import {type GifInfoUrl, GifNetwork, type RenderGifsCallback} from "./abstract_gif_network.ts";import * as channel from "./channel.ts";import {get_rating} from "./gif_state.ts";import {realm} from "./state_data.ts";import {user_settings} from "./user_settings.ts";-import type { GifInfoUrl, RenderGifsCallback } from "./abstract_gif_network.ts";const BASE_URL = "https://tenor.googleapis.com/v2";@@ -46,7 +46,7 @@ export type TenorPayload = {q?: string;};-export class TenorNetwork {+export class TenorNetwork extends GifNetwork {is_loading_more = false;next_pos_identifier: string | number | undefined;abandoned = false;