Skip to content

Commit 93c96a2

Browse files
hoangdatdab246
andauthored
ADR-71 CollapseThread (#4380)
* ADR-71 CollapseThread * fixup! ADR-71 CollapseThread * docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! fixup! fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! fixup! fixup! fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList * fixup! fixup! fixup! fixup! fixup! fixup! fixup! docs(ADR-0072): Add thread-aware bulk actions for collapseThreads in EmailList --------- Co-authored-by: dab246 <tdvu@linagora.com>
1 parent 6d0246d commit 93c96a2

File tree

2 files changed

+697
-0
lines changed

2 files changed

+697
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# 0071 - Enable collapseThreads in Email/query
2+
3+
Date: 2026-03-12
4+
5+
## Status
6+
7+
Proposed
8+
9+
## Context
10+
11+
JMAP `Email/query` supports `collapseThreads` (RFC 8621 §4.4). When `true`, server returns only the **latest email per thread**, avoiding duplicate rows in the mail list.
12+
13+
Currently, our app does **not** set `collapseThreads`. When thread is enabled, users see multiple emails from the same thread as separate rows.
14+
15+
### Two Query Paths (see ADR-0070)
16+
17+
| Path | `FORCE_EMAIL_QUERY` | Method | Cache |
18+
|------|---------------------|--------|-------|
19+
| Force query | `true` | `forceQueryAllEmailsForWeb()` | No local cache — server only |
20+
| Cache-first | `false` | `getAllEmail()` | Local DB first, then sync |
21+
22+
### Problem: Cache Inconsistency on Toggle
23+
24+
On the cache-first path, the local DB reflects the `collapseThreads` mode it was built under. When thread mode changes:
25+
26+
- **OFF → ON**: Cache has individual emails (5 rows) but server now returns collapsed (3 rows) → stale first yield
27+
- **ON → OFF**: Cache has collapsed emails (3 rows) but server now returns all individuals (5 rows) → missing emails in first yield
28+
29+
Force-query path has **no problem** — always queries server directly.
30+
31+
## Decision
32+
33+
### 1. Set `collapseThreads: true` in Email/query When Thread Is Enabled
34+
35+
In `MailAPIMixin.fetchAllEmail()` and `ThreadAPI.searchEmails()`, pass `collapseThreads: true` when thread is enabled.
36+
37+
### 2. Clear Email Cache on Thread Setting Toggle
38+
39+
Reuse the existing thread-enabled setting. **No new flag needed.** When thread is toggled (enable ↔ disable), clear email cache immediately in the toggle handler. Next `getAllEmail()` will rebuild cache under correct mode.
40+
41+
### 3. No Change for Force-Query Path
42+
43+
Already server-only. Just pass `collapseThreads: true` in the query.
44+
45+
## Consequences
46+
47+
**Positive**: Correct thread display, reduced data per page, spec-compliant.
48+
49+
**Negative**: One-time full reload on each toggle; toggle handler coupled with cache management.
50+
51+
## Implementation Steps
52+
53+
1. Add `collapseThreads` to `QueryEmailMethod` in `MailAPIMixin.fetchAllEmail()` and `ThreadAPI.searchEmails()`
54+
2. Pass thread-enabled status from Settings to query builder
55+
3. Clear email cache in thread setting toggle handler
56+
4. Update `GetEmailsInMailboxInteractor` and related interactors to propagate thread status
57+
58+
## References
59+
60+
- [RFC 8621 §4.4](https://www.rfc-editor.org/rfc/rfc8621#section-4.4)
61+
- [ADR-0070](./0070-sync-strategy-disappearing-emails.md)
62+
- `lib/features/base/mixin/mail_api_mixin.dart``fetchAllEmail()`
63+
- `lib/features/thread/data/repository/thread_repository_impl.dart``getAllEmail()`
64+
- `lib/features/thread/domain/usecases/get_emails_in_mailbox_interactor.dart`

0 commit comments

Comments
 (0)