mirror of
https://github.com/the-djmaze/snappymail.git
synced 2026-06-29 07:16:07 +00:00
Improved Nextcloud integration #96
This commit is contained in:
@@ -49,3 +49,11 @@
|
||||
background-image: linear-gradient(to bottom, #f4f4f4, #dfdfdf) !important;
|
||||
background-repeat: repeat-x !important;
|
||||
}
|
||||
#V-AdminPane > .b-toolbar {
|
||||
background-color: #0082c9;
|
||||
background-image: linear-gradient(40deg, #0082c9 0%, #30b6ff 100%);
|
||||
color: #fff;
|
||||
}
|
||||
#V-AdminPane > .b-toolbar h4::before {
|
||||
content: 'Nextcloud: ';
|
||||
}
|
||||
|
||||
@@ -7,16 +7,18 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
VERSION = '2.1',
|
||||
RELEASE = '2022-10-10',
|
||||
CATEGORY = 'Integrations',
|
||||
DESCRIPTION = 'Integrate with Nextcloud v18+',
|
||||
REQUIRED = '2.15.2';
|
||||
DESCRIPTION = 'Integrate with Nextcloud v20+',
|
||||
REQUIRED = '2.18.6';
|
||||
|
||||
public function Init() : void
|
||||
{
|
||||
if (static::IsIntegrated()) {
|
||||
$this->UseLangs(true);
|
||||
|
||||
$this->addHook('main.fabrica', 'MainFabrica');
|
||||
$this->addHook('filter.app-data', 'FilterAppData');
|
||||
$this->addHook('json.attachments', 'DoAttachmentsActions');
|
||||
|
||||
$this->addHook('json.attachments', 'DoAttachmentsActions');
|
||||
$this->addJs('js/attachments.js');
|
||||
}
|
||||
}
|
||||
@@ -36,11 +38,33 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
return static::IsIntegrated() && \OC::$server->getUserSession()->isLoggedIn();
|
||||
}
|
||||
|
||||
/*
|
||||
$sUID = \OC::$server->getUserSession()->getUser()->getUID();
|
||||
WebDAV /nextcloud/remote.php/dav/files/$sUID/
|
||||
\OCP\Util::linkToRemote('files');
|
||||
|
||||
\OC::$server->getCalendarManager();
|
||||
\OC::$server->getLDAPProvider();
|
||||
\OC::$server->getAppDataDir('snappymail'); ??
|
||||
|
||||
$oFiles = \OCP\Files::getStorage('files');
|
||||
if ($oFiles and $oFiles->is_dir('/')) {
|
||||
$dh = $oFiles->opendir('/');
|
||||
if (\is_resource($dh)) {
|
||||
while (($file = \readdir($dh)) !== false) {
|
||||
if ($file != '.' && $file != '..') {
|
||||
// DO THINGS
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
public function DoAttachmentsActions(\SnappyMail\AttachmentsAction $data)
|
||||
{
|
||||
if ('nextcloud' === $data->action) {
|
||||
if (static::isLoggedIn() && 'nextcloud' === $data->action) {
|
||||
$oFiles = \OCP\Files::getStorage('files');
|
||||
if ($oFiles && $data->filesProvider->IsActive() && \method_exists($oFiles, 'file_put_contents')) {
|
||||
if ($oFiles && \method_exists($oFiles, 'file_put_contents')) {
|
||||
$sSaveFolder = $this->Config()->Get('plugin', 'save_folder', '') ?: 'Attachments';
|
||||
$oFiles->is_dir($sSaveFolder) || $oFiles->mkdir($sSaveFolder);
|
||||
$data->result = true;
|
||||
@@ -77,14 +101,11 @@ class NextcloudPlugin extends \RainLoop\Plugins\AbstractPlugin
|
||||
|
||||
public function FilterAppData($bAdmin, &$aResult) : void
|
||||
{
|
||||
if (!$bAdmin && \is_array($aResult) && static::IsIntegrated()) {
|
||||
if (!$bAdmin && \is_array($aResult)) {
|
||||
$key = \array_search(\RainLoop\Enumerations\Capa::AUTOLOGOUT, $aResult['Capa']);
|
||||
if (false !== $key) {
|
||||
unset($aResult['Capa'][$key]);
|
||||
}
|
||||
if (static::IsLoggedIn() && \class_exists('OCP\Files')) {
|
||||
$aResult['System']['attachmentsActions'][] = 'nextcloud';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,43 +1,40 @@
|
||||
(rl => {
|
||||
if (rl) {
|
||||
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) {
|
||||
rl.fetchJSON('./?/Json/&q[]=/0/', {}, {
|
||||
Action: 'AttachmentsActions',
|
||||
Do: 'nextcloud',
|
||||
Hashes: hashes
|
||||
})
|
||||
.then(result => {
|
||||
if (result?.Result) {
|
||||
// success
|
||||
} else {
|
||||
view.saveNextcloudError(true);
|
||||
}
|
||||
})
|
||||
.catch(() => view.saveNextcloudError(true));
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let template = document.getElementById('MailMessageView');
|
||||
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="icon-file-archive" data-bind="visible: !saveNextcloudError(), css: {\'icon-file-archive\': !saveNextcloudLoading(), \'icon-spinner\': saveNextcloudLoading()}"></i>'
|
||||
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS">Save Nextcloud</span>'
|
||||
+ '</span>'));
|
||||
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) {
|
||||
rl.fetchJSON('./?/Json/&q[]=/0/', {}, {
|
||||
Action: 'AttachmentsActions',
|
||||
Do: 'nextcloud',
|
||||
Hashes: hashes
|
||||
})
|
||||
.then(result => {
|
||||
if (result?.Result) {
|
||||
// success
|
||||
} else {
|
||||
view.saveNextcloudError(true);
|
||||
}
|
||||
})
|
||||
.catch(() => view.saveNextcloudError(true));
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let template = document.getElementById('MailMessageView');
|
||||
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>'
|
||||
+ '<span class="g-ui-link" data-bind="click: saveNextcloud" data-i18n="NEXTCLOUD/SAVE_ATTACHMENTS">Save Nextcloud</span>'
|
||||
+ '</span>'));
|
||||
}
|
||||
})(window.rl);
|
||||
|
||||
Reference in New Issue
Block a user