sharing button
This commit is contained in:
@@ -53,6 +53,11 @@ files_recordings = Recordings
|
|||||||
files_files = Files
|
files_files = Files
|
||||||
files_message = Show the message
|
files_message = Show the message
|
||||||
files_empty = Nothing shared yet
|
files_empty = Nothing shared yet
|
||||||
|
forward = Forward
|
||||||
|
forward_title = Forward to…
|
||||||
|
forward_filter = Search a discussion
|
||||||
|
forward_error = This message cannot be forwarded
|
||||||
|
forward_encrypted_file = This encrypted file can only be sent in an encrypted discussion
|
||||||
|
|
||||||
; Upstream strings still in use, their widgets are not part of this edition
|
; Upstream strings still in use, their widgets are not part of this edition
|
||||||
|
|
||||||
|
|||||||
@@ -3110,3 +3110,18 @@ msgstr "Chọn một mật khẩu tốt"
|
|||||||
|
|
||||||
msgid "Type your password again"
|
msgid "Type your password again"
|
||||||
msgstr "Nhập lại mật khẩu"
|
msgstr "Nhập lại mật khẩu"
|
||||||
|
|
||||||
|
msgid "Forward"
|
||||||
|
msgstr "Chuyển tiếp"
|
||||||
|
|
||||||
|
msgid "Forward to…"
|
||||||
|
msgstr "Chuyển tiếp tới…"
|
||||||
|
|
||||||
|
msgid "Search a discussion"
|
||||||
|
msgstr "Tìm cuộc trò chuyện"
|
||||||
|
|
||||||
|
msgid "This message cannot be forwarded"
|
||||||
|
msgstr "Không thể chuyển tiếp tin nhắn này"
|
||||||
|
|
||||||
|
msgid "This encrypted file can only be sent in an encrypted discussion"
|
||||||
|
msgstr "Tệp mã hóa này chỉ có thể gửi trong cuộc trò chuyện được mã hóa"
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ var Chat = {
|
|||||||
Chat.pagination = config['pagination'];
|
Chat.pagination = config['pagination'];
|
||||||
Chat.delivery_error = config['delivery_error'];
|
Chat.delivery_error = config['delivery_error'];
|
||||||
Chat.action_impossible_encrypted_error = config['action_impossible_encrypted_error'];
|
Chat.action_impossible_encrypted_error = config['action_impossible_encrypted_error'];
|
||||||
|
Chat.encrypted_file_error = config['encrypted_file_error'];
|
||||||
},
|
},
|
||||||
autocomplete: function (event, jid) {
|
autocomplete: function (event, jid) {
|
||||||
RoomsUtils_ajaxMucUsersAutocomplete(jid);
|
RoomsUtils_ajaxMucUsersAutocomplete(jid);
|
||||||
@@ -292,6 +293,13 @@ var Chat = {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// The key of an encrypted file (a forwarded one) must not go in clear
|
||||||
|
if (typeof AESGCM_REGEX != 'undefined' && AESGCM_REGEX.test(text.trim())) {
|
||||||
|
Toast.send(Chat.encrypted_file_error);
|
||||||
|
Chat.disableSending();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Chat.lastSentUUID = id = crypto.randomUUID();
|
Chat.lastSentUUID = id = crypto.randomUUID();
|
||||||
let request = Chat_ajaxHttpDaemonSendMessage(id, jid, text, isMuc, null, replyMid, mucReceipts);
|
let request = Chat_ajaxHttpDaemonSendMessage(id, jid, text, isMuc, null, replyMid, mucReceipts);
|
||||||
request.then(response => {
|
request.then(response => {
|
||||||
@@ -451,6 +459,18 @@ var Chat = {
|
|||||||
Chat.toggleAction();
|
Chat.toggleAction();
|
||||||
|
|
||||||
var textarea = Chat.getTextarea();
|
var textarea = Chat.getTextarea();
|
||||||
|
|
||||||
|
// A decrypted file forwarded to this discussion: through the upload
|
||||||
|
// panel, it is encrypted again if this discussion is encrypted
|
||||||
|
let forwarded = window.movimForwardFile;
|
||||||
|
if (forwarded && forwarded.jid == textarea.dataset.jid
|
||||||
|
&& typeof Upload != 'undefined' && Upload.file == null) {
|
||||||
|
delete window.movimForwardFile;
|
||||||
|
Upload.file = forwarded.file;
|
||||||
|
Upload.name = forwarded.file.name;
|
||||||
|
Upload_ajaxGetPanel();
|
||||||
|
}
|
||||||
|
|
||||||
textarea.onkeydown = function (event) {
|
textarea.onkeydown = function (event) {
|
||||||
if ((event.key == 'ArrowLeft' && Chat.tryPreviousEmoji())
|
if ((event.key == 'ArrowLeft' && Chat.tryPreviousEmoji())
|
||||||
|| (event.key == 'ArrowRight' && Chat.tryNextEmoji())) {
|
|| (event.key == 'ArrowRight' && Chat.tryNextEmoji())) {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
var ChatActions = {
|
var ChatActions = {
|
||||||
message: null,
|
message: null,
|
||||||
|
forwardError: null,
|
||||||
// OMEMO messages of the open conversation: {jid, entries: [[mid, id, messageid, published]], bodies}
|
// OMEMO messages of the open conversation: {jid, entries: [[mid, id, messageid, published]], bodies}
|
||||||
index: null,
|
index: null,
|
||||||
keywords: '',
|
keywords: '',
|
||||||
@@ -7,6 +8,99 @@ var ChatActions = {
|
|||||||
setMessage: function (message) {
|
setMessage: function (message) {
|
||||||
ChatActions.message = message;
|
ChatActions.message = message;
|
||||||
},
|
},
|
||||||
|
initMessageDialog: function (forwardError) {
|
||||||
|
ChatActions.forwardError = forwardError;
|
||||||
|
|
||||||
|
// The system share sheet (mostly on mobile), to send to other apps
|
||||||
|
if (navigator.share) {
|
||||||
|
document.querySelector('#chat_actions li.share')?.classList.remove('hide');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
// The text of the message, decrypted by this browser for OMEMO
|
||||||
|
messageText: async function () {
|
||||||
|
let message = ChatActions.message;
|
||||||
|
if (!message) return null;
|
||||||
|
|
||||||
|
if (message.encrypted) {
|
||||||
|
if (typeof ChatOmemoDB == 'undefined') return null;
|
||||||
|
let text = await ChatOmemoDB.getMessage(message.id);
|
||||||
|
if (typeof text != 'string' && message.messageid) text = await ChatOmemoDB.getMessage(message.messageid);
|
||||||
|
return (typeof text == 'string' && text.trim()) ? text : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let text = MovimUtils.decodeHTMLEntities(message.body ?? '');
|
||||||
|
return text.trim() ? text : null;
|
||||||
|
},
|
||||||
|
|
||||||
|
filterForward: function (keyword) {
|
||||||
|
let words = ChatActions.normalize(keyword).split(/\s+/).filter(w => w);
|
||||||
|
document.querySelectorAll('#forward_targets li').forEach(li => {
|
||||||
|
let haystack = ChatActions.normalize(li.dataset.filter);
|
||||||
|
li.classList.toggle('hide', !words.every(w => haystack.includes(w)));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
// Put the message in the draft of the other discussion and open it, the
|
||||||
|
// user can review it and send it as usual (encrypted if enabled there)
|
||||||
|
forwardTo: async function (jid, muc) {
|
||||||
|
let text = await ChatActions.messageText();
|
||||||
|
if (!text) {
|
||||||
|
Toast.send(ChatActions.forwardError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof AESGCM_REGEX != 'undefined' && AESGCM_REGEX.test(text.trim())) {
|
||||||
|
// An encrypted file: decrypted here and uploaded again from the
|
||||||
|
// other discussion, encrypted with a new key only if it is
|
||||||
|
// encrypted. Kept on window, the widget scripts are reloaded.
|
||||||
|
try {
|
||||||
|
window.movimForwardFile = { jid: jid, file: await ChatActions.decryptedFile(text.trim()) };
|
||||||
|
} catch (e) {
|
||||||
|
console.error(e);
|
||||||
|
Toast.send(ChatActions.forwardError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
localStorage.setItem(jid + '_message', text);
|
||||||
|
}
|
||||||
|
|
||||||
|
Dialog_ajaxClear();
|
||||||
|
ChatActions_ajaxForwardTo(jid, muc);
|
||||||
|
},
|
||||||
|
|
||||||
|
decryptedFile: async function (url) {
|
||||||
|
let [, , filename] = url.match(AESGCM_REGEX);
|
||||||
|
let blob = await (await fetch(await ChatOmemo.decryptFile(url))).blob();
|
||||||
|
return new File([blob], filename, { type: blob.type });
|
||||||
|
},
|
||||||
|
|
||||||
|
share: async function () {
|
||||||
|
let text = await ChatActions.messageText();
|
||||||
|
if (!text || !navigator.share) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
let url = text.trim();
|
||||||
|
if (typeof AESGCM_REGEX != 'undefined' && AESGCM_REGEX.test(url)) {
|
||||||
|
// An encrypted file: share the decrypted file, never the key
|
||||||
|
let file = await ChatActions.decryptedFile(url);
|
||||||
|
|
||||||
|
if (!navigator.canShare || !navigator.canShare({ files: [file] })) {
|
||||||
|
Toast.send(ChatActions.forwardError);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await navigator.share({ files: [file] });
|
||||||
|
} else if (/^https?:\/\/\S+$/.test(url)) {
|
||||||
|
await navigator.share({ url: url });
|
||||||
|
} else {
|
||||||
|
await navigator.share({ text: text });
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
// Cancelled by the user
|
||||||
|
if (e.name != 'AbortError') Toast.send(ChatActions.forwardError);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
focusSearch: function () {
|
focusSearch: function () {
|
||||||
document.querySelector('form[name=search] input').focus();
|
document.querySelector('form[name=search] input').focus();
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -31,6 +31,7 @@ pub async fn call(ctx: &Ctx, func: &str, p: &P<'_>) -> bool {
|
|||||||
"pagination": PAGINATION,
|
"pagination": PAGINATION,
|
||||||
"delivery_error": ctx.t("message.error", &[]),
|
"delivery_error": ctx.t("message.error", &[]),
|
||||||
"action_impossible_encrypted_error": ctx.t("chat.action_impossible_encrypted", &[]),
|
"action_impossible_encrypted_error": ctx.t("chat.action_impossible_encrypted", &[]),
|
||||||
|
"encrypted_file_error": ctx.t("chatactions.forward_encrypted_file", &[]),
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
//! ChatActions widget: actions on a message (react, copy, reply, edit,
|
//! ChatActions widget: actions on a message (react, copy, reply, forward,
|
||||||
//! retract, moderate), search in a discussion, shared files, URL previews.
|
//! share, edit, retract, moderate), search in a discussion, shared files, URL previews.
|
||||||
|
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
@@ -30,6 +30,8 @@ pub async fn call(ctx: &Ctx, func: &str, p: &P<'_>) -> bool {
|
|||||||
search(ctx, &p.str(0), &p.str(1), p.b(2), &encrypted).await;
|
search(ctx, &p.str(0), &p.str(1), p.b(2), &encrypted).await;
|
||||||
}
|
}
|
||||||
"ajaxShowFiles" => show_files(ctx, &p.str(0), p.b(1)).await,
|
"ajaxShowFiles" => show_files(ctx, &p.str(0), p.b(1)).await,
|
||||||
|
"ajaxShowForwardDialog" => show_forward_dialog(ctx).await,
|
||||||
|
"ajaxForwardTo" => super::search::chat(ctx, &p.str(0), p.b(1)).await,
|
||||||
"ajaxCopiedMessageText" => ctx.toast(&ctx.t("chatactions.copied_text", &[])),
|
"ajaxCopiedMessageText" => ctx.toast(&ctx.t("chatactions.copied_text", &[])),
|
||||||
"ajaxHttpDaemonRetract" => retract(ctx, p.i(0).unwrap_or(0)).await,
|
"ajaxHttpDaemonRetract" => retract(ctx, p.i(0).unwrap_or(0)).await,
|
||||||
"ajaxHttpDaemonModerate" => moderate(ctx, p.i(0).unwrap_or(0)).await,
|
"ajaxHttpDaemonModerate" => moderate(ctx, p.i(0).unwrap_or(0)).await,
|
||||||
@@ -119,6 +121,39 @@ async fn show_message_dialog(ctx: &Ctx, mid: i64) {
|
|||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
super::dialog(ctx, &html, false, false);
|
super::dialog(ctx, &html, false, false);
|
||||||
|
rpc!(ctx, "ChatActions.initMessageDialog", ctx.t("chatactions.forward_error", &[]));
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Where to forward a message: the open discussions (most recent first),
|
||||||
|
/// the bookmarked rooms, then the rest of the roster. The browser fills the
|
||||||
|
/// draft of the chosen discussion and opens it, the normal sending (with
|
||||||
|
/// OMEMO when enabled there) does the rest.
|
||||||
|
async fn show_forward_dialog(ctx: &Ctx) {
|
||||||
|
let me = ctx.jid();
|
||||||
|
let mut open = db::open_chats(ctx.db(), &me).await.unwrap_or_default();
|
||||||
|
open.reverse();
|
||||||
|
open.retain(|j| *j != me);
|
||||||
|
|
||||||
|
let mut roster: Vec<String> = ctx.st(|st| st.roster.keys().filter(|j| !open.contains(j)).cloned().collect()).unwrap_or_default();
|
||||||
|
let views = super::contact_views(ctx, &[open.clone(), roster.clone()].concat()).await;
|
||||||
|
roster.sort_by_key(|j| views.get(j).map(|v| v.truename.to_lowercase()).unwrap_or_default());
|
||||||
|
|
||||||
|
let contact = |jid: &String| {
|
||||||
|
views.get(jid).map(|c| json!({ "jid": c.jid, "name": c.truename, "picture": c.picture, "muc": false }))
|
||||||
|
};
|
||||||
|
|
||||||
|
let mut rooms: Vec<_> = ctx
|
||||||
|
.st(|st| st.conferences.values().cloned().collect::<Vec<_>>())
|
||||||
|
.unwrap_or_default()
|
||||||
|
.into_iter()
|
||||||
|
.map(|c| json!({ "jid": c.jid, "name": c.title(), "picture": rooms::room_picture(ctx, &c), "muc": true }))
|
||||||
|
.collect();
|
||||||
|
rooms.sort_by_key(|r| r["name"].as_str().unwrap_or("").to_lowercase());
|
||||||
|
|
||||||
|
let targets: Vec<_> = open.iter().filter_map(contact).chain(rooms).chain(roster.iter().filter_map(contact)).collect();
|
||||||
|
|
||||||
|
let html = ctx.render("ChatActions/_chatactions_forward.html", json!({ "targets": targets }));
|
||||||
|
super::dialog(ctx, &html, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The browser searches and lists the OMEMO messages itself (the server
|
/// The browser searches and lists the OMEMO messages itself (the server
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<section id="chat_forward">
|
||||||
|
<h3>{{ __('chatactions.forward_title') }}</h3>
|
||||||
|
<ul class="list">
|
||||||
|
<li class="search">
|
||||||
|
<form name="forward" onsubmit="return false;">
|
||||||
|
<div>
|
||||||
|
<input name="keyword" autocomplete="off" type="text"
|
||||||
|
placeholder="{{ __('chatactions.forward_filter') }}"
|
||||||
|
oninput="ChatActions.filterForward(this.value)">
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
<ul class="list active thin" id="forward_targets">
|
||||||
|
{% for t in targets %}
|
||||||
|
<li data-filter="{{ t.name|lower }} {{ t.jid|lower }}"
|
||||||
|
onclick="ChatActions.forwardTo('{{ t.jid|echapJS }}', {% if t.muc %}true{% else %}false{% endif %})">
|
||||||
|
<span class="primary icon bubble small">
|
||||||
|
<img alt="" src="{{ t.picture }}">
|
||||||
|
</span>
|
||||||
|
{% if t.muc %}
|
||||||
|
<span class="control icon gray">
|
||||||
|
<i class="material-symbols">forum</i>
|
||||||
|
</span>
|
||||||
|
{% endif %}
|
||||||
|
<div>
|
||||||
|
<p class="line">{{ t.name }}</p>
|
||||||
|
<p class="line">{{ t.jid }}</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
{% endfor %}
|
||||||
|
</ul>
|
||||||
|
</section>
|
||||||
|
<footer>
|
||||||
|
<button onclick="Dialog_ajaxClear()" class="button flat">
|
||||||
|
{{ __('button.cancel') }}
|
||||||
|
</button>
|
||||||
|
</footer>
|
||||||
@@ -38,6 +38,23 @@
|
|||||||
</div>
|
</div>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<li onclick="ChatActions_ajaxShowForwardDialog()">
|
||||||
|
<span class="primary icon gray">
|
||||||
|
<i class="material-symbols">forward</i>
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<p>{{ __('chatactions.forward') }}</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
<li class="share hide" onclick="ChatActions.share(); Dialog_ajaxClear()">
|
||||||
|
<span class="primary icon gray">
|
||||||
|
<i class="material-symbols">share</i>
|
||||||
|
</span>
|
||||||
|
<div>
|
||||||
|
<p>{{ __('button.share') }}</p>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
|
|
||||||
{% if editable %}
|
{% if editable %}
|
||||||
<li onclick="Chat_ajaxEdit({{ message.mid }}); Dialog_ajaxClear();">
|
<li onclick="Chat_ajaxEdit({{ message.mid }}); Dialog_ajaxClear();">
|
||||||
<span class="primary icon gray">
|
<span class="primary icon gray">
|
||||||
|
|||||||
Reference in New Issue
Block a user