Skip to content

feat: Allow user to control message view mode #10945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@
'url' => '/api/settings/importance-classification-default',
'verb' => 'PUT'
],
[
'name' => 'settings#setLayoutMessageView',
'url' => '/api/settings/layout-message-view',
'verb' => 'PUT'
],
[
'name' => 'trusted_senders#setTrusted',
'url' => '/api/trustedsenders/{email}',
Expand Down
6 changes: 5 additions & 1 deletion lib/Contracts/IMailSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
interface IMailSearch {
public const ORDER_NEWEST_FIRST = 'DESC';
public const ORDER_OLDEST_FIRST = 'ASC';
public const VIEW_SINGLETON = 'singleton';
public const VIEW_THREADED = 'threaded';
/**
* @throws DoesNotExistException
* @throws ClientException
Expand All @@ -36,6 +38,7 @@ public function findMessage(Account $account,
* @param string|null $filter
* @param int|null $cursor
* @param int|null $limit
* @param string|null $view
*
* @return Message[]
*
Expand All @@ -47,7 +50,8 @@ public function findMessages(Account $account,
string $sortOrder,
?string $filter,
?int $cursor,
?int $limit): array;
?int $limit,
?string $view): array;

/**
* @param IUser $user
Expand Down
26 changes: 16 additions & 10 deletions lib/Controller/MessagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
* @param int $cursor
* @param string $filter
* @param int|null $limit
* @param string $view returns messages in requested view ('singleton' or 'threaded')
*
* @return JSONResponse
*
Expand All @@ -134,7 +135,8 @@
public function index(int $mailboxId,
?int $cursor = null,
?string $filter = null,
?int $limit = null): JSONResponse {
?int $limit = null,
?string $view = null): JSONResponse {
try {
$mailbox = $this->mailManager->getMailbox($this->currentUserId, $mailboxId);
$account = $this->accountService->find($this->currentUserId, $mailbox->getAccountId());
Expand All @@ -143,17 +145,21 @@
}

$this->logger->debug("loading messages of mailbox <$mailboxId>");
$sort = $this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest') === 'newest' ? IMailSearch::ORDER_NEWEST_FIRST: IMailSearch::ORDER_OLDEST_FIRST;

Check warning on line 148 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L148

Added line #L148 was not covered by tests

$view = $view === 'singleton' ? IMailSearch::VIEW_SINGLETON : IMailSearch::VIEW_THREADED;

Check warning on line 150 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L150

Added line #L150 was not covered by tests

$order = $this->preferences->getPreference($this->currentUserId, 'sort-order', 'newest') === 'newest' ? 'DESC': 'ASC';
$messages = $this->mailSearch->findMessages(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inline the var and you have a smaller diff ✨

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, Hopefully this is what you ment

$account,
$mailbox,
$sort,
$filter === '' ? null : $filter,
$cursor,
$limit,
$view
);

Check warning on line 160 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L152-L160

Added lines #L152 - L160 were not covered by tests
return new JSONResponse(
$this->mailSearch->findMessages(
$account,
$mailbox,
$order,
$filter === '' ? null : $filter,
$cursor,
$limit
)
$messages

Check warning on line 162 in lib/Controller/MessagesController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/MessagesController.php#L162

Added line #L162 was not covered by tests
);
}

Expand Down
1 change: 1 addition & 0 deletions lib/Controller/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function index(): TemplateResponse {
'app-version' => $this->config->getAppValue('mail', 'installed_version'),
'external-avatars' => $this->preferences->getPreference($this->currentUserId, 'external-avatars', 'true'),
'layout-mode' => $this->preferences->getPreference($this->currentUserId, 'layout-mode', 'vertical-split'),
'layout-message-view' => $this->preferences->getPreference($this->currentUserId, 'layout-message-view', $this->config->getAppValue('mail', 'layout_message_view', 'threaded')),
'reply-mode' => $this->preferences->getPreference($this->currentUserId, 'reply-mode', 'top'),
'collect-data' => $this->preferences->getPreference($this->currentUserId, 'collect-data', 'true'),
'search-priority-body' => $this->preferences->getPreference($this->currentUserId, 'search-priority-body', 'false'),
Expand Down
5 changes: 5 additions & 0 deletions lib/Controller/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@
return new JSONResponse([]);
}

public function setLayoutMessageView(string $value): JSONResponse {
$this->config->setAppValue('mail', 'layout_message_view', $value);
return new JSONResponse([]);

Check warning on line 129 in lib/Controller/SettingsController.php

View check run for this annotation

Codecov / codecov/patch

lib/Controller/SettingsController.php#L127-L129

Added lines #L127 - L129 were not covered by tests
}

}
34 changes: 19 additions & 15 deletions lib/Db/MessageMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -807,21 +807,23 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, string $sor
} else {
$select = $qb->select(['m.id', 'm.sent_at']);
}

$selfJoin = $select->expr()->andX(
$select->expr()->eq('m.mailbox_id', 'm2.mailbox_id', IQueryBuilder::PARAM_INT),
$select->expr()->eq('m.thread_root_id', 'm2.thread_root_id', IQueryBuilder::PARAM_INT),
$select->expr()->orX(
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->andX(
$select->expr()->eq('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.message_id', 'm2.message_id', IQueryBuilder::PARAM_STR),

$select->from($this->getTableName(), 'm');

if ($query->getStacked()) {
$selfJoin = $select->expr()->andX(
$select->expr()->eq('m.mailbox_id', 'm2.mailbox_id', IQueryBuilder::PARAM_INT),
$select->expr()->eq('m.thread_root_id', 'm2.thread_root_id', IQueryBuilder::PARAM_INT),
$select->expr()->orX(
$select->expr()->lt('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->andX(
$select->expr()->eq('m.sent_at', 'm2.sent_at', IQueryBuilder::PARAM_INT),
$select->expr()->lt('m.message_id', 'm2.message_id', IQueryBuilder::PARAM_STR),
),
),
),
);

$select->from($this->getTableName(), 'm')
->leftJoin('m', $this->getTableName(), 'm2', $selfJoin);
);
$select->leftJoin('m', $this->getTableName(), 'm2', $selfJoin);
}

if (!empty($query->getFrom())) {
$select->innerJoin('m', 'mail_recipients', 'r0', 'm.id = r0.message_id');
Expand Down Expand Up @@ -1007,7 +1009,9 @@ public function findIdsByQuery(Mailbox $mailbox, SearchQuery $query, string $sor
);
}

$select->andWhere($qb->expr()->isNull('m2.id'));
if ($query->getStacked()) {
$select->andWhere($qb->expr()->isNull('m2.id'));
}

if ($sortOrder === 'ASC') {
$select->orderBy('m.sent_at', $sortOrder);
Expand Down
7 changes: 6 additions & 1 deletion lib/Service/Search/MailSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
* @param string|null $filter
* @param int|null $cursor
* @param int|null $limit
* @param string|null $view
*
* @return Message[]
*
Expand All @@ -91,7 +92,8 @@
string $sortOrder,
?string $filter,
?int $cursor,
?int $limit): array {
?int $limit,
?string $view): array {
if ($mailbox->hasLocks($this->timeFactory->getTime())) {
throw MailboxLockedException::from($mailbox);
}
Expand All @@ -103,6 +105,9 @@
if ($cursor !== null) {
$query->setCursor($cursor);
}
if ($view !== null) {
$query->setStacked($view === self::VIEW_THREADED);

Check warning on line 109 in lib/Service/Search/MailSearch.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/Search/MailSearch.php#L109

Added line #L109 was not covered by tests
}
// In flagged we don't want anything but flagged messages
if ($mailbox->isSpecialUse(Horde_Imap_Client::SPECIALUSE_FLAGGED)) {
$query->addFlag(Flag::is(Flag::FLAGGED));
Expand Down
10 changes: 10 additions & 0 deletions lib/Service/Search/SearchQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
class SearchQuery {
/** @var int|null */
private $cursor;

private bool $stacked = true;

/** @var Flag[] */
private $flags = [];
Expand Down Expand Up @@ -72,6 +74,14 @@
$this->cursor = $cursor;
}

public function getStacked(): bool {
return $this->stacked;
}

public function setStacked(bool $stacked): void {
$this->stacked = $stacked;

Check warning on line 82 in lib/Service/Search/SearchQuery.php

View check run for this annotation

Codecov / codecov/patch

lib/Service/Search/SearchQuery.php#L81-L82

Added lines #L81 - L82 were not covered by tests
}

public function getMatch(): string {
return $this->match;
}
Expand Down
6 changes: 6 additions & 0 deletions lib/Settings/AdminSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ public function getForm() {
$this->config->getAppValue('mail', 'allow_new_mail_accounts', 'yes') === 'yes'
);

$this->initialStateService->provideInitialState(
Application::APP_ID,
'layout_message_view',
$this->config->getAppValue('mail', 'layout_message_view', 'threaded')
);

$this->initialStateService->provideInitialState(
Application::APP_ID,
'llm_processing',
Expand Down
31 changes: 31 additions & 0 deletions src/components/AppSettingsMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,24 @@
{{ t('mail', 'Horizontal split') }}
</NcCheckboxRadioSwitch>

<h6>{{ t('mail', 'Message View Mode') }}</h6>
<div class="sorting">
<NcCheckboxRadioSwitch type="radio"
name="message_view_mode_radio"
value="threaded"
:checked="layoutMessageView"
@update:checked="setLayoutMessageView('threaded')">
{{ t('mail', 'Show all messages in thread') }}
</NcCheckboxRadioSwitch>
<NcCheckboxRadioSwitch type="radio"
name="message_view_mode_radio"
value="singleton"
:checked="layoutMessageView"
@update:checked="setLayoutMessageView('singleton')">
{{ t('mail', 'Show only the selected message') }}
</NcCheckboxRadioSwitch>
</div>

<h6>{{ t('mail', 'Sorting') }}</h6>
<div class="sorting">
<NcCheckboxRadioSwitch class="sorting__switch"
Expand Down Expand Up @@ -398,6 +416,9 @@ export default {
layoutMode() {
return this.mainStore.getPreference('layout-mode', 'vertical-split')
},
layoutMessageView() {
return this.mainStore.getPreference('layout-message-view')
},
},
watch: {
showSettings(value) {
Expand Down Expand Up @@ -439,6 +460,16 @@ export default {
Logger.error('Could not save preferences', { error })
}
},
async setLayoutMessageView(value) {
try {
await this.mainStore.savePreference({
key: 'layout-message-view',
value,
})
} catch (error) {
Logger.error('Could not save preferences', { error })
}
},
async onOpen() {
this.showSettings = true
},
Expand Down
Loading
Loading