Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose_call_ui: Extract XHR success and error callbacks.

apoorvapendsefdc5fa2b39cf
diff --git a/web/src/compose_call_ui.ts b/web/src/compose_call_ui.ts
index a843315fd59..22db63d7a0c 100644
--- a/web/src/compose_call_ui.ts
+++ b/web/src/compose_call_ui.ts
@@ -70,49 +70,52 @@ export function generate_and_insert_audio_or_video_call_link(
is_video_call: !is_audio_call,
};
+ const handle_success = (res: unknown): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ const data = call_response_schema.parse(res);
+ if (is_audio_call) {
+ insert_audio_call_url(data.url, $target_textarea);
+ } else {
+ insert_video_call_url(data.url, $target_textarea);
+ }
+ };
+
+ const handle_error = (
+ _xhr: JQuery.jqXHR<unknown>,
+ status: JQuery.Ajax.ErrorTextStatus,
+ ): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ const parsed = z.object({code: z.string()}).safeParse(_xhr.responseJSON);
+ if (
+ status === "error" &&
+ parsed.success &&
+ parsed.data.code === "INVALID_VIDEO_CALL_PROVIDER_TOKEN"
+ ) {
+ if (oauth_call_provider === "webex") {
+ current_user.has_webex_token = false;
+ } else {
+ current_user.has_zoom_token = false;
+ }
+ }
+ if (status === "error" && parsed.success && parsed.data.code === "UNKNOWN_ZOOM_USER") {
+ compose_banner.show_unknown_zoom_user_error(current_user.delivery_email);
+ } else if (status !== "abort") {
+ ui_report.generic_embed_error(
+ $t_html({defaultMessage: "Failed to create video call."}),
+ );
+ }
+ };
+
const make_oauth_call = (from_token_callback?: boolean): void => {
xhr = channel.post({
url: `/json/calls/${oauth_call_provider}/create`,
data: request,
- success(res) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- const data = call_response_schema.parse(res);
- if (is_audio_call) {
- insert_audio_call_url(data.url, $target_textarea);
- } else {
- insert_video_call_url(data.url, $target_textarea);
- }
- },
- error(_xhr, status) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- const parsed = z.object({code: z.string()}).safeParse(_xhr.responseJSON);
- if (
- status === "error" &&
- parsed.success &&
- parsed.data.code === "INVALID_VIDEO_CALL_PROVIDER_TOKEN"
- ) {
- if (oauth_call_provider === "webex") {
- current_user.has_webex_token = false;
- } else {
- current_user.has_zoom_token = false;
- }
- }
- if (
- status === "error" &&
- parsed.success &&
- parsed.data.code === "UNKNOWN_ZOOM_USER"
- ) {
- compose_banner.show_unknown_zoom_user_error(current_user.delivery_email);
- } else if (status !== "abort") {
- ui_report.generic_embed_error(
- $t_html({defaultMessage: "Failed to create video call."}),
- );
- }
- },
+ success: handle_success,
+ error: handle_error,
});
if (xhr && from_token_callback) {
compose_call.track_xhr_for_key(key, xhr);
@@ -146,46 +149,56 @@ export function generate_and_insert_audio_or_video_call_link(
meeting_name,
voice_only: is_audio_call,
};
+
+ const handle_success = (response: unknown): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ const data = call_response_schema.parse(response);
+ if (is_audio_call) {
+ insert_audio_call_url(data.url, $target_textarea);
+ } else {
+ insert_video_call_url(data.url, $target_textarea);
+ }
+ };
+
xhr = channel.get({
url: "/json/calls/bigbluebutton/create",
data: request,
- success(response) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- const data = call_response_schema.parse(response);
- if (is_audio_call) {
- insert_audio_call_url(data.url, $target_textarea);
- } else {
- insert_video_call_url(data.url, $target_textarea);
- }
- },
+ success: handle_success,
});
break;
}
case available_providers.constructor_groups?.id: {
+ const handle_success = (response: unknown): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ const data = call_response_schema.parse(response);
+ insert_video_call_url(data.url, $target_textarea);
+ };
+
+ const handle_error = (
+ _xhr: JQuery.jqXHR<unknown>,
+ status: JQuery.Ajax.ErrorTextStatus,
+ ): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ if (status !== "abort") {
+ ui_report.generic_embed_error(
+ $t_html({defaultMessage: "Failed to create video call."}),
+ 2000,
+ );
+ }
+ };
+
xhr = channel.post({
url: "/json/calls/constructorgroups/create",
data: {},
- success(response) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- const data = call_response_schema.parse(response);
- insert_video_call_url(data.url, $target_textarea);
- },
- error(_xhr, status) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- if (status !== "abort") {
- ui_report.generic_embed_error(
- $t_html({defaultMessage: "Failed to create video call."}),
- 2000,
- );
- }
- },
+ success: handle_success,
+ error: handle_error,
});
break;
}
@@ -193,27 +206,34 @@ export function generate_and_insert_audio_or_video_call_link(
const room_name = `${get_recipient_label()?.label_text ?? ""} conversation`;
const request = {room_name};
+ const handle_success = (response: unknown): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ const data = call_response_schema.parse(response);
+ insert_video_call_url(data.url, $target_textarea);
+ };
+
+ const handle_error = (
+ _xhr: JQuery.jqXHR<unknown>,
+ status: JQuery.Ajax.ErrorTextStatus,
+ ): void => {
+ if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
+ return;
+ }
+ if (status !== "abort") {
+ ui_report.generic_embed_error(
+ $t_html({defaultMessage: "Failed to create video call."}),
+ 2000,
+ );
+ }
+ };
+
xhr = channel.post({
url: "/json/calls/nextcloud_talk/create",
data: request,
- success(response) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- const data = call_response_schema.parse(response);
- insert_video_call_url(data.url, $target_textarea);
- },
- error(_, status) {
- if (xhr && compose_call.ignored_call_xhrs.has(xhr)) {
- return;
- }
- if (status !== "abort") {
- ui_report.generic_embed_error(
- $t_html({defaultMessage: "Failed to create video call."}),
- 2000,
- );
- }
- },
+ success: handle_success,
+ error: handle_error,
});
break;