Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
tenor_network: Use a new network object per picker instance.
apoorvapendse141cec63118c
diff --git a/web/src/tenor.ts b/web/src/tenor.tsindex 01e516dd299..c31ccab222c 100644--- a/web/src/tenor.ts+++ b/web/src/tenor.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;-const network = new tenor_network.TenorNetwork();+let network: tenor_network.TenorNetwork;function is_editing_existing_message(): boolean {if (compose_icon_session === undefined) {@@ -105,19 +105,14 @@ export function hide_tenor_popover(): boolean {tenor_popover_instance.destroy();tenor_popover_instance = undefined;current_search_term = undefined;- network.reset();+ network.abandon();return true;}return false;}function render_gifs_to_grid(urls: GifInfoUrl[], next_page: boolean): void {- // Tenor popover may have been hidden by the- // time this function is called.- if (tenor_popover_instance === undefined) {- return;- }-+ assert(tenor_popover_instance !== undefined);let gif_grid_html = "";if (!next_page) {@@ -249,6 +244,10 @@ function register_click_handlers(): void {".compose_control_button.compose-gif-icon-tenor",function (this: HTMLElement) {compose_icon_session = new ComposeIconSession(this);+ if (network) {+ network.abandon();+ }+ network = new tenor_network.TenorNetwork();toggle_tenor_popover(this);},);diff --git a/web/src/tenor_network.ts b/web/src/tenor_network.tsindex 6b8c148aeba..3d85b68fbe6 100644--- a/web/src/tenor_network.ts+++ b/web/src/tenor_network.ts@@ -1,3 +1,4 @@+import assert from "minimalistic-assert";import * as z from "zod/mini";import * as channel from "./channel.ts";@@ -48,17 +49,18 @@ export type TenorPayload = {export class TenorNetwork {is_loading_more = false;next_pos_identifier: string | number | undefined;+ abandoned = false;is_loading_more_gifs(): boolean {return this.is_loading_more;}- reset(): void {- this.is_loading_more = false;- this.next_pos_identifier = undefined;+ abandon(): void {+ this.abandoned = true;}ask_for_default_gifs(next_page: boolean, render_gifs_callback: RenderGifsCallback): void {+ assert(!this.abandoned);// We use "default" generically here in anticipation of// tenor default == featured// giphy default == trending@@ -71,6 +73,7 @@ export class TenorNetwork {next_page: boolean,render_gifs_callback: RenderGifsCallback,): void {+ assert(!this.abandoned);const data: TenorPayload = {q: search_term,...get_base_payload(),@@ -85,6 +88,7 @@ export class TenorNetwork {next_page = false,render_gifs_callback: RenderGifsCallback,): void {+ assert(!this.abandoned);if (next_page) {this.is_loading_more = true;data = {...data, pos: this.next_pos_identifier};@@ -93,6 +97,12 @@ export class TenorNetwork {url,data,success: (raw_tenor_result) => {+ // We don't want to have this code run after the caller+ // abandons its network object, to avoid all sorts of weird+ // bugs.+ if (this.abandoned) {+ return;+ }const parsed_data = tenor_result_schema.parse(raw_tenor_result);const urls: GifInfoUrl[] = parsed_data.results.map((result) => ({preview_url: result.media_formats.tinygif.url,