Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
71a4ef5
읽음·별표 상태를 IMAP 서버와 동기화
littlebit0 Nov 21, 2026
04690f6
플래그 변경 후 상세 캐시 갱신, 위젯 해제 이후에도 무효화, 실패 롤백을 해당 필드로 한정
littlebit0 Nov 21, 2026
b1f30c4
플래그 변경 요청을 순서대로 전송하고 캐시 재조회 테스트를 상세 화면 재진입 기준으로 수정
littlebit0 Nov 21, 2026
851e61c
연속 요청 실패 시 서버가 확정한 마지막 플래그 상태로 복원
littlebit0 Nov 21, 2026
2c3e7f7
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
9e57d9e
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
012c4ab
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
6aa5266
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
1211c85
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
dc35bd4
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
f89b1e1
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
15cbfc9
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
05a7c2f
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
4532cc1
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
a3b7a41
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
fdc8dec
Merge remote-tracking branch 'origin/main' into feat/issue-26-flag-sync
littlebit0 Nov 26, 2026
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
7 changes: 7 additions & 0 deletions apps/client/lib/core/i18n/language_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ class AppStrings {
String get send => _ko ? '보내기' : 'Send';
String get message => _ko ? '메일' : 'Message';
String get reply => _ko ? '답장' : 'Reply';
String get markUnread => _ko ? '읽지 않음으로 표시' : 'Mark as unread';
String get markRead => _ko ? '읽음으로 표시' : 'Mark as read';
String get addStar => _ko ? '별표 표시' : 'Add star';
String get removeStar => _ko ? '별표 해제' : 'Remove star';
String get flagUpdateFailed => _ko
? '메일 상태를 서버에 반영하지 못했습니다.'
: 'Could not update the message on the server.';
String get replyAll => _ko ? '전체 답장' : 'Reply all';
String get cc => _ko ? '참조' : 'Cc';

Expand Down
11 changes: 10 additions & 1 deletion apps/client/lib/features/accounts/account_mailbox_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,16 @@ class _MailboxContentState extends ConsumerState<_MailboxContent> {
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
trailing: Text(message.receivedAtLabel),
trailing: Row(
mainAxisSize: MainAxisSize.min,
children: [
if (message.flagged) ...[
const Icon(Icons.star, size: 18, color: Colors.amber),
const SizedBox(width: 6),
],
Text(message.receivedAtLabel),
],
),
onTap: () => context.go(
'/accounts/${account.id}/messages/${Uri.encodeComponent(message.id)}',
extra: const {'disableTransition': true},
Expand Down
116 changes: 108 additions & 8 deletions apps/client/lib/features/message/message_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:go_router/go_router.dart';

import '../../core/i18n/language_controller.dart';
import '../../services/mail_api_client.dart';
import '../accounts/account_providers.dart';
import '../../widgets/app_shell.dart';
import 'attachment_list.dart';
import 'linked_message_body.dart';
Expand All @@ -20,7 +21,7 @@ final messageProvider =
);
});

class MessagePage extends ConsumerWidget {
class MessagePage extends ConsumerStatefulWidget {
const MessagePage({
super.key,
required this.messageId,
Expand All @@ -31,10 +32,91 @@ class MessagePage extends ConsumerWidget {
final String accountId;

@override
Widget build(BuildContext context, WidgetRef ref) {
final message = ref.watch(
messageProvider((messageId: messageId, accountId: accountId)),
);
ConsumerState<MessagePage> createState() => _MessagePageState();
}

class _MessagePageState extends ConsumerState<MessagePage> {
// Local overrides until the server confirms; null means "as loaded".
bool? _seen;
bool? _flagged;
bool _autoMarked = false;

String get messageId => widget.messageId;
String get accountId => widget.accountId;

// Last server-confirmed values (null = as loaded); failures roll back to these.
bool? _confirmedSeen;
bool? _confirmedFlagged;

// Bumped per request so a failure only rolls back when no newer request for the field is pending.
int _seenVersion = 0;
int _flaggedVersion = 0;

// Requests run one at a time so the server applies them in tap order.
Future<void> _queue = Future.value();

Future<void> _setFlags({bool? seen, bool? flagged}) async {
final id = accountId;
// The container outlives this widget, so invalidation still works after dispose.
final container = ProviderScope.containerOf(context, listen: false);
final seenVersion = seen != null ? ++_seenVersion : _seenVersion;
final flaggedVersion =
flagged != null ? ++_flaggedVersion : _flaggedVersion;
setState(() {
if (seen != null) _seen = seen;
if (flagged != null) _flagged = flagged;
});
try {
final run = _queue.then(
(_) => container.read(mailApiClientProvider).setMessageFlags(
accountId: id,
messageId: messageId,
seen: seen,
flagged: flagged,
),
);
_queue = run.catchError((_) {});
await run;
if (seen != null) _confirmedSeen = seen;
if (flagged != null) _confirmedFlagged = flagged;
container.invalidate(accountMessagesProvider(id));
container.invalidate(
messageProvider((messageId: messageId, accountId: id)),
);
} catch (_) {
if (!mounted) return;
setState(() {
if (seen != null && seenVersion == _seenVersion) _seen = _confirmedSeen;
if (flagged != null && flaggedVersion == _flaggedVersion) {
_flagged = _confirmedFlagged;
}
});
ScaffoldMessenger.maybeOf(context)?.showSnackBar(
SnackBar(content: Text(ref.read(appStringsProvider).flagUpdateFailed)),
);
}
}

// Opening a message marks it read, matching other mail apps.
void _markReadOnOpen(AsyncValue<MessageDetail> value) {
final item = value.valueOrNull;
if (item == null || _autoMarked) return;
_autoMarked = true;
if (!item.seen) _setFlags(seen: true);
}

@override
Widget build(BuildContext context) {
final request = (messageId: messageId, accountId: accountId);
final message = ref.watch(messageProvider(request));
final detail = message.valueOrNull;
if (!_autoMarked && detail != null) {
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) _markReadOnOpen(message);
});
}
final seen = _seen ?? detail?.seen ?? false;
final flagged = _flagged ?? detail?.flagged ?? false;
final strings = ref.watch(appStringsProvider);
final mailboxPath = '/accounts/$accountId/mail';

Expand All @@ -52,6 +134,25 @@ class MessagePage extends ConsumerWidget {
),
title: Text(strings.message),
actions: [
if (detail != null) ...[
IconButton(
tooltip: flagged ? strings.removeStar : strings.addStar,
onPressed: () => _setFlags(flagged: !flagged),
Comment thread
littlebit0 marked this conversation as resolved.
Resolved
icon: Icon(
flagged ? Icons.star : Icons.star_border,
color: flagged ? Colors.amber : null,
),
),
IconButton(
tooltip: seen ? strings.markUnread : strings.markRead,
onPressed: () => _setFlags(seen: !seen),
icon: Icon(
seen
? Icons.mark_email_unread_outlined
: Icons.drafts_outlined,
),
),
],
if (message.value case final item?) ...[
IconButton(
tooltip: strings.reply,
Expand Down Expand Up @@ -89,9 +190,8 @@ class MessagePage extends ConsumerWidget {
],
),
loading: () => const Center(child: CircularProgressIndicator()),
error: (error, stackTrace) => Center(
child: Text(strings.messageLoadFailedTitle),
),
error: (error, stackTrace) =>
Center(child: Text(strings.messageLoadFailedTitle)),
),
),
],
Expand Down
26 changes: 25 additions & 1 deletion apps/client/lib/services/mail_api_client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ class MailApiClient {
return MessageDetail.fromJson(response.data ?? {});
}

Future<void> setMessageFlags({
required String accountId,
required String messageId,
bool? seen,
bool? flagged,
}) async {
await _dio.post(
'/accounts/$accountId/messages/${Uri.encodeComponent(messageId)}/flags',
data: {
if (seen != null) 'seen': seen,
if (flagged != null) 'flagged': flagged,
},
);
}

Future<void> downloadAttachment({
required String accountId,
required String messageId,
Expand Down Expand Up @@ -302,6 +317,7 @@ class MailSummary {
required this.snippet,
required this.receivedAtLabel,
required this.unread,
this.flagged = false,
});

final String id;
Expand All @@ -310,6 +326,7 @@ class MailSummary {
final String snippet;
final String receivedAtLabel;
final bool unread;
final bool flagged;

factory MailSummary.fromJson(Map<String, dynamic> json) {
return MailSummary(
Expand All @@ -318,7 +335,8 @@ class MailSummary {
subject: json['subject'] as String? ?? '',
snippet: json['snippet'] as String? ?? '',
receivedAtLabel: _formatReceivedAt(json['receivedAt'] as String?),
unread: true,
unread: !(json['seen'] as bool? ?? false),
flagged: json['flagged'] as bool? ?? false,
);
}
}
Expand All @@ -331,6 +349,8 @@ class MessageDetail {
required this.body,
required this.links,
required this.receivedAtLabel,
this.seen = false,
this.flagged = false,
this.attachments = const [],
this.receivedAt,
this.accountId,
Expand All @@ -341,6 +361,8 @@ class MessageDetail {
this.replyAllCc = const [],
});

final bool seen;
final bool flagged;
final String? accountId;
final String? messageId;
final List<String> references;
Expand All @@ -367,6 +389,8 @@ class MessageDetail {
.map(MessageLink.fromJson)
.toList(growable: false),
receivedAtLabel: _formatReceivedAt(json['receivedAt'] as String?),
seen: json['seen'] as bool? ?? false,
flagged: json['flagged'] as bool? ?? false,
attachments: (json['attachments'] as List<dynamic>? ?? const [])
.whereType<Map<String, dynamic>>()
.map(MessageAttachment.fromJson)
Expand Down
Loading
Loading