edit: Add support for using video call link in message edit.

This code will correctly add video call link to the message
textarea based on whether 'Add video call' was selected from
message composition form or message edit form.

The implementation was semi-rewritten by tabbott to remove an
unnecessary global variable, with fixes for the unit tests from
showell.

Fixes #11188.
This commit is contained in:
Abhinav Singh
2019-01-23 12:34:53 +05:30
committed by Tim Abbott
parent 954a98b49f
commit e7c8077abc
4 changed files with 32 additions and 16 deletions

View File

@@ -688,9 +688,9 @@ exports.needs_subscribe_warning = function (email) {
return true;
};
function insert_video_call_url(url) {
function insert_video_call_url(url, target_textarea) {
var video_call_link_text = '[' + _('Click to join video call') + '](' + url + ')';
compose_ui.insert_syntax_and_focus(video_call_link_text);
compose_ui.insert_syntax_and_focus(video_call_link_text, target_textarea);
}
exports.initialize = function () {
@@ -933,9 +933,19 @@ exports.initialize = function () {
}
}
$('#compose').on('click', '#video_link', function (e) {
$('body').on('click', '.video_link', function (e) {
e.preventDefault();
var target_textarea;
// The data-message-id atribute is only present in the video
// call icon present in the message edit form. If present,
// the request is for the edit UI; otherwise, it's for the
// compose box.
var edit_message_id = $(e.target).attr('data-message-id');
if (edit_message_id !== undefined) {
target_textarea = $("#message_edit_content_" + edit_message_id);
}
if (page_params.jitsi_server_url === null) {
return;
}
@@ -944,17 +954,17 @@ exports.initialize = function () {
var video_call_id = util.random_int(100000000000000, 999999999999999);
if (page_params.realm_video_chat_provider === "Google Hangouts") {
video_call_link = "https://hangouts.google.com/hangouts/_/" + page_params.realm_google_hangouts_domain + "/" + video_call_id;
insert_video_call_url(video_call_link);
insert_video_call_url(video_call_link, target_textarea);
} else if (page_params.realm_video_chat_provider === "Zoom") {
channel.get({
url: '/json/calls/create',
success: function (response) {
insert_video_call_url(response.zoom_url);
insert_video_call_url(response.zoom_url, target_textarea);
},
});
} else {
video_call_link = page_params.jitsi_server_url + "/" + video_call_id;
insert_video_call_url(video_call_link);
insert_video_call_url(video_call_link, target_textarea);
}
});