Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
giphy: Refactor Giphy integration to centralize common parts.
apoorvapendse630eba704db1
diff --git a/tools/test-js-with-node b/tools/test-js-with-nodeindex 13fc4a9c312..525dc7910d4 100755--- a/tools/test-js-with-node+++ b/tools/test-js-with-node@@ -113,8 +113,8 @@ EXEMPT_FILES = make_set("web/src/fetch_status.ts","web/src/flatpickr.ts","web/src/gear_menu.ts",+ "web/src/gif_state.ts","web/src/giphy.ts",- "web/src/giphy_state.ts","web/src/global.ts","web/src/group_permission_settings.ts","web/src/group_setting_pill.ts",diff --git a/web/src/click_handlers.ts b/web/src/click_handlers.tsindex 31d6cb413c8..7df4bd9e36a 100644--- a/web/src/click_handlers.ts+++ b/web/src/click_handlers.ts@@ -772,7 +772,7 @@ export function initialize(): void {function handle_compose_click(e: JQuery.ClickEvent): void {const $target = $(e.target);// Emoji clicks should be handled by their own click handler in emoji_picker.js- if ($target.is(".emoji_map, img.emoji, .drag, .compose_gif_icon")) {+ if ($target.is(".emoji_map, img.emoji, .drag, .compose-gif-icon-giphy")) {return;}diff --git a/web/src/giphy_state.ts b/web/src/gif_state.tssimilarity index 100%rename from web/src/giphy_state.tsrename to web/src/gif_state.tsdiff --git a/web/src/giphy.ts b/web/src/giphy.tsindex 7d6aba11229..6a975b14c6d 100644--- a/web/src/giphy.ts+++ b/web/src/giphy.ts@@ -5,7 +5,7 @@ import _ from "lodash";import assert from "minimalistic-assert";import type * as tippy from "tippy.js";-import render_giphy_picker from "../templates/giphy_picker.hbs";+import render_gif_picker_ui from "../templates/gif_picker_ui.hbs";import * as blueslip from "./blueslip.ts";import * as compose_ui from "./compose_ui.ts";@@ -37,9 +37,9 @@ export function update_giphy_rating(): void {realm.realm_giphy_rating === realm.giphy_rating_options.disabled.id ||realm.giphy_api_key === "") {- $(".compose_gif_icon").hide();+ $(".compose-gif-icon-giphy").hide();} else {- $(".compose_gif_icon").show();+ $(".compose-gif-icon-giphy").show();}}@@ -130,13 +130,13 @@ async function update_grid_with_search_term(): Promise<void> {return;}- const $search_elem = $<HTMLInputElement>("input#giphy-search-query");+ const $search_elem = $<HTMLInputElement>("input#gif-search-query");// GIPHY popover may have been hidden by the// time this function is called.if ($search_elem.length > 0) {search_term = the($search_elem).value;gifs_grid.remove();- gifs_grid = await renderGIPHYGrid(the($("#giphy_grid_in_popover .giphy-content")));+ gifs_grid = await renderGIPHYGrid(the($(".gif-grid-in-popover .giphy-content")));return;}@@ -163,7 +163,7 @@ function toggle_giphy_popover(target: HTMLElement): void {theme: "popover-menu",placement: "top",onCreate(instance) {- instance.setContent(ui_util.parse_html(render_giphy_picker()));+ instance.setContent(ui_util.parse_html(render_gif_picker_ui()));$(instance.popper).addClass("giphy-popover");},onShow(instance) {@@ -185,7 +185,7 @@ function toggle_giphy_popover(target: HTMLElement): void {$popper.on("keyup",- "#giphy-search-query",+ "#gif-search-query",// Use debounce to create a 300ms interval between// every search. This makes the UX of searching pleasant// by allowing user to finish typing before search@@ -194,11 +194,11 @@ function toggle_giphy_popover(target: HTMLElement): void {);$popper.on("keydown", ".giphy-gif", ui_util.convert_enter_to_click);- $popper.on("keydown", ".compose_gif_icon", ui_util.convert_enter_to_click);+ $popper.on("keydown", ".compose-gif-icon-giphy", ui_util.convert_enter_to_click);$popper.on("click", "#giphy_search_clear", (e) => {e.stopPropagation();- $("#giphy-search-query").val("");+ $("#gif-search-query").val("");void update_grid_with_search_term();});@@ -208,7 +208,7 @@ function toggle_giphy_popover(target: HTMLElement): void {// Focus on search box by default.// This is specially helpful for users// navigating via keyboard.- $("#giphy-search-query").trigger("focus");+ $("#gif-search-query").trigger("focus");})();},onHidden() {@@ -223,9 +223,13 @@ function toggle_giphy_popover(target: HTMLElement): void {}function register_click_handlers(): void {- $("body").on("click", ".compose_control_button.compose_gif_icon", function (this: HTMLElement) {- toggle_giphy_popover(this);- });+ $("body").on(+ "click",+ ".compose_control_button.compose-gif-icon-giphy",+ function (this: HTMLElement) {+ toggle_giphy_popover(this);+ },+ );}export function initialize(): void {diff --git a/web/src/message_edit.ts b/web/src/message_edit.tsindex 814ea8f2ecd..9d0e720365b 100644--- a/web/src/message_edit.ts+++ b/web/src/message_edit.ts@@ -34,7 +34,7 @@ import {show_copied_confirmation} from "./copied_tooltip.ts";import * as dialog_widget from "./dialog_widget.ts";import * as echo from "./echo.ts";import * as feedback_widget from "./feedback_widget.ts";-import * as giphy_state from "./giphy_state.ts";+import * as gif_state from "./gif_state.ts";import * as hash_util from "./hash_util.ts";import {$t, $t_html} from "./i18n.ts";import * as keydown_util from "./keydown_util.ts";@@ -578,7 +578,7 @@ function edit_message($row: JQuery, raw_content: string): void {is_editable,content: raw_content,file_upload_enabled,- giphy_enabled: giphy_state.is_giphy_enabled(),+ giphy_enabled: gif_state.is_giphy_enabled(),minutes_to_edit: Math.floor((realm.realm_message_content_edit_limit_seconds ?? 0) / 60),max_message_length: realm.max_message_length,}),diff --git a/web/src/ui_init.js b/web/src/ui_init.jsindex 5b34170f366..1b51dee7eea 100644--- a/web/src/ui_init.js+++ b/web/src/ui_init.js@@ -51,8 +51,8 @@ import * as emoji_picker from "./emoji_picker.ts";import * as emojisets from "./emojisets.ts";import * as fenced_code from "./fenced_code.ts";import * as gear_menu from "./gear_menu.ts";+import * as gif_state from "./gif_state.ts";import * as giphy from "./giphy.ts";-import * as giphy_state from "./giphy_state.ts";import * as group_permission_settings from "./group_permission_settings.ts";import * as hashchange from "./hashchange.ts";import * as hotkey from "./hotkey.ts";@@ -208,7 +208,7 @@ function initialize_compose_box() {render_compose({embedded: $("#compose").attr("data-embedded") === "",file_upload_enabled: realm.max_file_upload_size_mib > 0 && upload.feature_check(),- giphy_enabled: giphy_state.is_giphy_enabled(),+ giphy_enabled: gif_state.is_giphy_enabled(),max_stream_name_length: realm.max_stream_name_length,max_topic_length: realm.max_topic_length,empty_string_topic_display_name: util.get_final_topic_display_name(""),diff --git a/web/styles/popovers.css b/web/styles/popovers.cssindex 093929b5e9d..65c53a4d6a6 100644--- a/web/styles/popovers.css+++ b/web/styles/popovers.css@@ -763,7 +763,7 @@ ul.popover-group-menu-member-list {}}-#giphy_grid_in_popover {+.gif-grid-in-popover {/* 300px of GIPHY grid + 5px is the extra gutter space* + 1px for outline.* between gif columns. */@@ -782,7 +782,7 @@ ul.popover-group-menu-member-list {outline: 1px solid hsl(0deg 100% 50%);}- .giphy-scrolling-container {+ .gif-scrolling-container {overflow: hidden auto;height: 200px;margin: 2px 3px;diff --git a/web/templates/compose_control_buttons.hbs b/web/templates/compose_control_buttons.hbsindex 2f61e799259..f1c59022670 100644--- a/web/templates/compose_control_buttons.hbs+++ b/web/templates/compose_control_buttons.hbs@@ -25,7 +25,7 @@<a role="button" class="compose_control_button zulip-icon zulip-icon-time time_pick" aria-label="{{t 'Add global time' }}" tabindex=0></a></div><div class="compose_control_button_container {{#unless giphy_enabled }}hide{{/unless}} preview_mode_disabled compose_button_tooltip" data-tippy-content="{{t 'Add GIF' }}">- <a role="button" class="compose_control_button compose_gif_icon zulip-icon zulip-icon-gif" aria-label="{{t 'Add GIF' }}" tabindex=0></a>+ <a role="button" class="compose_control_button compose-gif-icon-giphy zulip-icon zulip-icon-gif" aria-label="{{t 'Add GIF' }}" tabindex=0></a></div>{{#if message_id}}<div class="compose_control_button_container preview_mode_disabled compose_button_tooltip" data-tooltip-template-id="add-saved-snippet-tooltip">diff --git a/web/templates/giphy_picker.hbs b/web/templates/gif_picker_ui.hbssimilarity index 65%rename from web/templates/giphy_picker.hbsrename to web/templates/gif_picker_ui.hbsindex 18ab6f2fbe5..2aeed150a95 100644--- a/web/templates/giphy_picker.hbs+++ b/web/templates/gif_picker_ui.hbs@@ -1,10 +1,10 @@-<div id="giphy_grid_in_popover">+<div class="gif-grid-in-popover"><div class="arrow"></div><div class="popover-inner"><div class="popover-filter-input-wrapper">- <input type="text" id="giphy-search-query" class="popover-filter-input filter_text_input" autocomplete="off" placeholder="{{t 'Filter' }}" autofocus/>+ <input type="text" id="gif-search-query" class="popover-filter-input filter_text_input" autocomplete="off" placeholder="{{t 'Filter' }}" autofocus/></div>- <div class="giphy-scrolling-container" data-simplebar data-simplebar-tab-index="-1">+ <div class="gif-scrolling-container" data-simplebar data-simplebar-tab-index="-1">{{! We need a container we can replacewithout removing the simplebar wrappers.We replace the `giphy-content` when