Skip to content

Commit

Permalink
feature(Felamimail/js): allow empty subfolders for all imap folder
Browse files Browse the repository at this point in the history
  • Loading branch information
ccheng-dev committed Sep 9, 2024
1 parent 618a668 commit df27884
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 13 deletions.
28 changes: 23 additions & 5 deletions tine20/Felamimail/Backend/Cache/Sql/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -394,33 +394,51 @@ public function deleteMessageuidsByFolderId($_msguids, $_folderId)
* @throws Tinebase_Exception_InvalidArgument
*/
public function setMessageTags(Felamimail_Model_MessageFilter $filter, $_flags, $_mode)
{
$iterator = new Tinebase_Record_Iterator([
'iteratable' => $this,
'controller' => $this,
'filter' => $filter,
'options' => [
'limit' => 1000
],
'function' => 'setMessageTagsIteration',
]);
$result = $iterator->iterate($_flags, $_mode);
}

public function setMessageTagsIteration(Tinebase_Record_RecordSet $messages, $_flags, $_mode)
{
$tagIds = array_filter($_flags, function ($flag) { return strlen((string)$flag)=== 40;});
$tags = sizeof($tagIds) > 0 ? Tinebase_Tags::getInstance()->getTagsById($tagIds) : [];


if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
. ' About to ' . $_mode . ' tags for ' . count($messages) . ' messages.');

$filter = new Felamimail_Model_MessageFilter([
['field' => 'id', 'operator' => 'in', 'value' => $messages->getId()]
]);

if ($_mode === 'clear') {
try {
$messages = $this->search($filter);
if (sizeof($tags) === 0) {
$tags = Tinebase_Tags::getInstance()->getMultipleTagsOfRecords($messages);
}

if ($tags) {
Tinebase_Tags::getInstance()->detachTagsFromMultipleRecords($filter, $tags->getId());
}
} catch (Zend_Db_Statement_Exception $zdse) {
throw new Felamimail_Exception('failed to detach tags: ' . print_r($tags, TRUE));
}
}

if ($_mode === 'add') {
foreach ($tags as $tag) {
try {
Tinebase_Tags::getInstance()->attachTagToMultipleRecords($filter, $tag);
} catch (Zend_Db_Statement_Exception $zdse) {
throw new Felamimail_Exception('failed to attach tags: ' . print_r($tag->getId(), TRUE));
}

}
}
}
Expand Down
30 changes: 22 additions & 8 deletions tine20/Felamimail/js/nodeActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ Tine.Felamimail.nodeActions.actionUpdater = function(action, grants, records, is
} else {
const isTrashFolder = (folder.get('globalname') === account.get('trash_folder') || folder.get('localname').match(/^junk$/i)) ?? false;
const isFolderSelectable = folder.get('is_selectable');
const isSystemFolder = folder.get('system_folder');
const isSystemFolder = folder.isSystemFolder();

action.baseAction.setHidden(!folderActions.includes(action.itemId) && !isFolderSelectable);

Expand All @@ -130,7 +130,7 @@ Tine.Felamimail.nodeActions.actionUpdater = function(action, grants, records, is
case 'RefreshFolderAction':
break;
case 'EmptyFolderAction':
action.baseAction.setHidden(!isTrashFolder);
action.baseAction.setHidden((isSystemFolder && !isTrashFolder));
break;
case 'MoveFolderAction':
case 'rename':
Expand All @@ -152,17 +152,31 @@ Tine.Felamimail.nodeActions.EmptyFolderAction = {
scope: this,
handler: async function (action) {
const app = action.app;
const account = action.account;
const folder = action.folder;
const selectedNode = action.node;

try {
if (selectedNode) {
selectedNode.getUI().addClass("x-tree-node-loading");
const result = await Tine.Felamimail.emptyFolder(folder.id);
const folderRecord = Tine.Felamimail.folderBackend.recordReader({responseText: result});
app.getFolderStore().updateFolder(folderRecord);
selectedNode.removeAll();
selectedNode.getUI().removeClass("x-tree-node-loading");
const isTrashFolder = (folder.get('globalname') === account.get('trash_folder') || folder.get('localname').match(/^junk$/i)) ?? false;
if (!isTrashFolder) {
Ext.MessageBox.confirm(
i18n._('Empty folder?'),
i18n._('Do you really want to delete all the messages in this folder?'),
async function (button) {
if (button === 'yes') {
selectedNode.getUI().addClass("x-tree-node-loading");
const result = await Tine.Felamimail.emptyFolder(folder.id);
const folderRecord = Tine.Felamimail.folderBackend.recordReader({responseText: result});
app.getFolderStore().updateFolder(folderRecord);
selectedNode.removeAll();
selectedNode.getUI().removeClass("x-tree-node-loading");
}
},
this
);
}

} else {
folder.set('cache_unreadcount', 0);
}
Expand Down

0 comments on commit df27884

Please sign in to comment.