2022-10-12 20:06:11 +08:00
|
|
|
(rl => {
|
2022-10-21 18:17:49 +08:00
|
|
|
// if (rl.settings.get('Nextcloud'))
|
2022-10-14 19:48:37 +08:00
|
|
|
|
2022-10-13 00:45:26 +08:00
|
|
|
addEventListener('rl-view-model.create', e => {
|
|
|
|
if ('MailMessageView' === e.detail.viewModelTemplateID) {
|
|
|
|
let view = e.detail;
|
|
|
|
view.saveNextcloudError = ko.observable(false).extend({ falseTimeout: 7000 });
|
|
|
|
view.saveNextcloudLoading = ko.observable(false);
|
|
|
|
view.saveNextcloud = () => {
|
|
|
|
const
|
|
|
|
hashes = (view.message()?.attachments || [])
|
|
|
|
.map(item => item?.checked() /*&& !item?.isLinked()*/ ? item.download : '')
|
|
|
|
.filter(v => v);
|
|
|
|
if (hashes.length) {
|
2022-10-13 00:49:09 +08:00
|
|
|
view.saveNextcloudLoading(true);
|
2022-10-25 22:08:28 +08:00
|
|
|
rl.nextcloud.selectFolder().then(folder => {
|
2022-10-19 16:15:03 +08:00
|
|
|
if (folder) {
|
|
|
|
rl.fetchJSON('./?/Json/&q[]=/0/', {}, {
|
|
|
|
Action: 'AttachmentsActions',
|
|
|
|
Do: 'nextcloud',
|
|
|
|
Hashes: hashes,
|
|
|
|
NcFolder: folder
|
|
|
|
})
|
|
|
|
.then(result => {
|
|
|
|
view.saveNextcloudLoading(false);
|
|
|
|
if (result?.Result) {
|
|
|
|
// success
|
|
|
|
} else {
|
|
|
|
view.saveNextcloudError(true);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
view.saveNextcloudLoading(false);
|
|
|
|
view.saveNextcloudError(true);
|
|
|
|
});
|
2022-10-20 22:38:18 +08:00
|
|
|
} else {
|
|
|
|
view.saveNextcloudLoading(false);
|
2022-10-13 00:45:26 +08:00
|
|
|
}
|
2022-10-13 00:49:09 +08:00
|
|
|
});
|
2022-10-13 00:45:26 +08:00
|
|
|
}
|
|
|
|
};
|
2022-10-13 20:07:04 +08:00
|
|
|
|
|
|
|
view.nextcloudSaveMsg = () => {
|
2022-10-25 22:08:28 +08:00
|
|
|
rl.nextcloud.selectFolder().then(folder => {
|
2022-10-19 16:15:03 +08:00
|
|
|
let msg = view.message();
|
|
|
|
folder && rl.pluginRemoteRequest(
|
|
|
|
(iError, data) => {
|
|
|
|
console.dir({
|
|
|
|
iError:iError,
|
|
|
|
data:data
|
|
|
|
});
|
|
|
|
},
|
|
|
|
'NextcloudSaveMsg',
|
|
|
|
{
|
|
|
|
'msgHash': msg.requestHash,
|
|
|
|
'folder': folder,
|
|
|
|
'filename': msg.subject()
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
2022-10-13 20:07:04 +08:00
|
|
|
};
|
2022-10-25 22:08:28 +08:00
|
|
|
|
|
|
|
view.nextcloudICS = ko.computed(() => {
|
|
|
|
let msg = view.message();
|
|
|
|
return msg
|
|
|
|
? msg.attachments.find(attachment => 'text/calendar' == attachment.mimeType)
|
|
|
|
: null;
|
|
|
|
}, {'pure':true});
|
|
|
|
|
|
|
|
view.nextcloudSaveICS = () => {
|
|
|
|
let attachment = view.nextcloudICS();
|
|
|
|
attachment && rl.nextcloud.selectCalendar().then(href => {
|
2022-10-28 15:45:11 +08:00
|
|
|
if (href) {
|
|
|
|
fetch(attachment.linkDownload(), {
|
|
|
|
mode: 'same-origin',
|
|
|
|
cache: 'no-cache',
|
|
|
|
redirect: 'error',
|
|
|
|
credentials: 'same-origin'
|
|
|
|
})
|
|
|
|
.then(response => (response.status < 400) ? response.text() : Promise.reject(new Error({ response })))
|
|
|
|
.then(text => rl.nextcloud.calendarPut(href, text));
|
|
|
|
}
|
2022-10-25 22:08:28 +08:00
|
|
|
});
|
|
|
|
}
|
2022-10-12 20:06:11 +08:00
|
|
|
}
|
2022-10-13 00:45:26 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
let template = document.getElementById('MailMessageView');
|
2022-10-13 20:07:04 +08:00
|
|
|
|
2022-10-13 00:45:26 +08:00
|
|
|
const attachmentsControls = template.content.querySelector('.attachmentsControls');
|
|
|
|
if (attachmentsControls) {
|
|
|
|
attachmentsControls.append(Element.fromHTML('<span>'
|
|
|
|
+ '<i class="fontastic iconcolor-red" data-bind="visible: saveNextcloudError">✖</i>'
|
|
|
|
+ '<i class="fontastic" data-bind="visible: !saveNextcloudError(), css: {\'icon-spinner\': saveNextcloudLoading()}">💾</i>'
|
2022-10-13 20:07:04 +08:00
|
|
|
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS"></span>'
|
2022-10-13 00:45:26 +08:00
|
|
|
+ '</span>'));
|
2022-10-25 22:08:28 +08:00
|
|
|
|
|
|
|
// https://github.com/nextcloud/calendar/issues/4684
|
2022-10-25 23:06:00 +08:00
|
|
|
let cfg = rl.settings.get('Nextcloud');
|
|
|
|
if (cfg.CalDAV) {
|
|
|
|
attachmentsControls.append(Element.fromHTML('<span data-bind="visible: nextcloudICS" data-icon="📅">'
|
|
|
|
+ '<span class="g-ui-link" data-bind="click: nextcloudSaveICS" data-i18n="NEXTCLOUD/SAVE_ICS"></span>'
|
|
|
|
+ '</span>'));
|
|
|
|
}
|
2022-10-12 20:06:11 +08:00
|
|
|
}
|
2022-10-13 02:14:30 +08:00
|
|
|
|
2022-10-13 20:07:04 +08:00
|
|
|
const msgMenu = template.content.querySelector('#more-view-dropdown-id + menu');
|
|
|
|
if (msgMenu) {
|
|
|
|
msgMenu.append(Element.fromHTML('<li role="presentation">'
|
|
|
|
+ '<a href="#" tabindex="-1" data-icon="📥" data-bind="click: nextcloudSaveMsg" data-i18n="NEXTCLOUD/SAVE_EML"></a>'
|
|
|
|
+ '</li>'));
|
|
|
|
}
|
2022-10-13 02:14:30 +08:00
|
|
|
|
2022-10-12 20:06:11 +08:00
|
|
|
})(window.rl);
|