Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
1e8c252
보내기 취소: 서버 발송 지연 큐와 취소 API, 클라이언트 취소 스낵바 추가
littlebit0 Nov 21, 2026
1eae0bf
보내기 취소: 종료 시 진행 중 발송 대기, 취소 항목 정리, 취소 스낵바 즉시 표시
littlebit0 Nov 21, 2026
dbab32f
발송 큐 용량·동시성 제한: 전체 200·계정별 20 초과 시 429, SMTP 동시 4건, 발송 본문 10MiB 제한
littlebit0 Nov 21, 2026
59ae6db
보내기 취소: 비동기 발송 실패 조회(GET /mail/send/:id)와 다시 작성, 취소 남은 시간을 서버 sendAt …
littlebit0 Nov 21, 2026
ecb4be1
발송 결과 조회를 최대 5분 백오프로 유지하고, 복구 초안은 새 작성 화면 인스턴스로 연다
littlebit0 Nov 21, 2026
0ca917d
복구 작성 화면을 별도 경로로 쌓아 작성 중인 메일을 보존
littlebit0 Nov 21, 2026
82a8b99
복구 작성 화면에서 발송한 뒤 go 대신 pop으로 돌아가 기존 작성 내용을 보존
littlebit0 Nov 21, 2026
30be151
발송 실패 초안을 앱 단위 상태로 보관하고 '발송 실패 N건' 배너에서 다시 작성·삭제하도록 변경
littlebit0 Nov 21, 2026
bf948f7
발송 실패 배너를 한 줄로 줄이고 목록은 높이가 제한된 대화상자에서 보도록 변경
littlebit0 Nov 21, 2026
4979b1a
실패 목록 보기 버튼 문구(한국어·영어) 추가
littlebit0 Nov 21, 2026
724cbfb
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
a8c4169
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
dc7721c
대기 중인 발송을 모두 취소할 수 있게 하기
littlebit0 Nov 26, 2026
03065cc
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
b15d7c1
취소 카운트다운에서 응답 왕복 시간 빼기
littlebit0 Nov 26, 2026
b37697c
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
f1cc055
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
34ac986
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
f50c9f3
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
ac0023b
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
littlebit0 Nov 26, 2026
41367a6
Merge remote-tracking branch 'origin/main' into feat/issue-34-undo-send
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
13 changes: 13 additions & 0 deletions apps/client/lib/core/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import '../features/message/compose_page.dart';
import '../features/message/message_page.dart';
import '../features/message/reply_draft.dart';
import '../features/settings/settings_page.dart';
import '../services/mail_api_client.dart';

final appRouterProvider = Provider<GoRouter>((ref) {
return GoRouter(
Expand Down Expand Up @@ -54,6 +55,18 @@ final appRouterProvider = Provider<GoRouter>((ref) {
),
),
),
GoRoute(
// Pushed on top of any open composer so its input survives; popping returns to it.
path: '/compose/recover',
redirect: (context, state) => state.extra is ComposeDraft ? null : '/accounts',
pageBuilder: (context, state) {
final draft = state.extra! as ComposeDraft;
return _verticalPage(
state: state,
child: ComposePage(initialAccountId: draft.accountId, initialDraft: draft),
);
},
),
GoRoute(
path: '/compose',
pageBuilder: (context, state) => _verticalPage(
Expand Down
24 changes: 24 additions & 0 deletions apps/client/lib/core/i18n/language_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,30 @@ class AppStrings {
'password' => _ko ? '비밀번호' : 'Password',
_ => mode,
};
String get mailSending => _ko ? '메일을 보내는 중입니다.' : 'Sending mail...';
String get undoSend => _ko ? '보내기 취소' : 'Undo send';
String get sendCancelled =>
_ko ? '보내기를 취소했습니다.' : 'Sending was cancelled.';
String get sendAlreadySent =>
_ko ? '이미 발송되어 취소할 수 없습니다.' : 'Already sent; it cannot be cancelled.';
String get sendCancelFailed =>
_ko ? '취소하지 못했습니다. 메일이 발송될 수 있습니다.' : 'Could not cancel; the mail may be sent.';
String sendDeliveryFailed(String reason) => _ko
? '메일을 보내지 못했습니다: $reason'
: 'The mail could not be delivered: $reason';
String get sendFailedShort => _ko ? '발송에 실패했습니다.' : 'Sending failed.';
String failedSendsCount(int n) => _ko ? '발송 실패 $n건' : '$n failed to send';
String pendingSendsCount(int n) => _ko ? '보내기 대기 $n건' : '$n waiting to send';
String get viewPendingSends => _ko ? '보기' : 'View';
String get viewFailedSends => _ko ? '보기' : 'View';
String get deleteFailedSend => _ko ? '삭제' : 'Delete';
String get rewriteMail => _ko ? '다시 작성' : 'Rewrite';
String get undoSendSetting => _ko ? '보내기 취소 시간' : 'Undo send delay';
String get undoSendSettingDescription => _ko
? '보낸 메일을 이 시간 동안 서버가 보관하며 취소할 수 있습니다.'
: 'The server holds sent mail for this long so you can cancel it.';
String secondsLabel(int seconds) =>
seconds == 0 ? (_ko ? '끔' : 'Off') : (_ko ? '$seconds초' : '${seconds}s');
String get registerThisDevice => _ko ? '이 기기 등록' : 'Register this device';
String get registerThisDeviceDescription => _ko
? '플랫폼 푸시 토큰을 메일 서버에 등록합니다.'
Expand Down
135 changes: 123 additions & 12 deletions apps/client/lib/features/message/compose_page.dart
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../core/i18n/language_controller.dart';
import '../../services/mail_api_client.dart';
import '../../widgets/app_shell.dart';
import 'failed_sends.dart';
import 'pending_sends.dart';
import 'reply_draft.dart';
import '../accounts/accounts_page.dart' show friendlyError;

Expand All @@ -16,10 +20,14 @@ class ComposePage extends ConsumerStatefulWidget {
const ComposePage({
super.key,
this.initialAccountId,
this.initialDraft,
this.reply,
});

final String? initialAccountId;

/// Reopened failed send (from `/compose/recover`).
final ComposeDraft? initialDraft;
final ReplyDraft? reply;

@override
Expand All @@ -38,8 +46,14 @@ class _ComposePageState extends ConsumerState<ComposePage> {
void initState() {
super.initState();
_accountId = widget.initialAccountId;
final draft = widget.initialDraft;
final reply = widget.reply;
if (reply != null) {
if (draft != null) {
_toController.text = draft.to;
_ccController.text = draft.cc;
_subjectController.text = draft.subject;
_bodyController.text = draft.body;
} else if (reply != null) {
_toController.text = reply.to.join(', ');
_ccController.text = reply.cc.join(', ');
_subjectController.text = reply.subject;
Expand Down Expand Up @@ -71,7 +85,7 @@ class _ComposePageState extends ConsumerState<ComposePage> {
AppBar(
leading: IconButton(
tooltip: strings.close,
onPressed: () => context.go(returnPath),
onPressed: () => context.canPop() ? context.pop() : context.go(returnPath),
icon: const Icon(Icons.close),
),
title: Text(strings.compose),
Expand Down Expand Up @@ -170,25 +184,70 @@ class _ComposePageState extends ConsumerState<ComposePage> {
return;
}

final client = ref.read(mailApiClientProvider);
final delay = ref.read(undoSendDelayProvider);
final router = GoRouter.of(context);
final container = ProviderScope.containerOf(context);
final failedSends = container.read(failedSendsProvider.notifier);
final pendingSends = container.read(pendingSendsProvider.notifier);
final inReplyTo = widget.initialDraft?.inReplyTo ?? widget.reply?.inReplyTo;
final references =
widget.initialDraft?.references ?? widget.reply?.references ?? const <String>[];

setState(() => _sending = true);
final SendReceipt receipt;
try {
await ref.read(mailApiClientProvider).sendMail(
accountId: accountId,
to: to,
cc: _addresses(_ccController.text),
subject: _subjectController.text,
body: _bodyController.text,
inReplyTo: widget.reply?.inReplyTo,
references: widget.reply?.references ?? const [],
);
receipt = await client.sendMail(
accountId: accountId,
to: to,
cc: _addresses(_ccController.text),
subject: _subjectController.text,
body: _bodyController.text,
delaySeconds: delay,
inReplyTo: inReplyTo,
references: references,
);
} catch (error) {
// The draft stays on screen so the user can fix it and retry.
if (mounted) setState(() => _sending = false);
report(strings.sendFailed(friendlyError(error, strings)));
return;
}

if (mounted) context.go('/accounts/$accountId/mail');
// The countdown comes from the server's deadline: show immediately (not behind
// older snackbars) and expire when the server actually sends. Earlier sends stay
// cancellable from the app-level pending list after clearSnackBars().
if (delay > 0 && receipt.remaining > Duration.zero) {
pendingSends.add(
PendingSend(
id: receipt.id,
to: _toController.text,
subject: _subjectController.text,
),
receipt.remaining,
);
messenger.clearSnackBars();
Comment thread
littlebit0 marked this conversation as resolved.
Resolved
messenger.showSnackBar(SnackBar(
Comment thread
littlebit0 marked this conversation as resolved.
Resolved
content: Text(strings.mailSending),
duration: receipt.remaining,
action: SnackBarAction(
label: strings.undoSend,
onPressed: () => cancelPendingSend(
client, strings, messenger, pendingSends, receipt.id),
),
));
}

// Detached from this page on purpose: the composer closes right after sending.
unawaited(_reportFailure(client, receipt, strings, messenger, router, failedSends));

// Pushed pages (recovery compose) pop so the composer underneath keeps its input.
if (!mounted) return;
if (context.canPop()) {
context.pop();
} else {
context.go('/accounts/$accountId/mail');
}
}

List<String> _addresses(String value) => value
Expand All @@ -197,3 +256,55 @@ class _ComposePageState extends ConsumerState<ComposePage> {
.where((item) => item.isNotEmpty)
.toList();
}

/// Polls the queued send after the undo window; on failure offers to reopen the draft.
Future<void> _reportFailure(
MailApiClient client,
SendReceipt receipt,
AppStrings strings,
ScaffoldMessengerState messenger,
GoRouter router,
FailedSendsNotifier failedSends,
) async {
final outcome = await awaitSendOutcome(client, receipt);
final draft = outcome?.draft;
if (outcome == null || draft == null) return;
final item = FailedSend(id: receipt.id, draft: draft, error: outcome.error ?? '');
// Also kept in the app-level list: a later send's clearSnackBars() must not lose it.
failedSends.add(item);
messenger.showSnackBar(SnackBar(
content: Text(strings.sendDeliveryFailed(outcome.error ?? '')),
duration: const Duration(seconds: 15),
action: SnackBarAction(
label: strings.rewriteMail,
onPressed: () => rewriteFailedSend(router, failedSends, item),
),
));
}

/// Waits out the undo window, then polls with backoff while the send is pending/sending, up to [maxWait].
/// Returns the outcome only when the send failed.
Future<SendOutcome?> awaitSendOutcome(
MailApiClient client,
SendReceipt receipt, {
Duration interval = const Duration(seconds: 2),
Duration maxInterval = const Duration(seconds: 15),
Duration maxWait = const Duration(minutes: 5),
}) async {
if (receipt.remaining > Duration.zero) await Future<void>.delayed(receipt.remaining);
var waited = Duration.zero;
var delay = interval;
while (waited < maxWait) {
await Future<void>.delayed(delay);
waited += delay;
try {
final outcome = await client.fetchSendOutcome(receipt.id);
if (outcome.status == 'failed') return outcome;
if (outcome.status == 'sent' || outcome.status == 'cancelled') return null;
} catch (_) {
// Transient error or expired entry: keep trying until maxWait.
}
delay = delay * 2 > maxInterval ? maxInterval : delay * 2;
}
return null;
}
136 changes: 136 additions & 0 deletions apps/client/lib/features/message/failed_sends.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';

import '../../core/i18n/language_controller.dart';
import '../../services/mail_api_client.dart';

class FailedSend {
const FailedSend(
{required this.id, required this.draft, required this.error});
final String id;
final ComposeDraft draft;
final String error;
}

/// App-level so a failed draft outlives the page and snackbars that reported it.
class FailedSendsNotifier extends Notifier<List<FailedSend>> {
@override
List<FailedSend> build() => const [];

void add(FailedSend item) =>
state = [...state.where((e) => e.id != item.id), item];

void remove(String id) => state = [...state.where((e) => e.id != id)];
}

final failedSendsProvider =
NotifierProvider<FailedSendsNotifier, List<FailedSend>>(
FailedSendsNotifier.new);

/// Reopens a failed draft in the stacked recovery composer and drops it from the list.
void rewriteFailedSend(
GoRouter router, FailedSendsNotifier notifier, FailedSend item) {
notifier.remove(item.id);
router.push('/compose/recover', extra: item.draft);
}

/// Persistent single-row "N failed" indicator; the list lives in a bounded dialog so the
/// banner never grows and pushes the mail area off screen.
class FailedSendsBanner extends ConsumerWidget {
const FailedSendsBanner({super.key});

@override
Widget build(BuildContext context, WidgetRef ref) {
final items = ref.watch(failedSendsProvider);
if (items.isEmpty) return const SizedBox.shrink();
final strings = ref.watch(appStringsProvider);
final scheme = Theme.of(context).colorScheme;

return Material(
color: scheme.errorContainer,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
child: Row(
children: [
Expanded(
child: Text(
strings.failedSendsCount(items.length),
style: Theme.of(context).textTheme.labelLarge?.copyWith(
color: scheme.onErrorContainer,
fontWeight: FontWeight.w700,
),
),
),
TextButton(
onPressed: () => showDialog<void>(
context: context,
builder: (_) =>
_FailedSendsDialog(router: GoRouter.of(context)),
),
child: Text(strings.viewFailedSends),
),
],
),
),
);
}
}

class _FailedSendsDialog extends ConsumerWidget {
const _FailedSendsDialog({required this.router});
final GoRouter router;

@override
Widget build(BuildContext context, WidgetRef ref) {
final items = ref.watch(failedSendsProvider);
final strings = ref.watch(appStringsProvider);
final notifier = ref.read(failedSendsProvider.notifier);
return AlertDialog(
title: Text(strings.failedSendsCount(items.length)),
content: SizedBox(
width: 480,
child: ListView.builder(
shrinkWrap: true,
itemCount: items.length,
itemBuilder: (context, i) {
final item = items[i];
return Row(
children: [
Expanded(
child: Text(
item.draft.subject.isEmpty
? item.draft.to
: '${item.draft.subject} · ${item.draft.to}',
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
rewriteFailedSend(router, notifier, item);
},
child: Text(strings.rewriteMail),
),
TextButton(
onPressed: () {
if (items.length == 1) Navigator.of(context).pop();
notifier.remove(item.id);
},
child: Text(strings.deleteFailedSend),
),
],
);
},
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: Text(strings.close),
),
],
);
}
}
Loading
Loading