add copy function
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
var ChatActions = {
|
||||
message: null,
|
||||
forwardError: null,
|
||||
copyError: null,
|
||||
// OMEMO messages of the open conversation: {jid, entries: [[mid, id, messageid, published]], bodies}
|
||||
index: null,
|
||||
keywords: '',
|
||||
@@ -8,13 +9,31 @@ var ChatActions = {
|
||||
setMessage: function (message) {
|
||||
ChatActions.message = message;
|
||||
},
|
||||
initMessageDialog: function (forwardError) {
|
||||
initMessageDialog: function (forwardError, copyError) {
|
||||
ChatActions.forwardError = forwardError;
|
||||
ChatActions.copyError = copyError;
|
||||
|
||||
// The system share sheet (mostly on mobile), to send to other apps
|
||||
if (navigator.share) {
|
||||
document.querySelector('#chat_actions li.share')?.classList.remove('hide');
|
||||
}
|
||||
|
||||
ChatActions.fillPreview();
|
||||
},
|
||||
// The server cannot read an OMEMO message, the preview shows its
|
||||
// decrypted text from this browser, like in the discussion
|
||||
fillPreview: async function () {
|
||||
let p = document.querySelector('#message_preview p.encrypted[data-mid]');
|
||||
if (!p || !ChatActions.message?.encrypted || ChatActions.message.retracted) return;
|
||||
|
||||
let text = await ChatActions.messageText();
|
||||
// Another dialog meanwhile
|
||||
if (!text || !p.isConnected) return;
|
||||
|
||||
if (typeof ChatOmemo == 'undefined' || !ChatOmemo.renderEncryptedFile(p, text)) {
|
||||
p.innerHTML = MovimUtils.linkify(MovimUtils.htmlEscape(text));
|
||||
}
|
||||
p.classList.remove('encrypted');
|
||||
},
|
||||
|
||||
// The text of the message, decrypted by this browser for OMEMO
|
||||
@@ -33,6 +52,24 @@ var ChatActions = {
|
||||
return text.trim() ? text : null;
|
||||
},
|
||||
|
||||
// Copy the text, decrypted for OMEMO. The link of an encrypted file
|
||||
// carries its key, it is never put in the clipboard.
|
||||
copy: async function () {
|
||||
let text = await ChatActions.messageText();
|
||||
if (!text || (typeof AESGCM_REGEX != 'undefined' && AESGCM_REGEX.test(text.trim()))) {
|
||||
Toast.send(ChatActions.copyError);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
ChatActions_ajaxCopiedMessageText();
|
||||
} catch (e) {
|
||||
MovimUtils.logError(e);
|
||||
Toast.send(ChatActions.copyError);
|
||||
}
|
||||
},
|
||||
|
||||
filterForward: function (keyword) {
|
||||
let words = ChatActions.normalize(keyword).split(/\s+/).filter(w => w);
|
||||
document.querySelectorAll('#forward_targets li').forEach(li => {
|
||||
|
||||
Reference in New Issue
Block a user