Skip to content

Commit

Permalink
fixup! feat: delete tags
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <[email protected]>
  • Loading branch information
hamza221 committed Oct 2, 2023
1 parent 90966b4 commit 7d3a707
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 41 deletions.
5 changes: 0 additions & 5 deletions lib/Contracts/IMailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,6 @@ public function updateTag(int $id, string $displayName, string $color, string $u
/**
* Delete a mail tag
*
* @param int $id
* @param string $userId
* @param Account $account
*
* @return Tag
* @throws ClientException
*/
public function deleteTag(int $id, string $userId, Account $account): Tag;
Expand Down
3 changes: 0 additions & 3 deletions lib/Controller/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ public function update(int $id, string $displayName, string $color): JSONRespons
/**
* @NoAdminRequired
*
* @param int $id
*
* @return JSONResponse
* @throws ClientException
*/
#[TrapError]
Expand Down
33 changes: 32 additions & 1 deletion lib/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,30 @@ public function flagMessage(Account $account, string $mailbox, int $uid, string
)
);
}
public function tagMessageWithClient(Horde_Imap_Client_Socket $client, Account $account, Mailbox $mailbox, Message $message, Tag $tag, bool $value):void {

if ($this->isPermflagsEnabled($client, $account, $mailbox->getName()) === true) {
try {
if ($value) {
// imap keywords and flags work the same way
$this->imapMessageMapper->addFlag($client, $mailbox, [$message->getUid()], $tag->getImapLabel());
} else {
$this->imapMessageMapper->removeFlag($client, $mailbox, [$message->getUid()], $tag->getImapLabel());
}
} catch (Horde_Imap_Client_Exception $e) {
throw new ServiceException(
"Could not set message keyword on IMAP: " . $e->getMessage(),
$e->getCode(),
$e
);
}
if ($value) {
$this->tagMapper->tagMessage($tag, $message->getMessageId(), $account->getUserId());
} else {
$this->tagMapper->untagMessage($tag, $message->getMessageId());
}
}
}
/**
* Tag (flag) a message on IMAP
*
Expand Down Expand Up @@ -839,10 +862,18 @@ public function deleteTag(int $id, string $userId, Account $account): Tag {
} catch (DoesNotExistException $e) {
throw new ClientException('Tag not found', 0, $e);
}
$client = $this->imapClientFactory->getClient($account);

foreach ($messageTags as $messageTag) {
$this->messageTagsMapper->delete($messageTag);
}

foreach ($messages as $message) {
$mailbox = $this->getMailbox($userId, $message->getMailboxId());
$this->tagMessage($account, $mailbox->getName(), $message, $tag, false);
$this->tagMessageWithClient($client, $account, $mailbox, $message, $tag, false);
}

$client->logout();
return $this->tagMapper->delete($tag);

}
Expand Down
9 changes: 7 additions & 2 deletions src/components/DeleteTagModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@
size="large"
container="body"
@close="onClose">
<div class="modal__content">
{{ t('mail', 'The tag will be deleted from all messages.') }}
<div class="modal-content">
<p class="modal-text">
{{ t('mail', 'The tag will be deleted from all messages.') }}
</p>
</div>
<div class="modal__footer">
<Button :disabled="deleting" @click="onClose">
Expand Down Expand Up @@ -89,4 +91,7 @@ export default {
justify-content: flex-end;
}
}
.modal-text{
margin-top: 20px;
}
</style>
6 changes: 1 addition & 5 deletions src/components/TagItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default {
},
methods: {
deleteTag() {
this.$emit('delete-tag', this.tag)
this.$emit('deleteTag', this.tag)

Check failure on line 94 in src/components/TagItem.vue

View workflow job for this annotation

GitHub Actions / eslint

Custom event name 'deleteTag' must be kebab-case
},
async updateColor(newColor) {
this.editColor = newColor
Expand Down Expand Up @@ -194,10 +194,6 @@ export default {
position: relative;
}
}
.tag-title {
margin-top: 20px;
margin-left: 10px;
}
.tag-group {
display: block;
position: relative;
Expand Down
53 changes: 29 additions & 24 deletions src/components/TagModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,33 @@
:key="tag.id"
:tag="tag"
:envelopes="envelopes"
@delete-tag="deleteTag" />
@deleteTag="deleteTag" />

<h2 class="tag-title">
{{ t('mail', 'Add tag') }}
</h2>
</div>
<div class="create-tag">
<NcButton v-if="!editing"
class="tagButton"
@click="addTagInput">
<template #icon>
<IconAdd :size="20" />
</template>
{{ t('mail', 'Add tag') }}
</NcButton>
<ActionInput v-if="editing" @submit="createTag">
<template #icon>
<IconTag :size="20" />
</template>
</ActionInput>
<ActionText
v-if="showSaving">
<template #icon>
<IconLoading :size="20" />
</template>
{{ t('mail', 'Saving tag …') }}
</ActionText>
<div class="create-tag">
<NcButton v-if="!editing"
class="tagButton"
@click="addTagInput">
<template #icon>
<IconAdd :size="20" />
</template>
{{ t('mail', 'Add tag') }}
</NcButton>
<ActionInput v-if="editing" @submit="createTag">
<template #icon>
<IconTag :size="20" />
</template>
</ActionInput>
<ActionText
v-if="showSaving">
<template #icon>
<IconLoading :size="20" />
</template>
{{ t('mail', 'Saving tag …') }}
</ActionText>
</div>
</div>
</Modal>
</template>
Expand Down Expand Up @@ -92,7 +92,8 @@ export default {
IconLoading,
TagItem,
NcButton,
IconAdd,},
IconAdd,
},
props: {
envelopes: {
// The envelopes on which this menu will act
Expand Down Expand Up @@ -251,6 +252,10 @@ export default {
display: inline-block;
margin-left: 10px;
}
.tag-title {
margin-top: 20px;
margin-left: 10px;
}

.create-tag {
list-style: none;
Expand Down
2 changes: 1 addition & 1 deletion src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -1274,7 +1274,7 @@ export default {
return handleHttpAuthErrors(commit, async () => {
await deleteTag(tag.id, accountId)
commit('deleteTag', { tagId: tag.id })
logger.debug('tag updated', { tag })
logger.debug('tag deleted', { tag })
})
},
async deleteThread({ getters, commit }, { envelope }) {
Expand Down

0 comments on commit 7d3a707

Please sign in to comment.