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 Sep 29, 2023
1 parent 0fcadeb commit 90966b4
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 37 deletions.
11 changes: 6 additions & 5 deletions lib/Contracts/IMailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,16 @@ public function createTag(string $displayName, string $color, string $userId): T
public function updateTag(int $id, string $displayName, string $color, string $userId): Tag;

/**
* Update a mail tag
* Delete a mail tag
*
* @param string $userId
* @param int $id
* @param string $userId
* @param Account $account
*
* @return int
* @throws ClientException if the given tag does not exist
* @return Tag
* @throws ClientException
*/
public function deleteTag(int $id, string $userId, array $messages, Account $account): Tag;
public function deleteTag(int $id, string $userId, Account $account): Tag;

/**
* @param Account $srcAccount
Expand Down
6 changes: 3 additions & 3 deletions lib/Controller/TagsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ class TagsController extends Controller {

public function __construct(IRequest $request,
string $UserId,
IMailManager $mailManager, AccountService $accountService,
IMailManager $mailManager,
AccountService $accountService,
) {
parent::__construct(Application::APP_ID, $request);
$this->currentUserId = $UserId;
Expand Down Expand Up @@ -99,11 +100,10 @@ public function update(int $id, string $displayName, string $color): JSONRespons
public function delete(int $id, int $accountId): JSONResponse {
try {
$account = $this->accountService->find($this->currentUserId, $accountId);
$messages = $this->mailManager->getMessagesByTag($this->currentUserId, $id, $account);
} catch (DoesNotExistException $e) {
return new JSONResponse([], Http::STATUS_FORBIDDEN);
}
$this->mailManager->deleteTag($id, $this->currentUserId, $messages, $account);
$this->mailManager->deleteTag($id, $this->currentUserId, $account);
return new JSONResponse($id);

Check failure on line 107 in lib/Controller/TagsController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

InvalidArgument

lib/Controller/TagsController.php:107:27: InvalidArgument: Argument 1 of OCP\AppFramework\Http\JSONResponse::__construct expects array<array-key, mixed>|object, but int provided (see https://psalm.dev/004)

Check failure on line 107 in lib/Controller/TagsController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

InvalidArgument

lib/Controller/TagsController.php:107:27: InvalidArgument: Argument 1 of OCP\AppFramework\Http\JSONResponse::__construct expects array<array-key, mixed>|object, but int provided (see https://psalm.dev/004)

Check failure on line 107 in lib/Controller/TagsController.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

InvalidArgument

lib/Controller/TagsController.php:107:27: InvalidArgument: Argument 1 of OCP\AppFramework\Http\JSONResponse::__construct expects array<array-key, mixed>|object, but int provided (see https://psalm.dev/004)
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Db/MessageTags.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class MessageTags extends Entity implements JsonSerializable {
protected $imapMessageId;
protected $tagId;

public function __construct() {
$this->addType('tagId', 'integer');
}

#[ReturnTypeWillChange]
public function jsonSerialize() {
Expand Down
7 changes: 1 addition & 6 deletions lib/Db/MessageTagsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IL10N;

/**
* @template-extends QBMapper<MessageTags>
*/
class MessageTagsMapper extends QBMapper {
/** @var IL10N */
private $l10n;

public function __construct(IDBConnection $db,
IL10N $l10n) {
public function __construct(IDBConnection $db) {
parent::__construct($db, 'mail_message_tags');
$this->l10n = $l10n;
}

public function getMessagesByTag(int $id): array {
Expand Down
23 changes: 10 additions & 13 deletions lib/Service/MailManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,6 @@ public function getMessage(string $uid, int $id): Message {
return $this->dbMessageMapper->findByUserId($uid, $id);
}

public function getMessagesByTag(string $uid, int $tagId, Account $account): array {
try {
$messageTags = $this->messageTagsMapper->getMessagesByTag($tagId);
$messages = array_map(function ($messageTag) use ($uid, $account) {
return $this->getByMessageId($account, $messageTag->getImapMessageId());
}, $messageTags);
} catch (DoesNotExistException $e) {
throw new ClientException('Messages not found', 0, $e);
}
return array_merge(...$messages);
}

/**
* @param Horde_Imap_Client_Socket $client
* @param Account $account
Expand Down Expand Up @@ -836,7 +824,16 @@ public function updateTag(int $id, string $displayName, string $color, string $u

return $this->tagMapper->update($tag);
}
public function deleteTag(int $id, string $userId, array $messages, Account $account): Tag {
public function deleteTag(int $id, string $userId, Account $account): Tag {
try {
$messageTags = $this->messageTagsMapper->getMessagesByTag($id);
$messages = array_merge(... array_map(function ($messageTag) use ($account) {

Check failure on line 830 in lib/Service/MailManager.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-master

NamedArgumentNotAllowed

lib/Service/MailManager.php:830:32: NamedArgumentNotAllowed: Method array_merge called with named unpacked array array<array-key, array<array-key, OCA\Mail\Db\Message>> (array with string keys) (see https://psalm.dev/268)

Check failure on line 830 in lib/Service/MailManager.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable27

NamedArgumentNotAllowed

lib/Service/MailManager.php:830:32: NamedArgumentNotAllowed: Method array_merge called with named unpacked array array<array-key, array<array-key, OCA\Mail\Db\Message>> (array with string keys) (see https://psalm.dev/268)

Check failure on line 830 in lib/Service/MailManager.php

View workflow job for this annotation

GitHub Actions / Nextcloud dev-stable26

NamedArgumentNotAllowed

lib/Service/MailManager.php:830:32: NamedArgumentNotAllowed: Method array_merge called with named unpacked array array<array-key, array<array-key, OCA\Mail\Db\Message>> (array with string keys) (see https://psalm.dev/268)
return $this->getByMessageId($account, $messageTag->getImapMessageId());
}, $messageTags));
} catch (DoesNotExistException $e) {
throw new ClientException('Messages not found', 0, $e);
}

try {
$tag = $this->tagMapper->getTagForUser($id, $userId);
} catch (DoesNotExistException $e) {
Expand Down
14 changes: 14 additions & 0 deletions src/components/TagItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
@click="openEditTag">
{{ t('mail','Edit name or color') }}
</NcActionButton>
<NcActionButton v-if="!tag.isDefaultTag"
@click="deleteTag">
<template #icon>
<DeleteIcon :size="20" />
</template>
{{ t('mail','Delete tag') }}
</NcActionButton>

<ActionInput v-if="renameTagInput"
:value="tag.displayName"
@submit="renameTag(tag, $event)" />
Expand Down Expand Up @@ -46,6 +54,8 @@
<script>
import { NcColorPicker, NcActions as Actions, NcActionButton, NcActionText as ActionText, NcActionInput as ActionInput, NcLoadingIcon as IconLoading } from '@nextcloud/vue'
import { showInfo } from '@nextcloud/dialogs'
import DeleteIcon from 'vue-material-design-icons/Delete'
export default {
name: 'TagItem',
components: {
Expand All @@ -55,6 +65,7 @@ export default {
ActionText,
ActionInput,
IconLoading,
DeleteIcon,
},
props: {
tag: {
Expand All @@ -79,6 +90,9 @@ export default {
}
},
methods: {
deleteTag() {
this.$emit('delete-tag', this.tag)
},
async updateColor(newColor) {
this.editColor = newColor
this.showSaving = false
Expand Down
18 changes: 8 additions & 10 deletions src/components/TagModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
<TagItem v-for="tag in tags"
:key="tag.id"
:tag="tag"
:envelopes="envelopes" />
:envelopes="envelopes"
@delete-tag="deleteTag" />

<h2 class="tag-title">
{{ t('mail', 'Add tag') }}
Expand Down Expand Up @@ -65,13 +66,13 @@
</template>

<script>
import { NcButton, NcModal as Modal, NcActionText as ActionText, NcActionInput as ActionInput, NcLoadingIcon as IconLoading } from '@nextcloud/vue'
import { NcModal as Modal, NcActionText as ActionText, NcActionInput as ActionInput, NcLoadingIcon as IconLoading, NcButton } from '@nextcloud/vue'
import DeleteTagModal from './DeleteTagModal.vue'
import TagItem from './TagItem.vue'
import IconTag from 'vue-material-design-icons/Tag'
import DeleteIcon from 'vue-material-design-icons/Delete'
import IconAdd from 'vue-material-design-icons/Plus'
import { showError, showInfo } from '@nextcloud/dialogs'
import { hiddenTags } from './tags.js'
import TagItem from './TagItem'
function randomColor() {
let randomHexColor = ((1 << 24) * Math.random() | 0).toString(16)
Expand All @@ -84,17 +85,14 @@ export default {
name: 'TagModal',
components: {
Modal,
NcButton,
ActionText,
ActionInput,
ActionButton,
DeleteTagModal,
IconRename,
IconTag,
IconAdd,
IconLoading,
DeleteIcon,
},
TagItem,
NcButton,
IconAdd,},

Check failure on line 95 in src/components/TagModal.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required after ','

Check failure on line 95 in src/components/TagModal.vue

View workflow job for this annotation

GitHub Actions / eslint

Expected a line break before this closing brace

Check failure on line 95 in src/components/TagModal.vue

View workflow job for this annotation

GitHub Actions / eslint

A space is required before '}'
props: {
envelopes: {
// The envelopes on which this menu will act
Expand Down

0 comments on commit 90966b4

Please sign in to comment.