Skip to content

Commit e7cd777

Browse files
committed
compose: Show error dialog on failure of edit-message request
I'm not finding the discussion where we said we wanted this (for consistency with the send-message UX), but I think we did. Error-feedback logic copied from the tap-"Send" button (_SendButtonState._send) modulo the error dialog's title, "Message not saved" vs. "Message not sent".
1 parent ef67a67 commit e7cd777

File tree

4 files changed

+37
-5
lines changed

4 files changed

+37
-5
lines changed

lib/widgets/compose_box.dart

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,7 +1800,7 @@ class _EditMessageBanner extends _Banner {
18001800
Color getBackgroundColor(DesignVariables designVariables) =>
18011801
designVariables.bannerBgIntInfo;
18021802

1803-
void _handleTapSave (BuildContext pageContext) {
1803+
void _handleTapSave (BuildContext pageContext) async {
18041804
final store = PerAccountStoreWidget.of(pageContext);
18051805
final controller = composeBoxState.controller;
18061806
if (controller is! EditMessageComposeBoxController) return; // TODO(log)
@@ -1826,10 +1826,24 @@ class _EditMessageBanner extends _Banner {
18261826
final messageId = controller.messageId;
18271827
final newContent = controller.content.textNormalized;
18281828
composeBoxState.endEditInteraction();
1829-
store.editMessage(
1830-
messageId: messageId,
1831-
originalRawContent: originalRawContent,
1832-
newContent: newContent).onError((_, _) {}); // TODO show error feedback
1829+
1830+
try {
1831+
await store.editMessage(
1832+
messageId: messageId,
1833+
originalRawContent: originalRawContent,
1834+
newContent: newContent);
1835+
} on ApiRequestException catch (e) {
1836+
if (!pageContext.mounted) return;
1837+
final zulipLocalizations = ZulipLocalizations.of(pageContext);
1838+
final message = switch (e) {
1839+
ZulipApiException() => zulipLocalizations.errorServerMessage(e.message),
1840+
_ => e.message,
1841+
};
1842+
showErrorDialog(context: pageContext,
1843+
title: zulipLocalizations.errorMessageEditNotSaved,
1844+
message: message);
1845+
return;
1846+
}
18331847
}
18341848

18351849
@override

test/widgets/action_sheet_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1952,6 +1952,12 @@ void main() {
19521952
await tester.pump(); // [MenuItemButton.onPressed] called in a post-frame callback: flutter/flutter@e4a39fa2e
19531953
}
19541954

1955+
Future<void> takeErrorDialogAndPump(WidgetTester tester) async {
1956+
final errorDialog = checkErrorDialog(tester, expectedTitle: 'Message not saved');
1957+
await tester.tap(find.byWidget(errorDialog));
1958+
await tester.pump();
1959+
}
1960+
19551961
group('present/absent appropriately', () {
19561962
/// Test whether the edit-message button is visible, given params.
19571963
///
@@ -2042,6 +2048,7 @@ void main() {
20422048
connection.prepare(apiException: eg.apiBadRequest());
20432049
await tester.tap(find.widgetWithText(ZulipWebUiKitButton, 'Save'));
20442050
await tester.pump(Duration.zero);
2051+
await takeErrorDialogAndPump(tester);
20452052
} else if (errorStatus == false) {
20462053
// We're testing the request-in-progress state. Prepare a delay,
20472054
// tap Save, and wait through only part of the delay.

test/widgets/compose_box_test.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1748,6 +1748,12 @@ void main() {
17481748
await tester.pump(); // message list updates
17491749
}
17501750

1751+
Future<void> takeErrorDialogAndPump(WidgetTester tester) async {
1752+
final errorDialog = checkErrorDialog(tester, expectedTitle: 'Message not saved');
1753+
await tester.tap(find.byWidget(errorDialog));
1754+
await tester.pump();
1755+
}
1756+
17511757
/// Check that the compose box is in the "Preparing…" state,
17521758
/// awaiting the fetch-raw-content request.
17531759
Future<void> checkAwaitingRawMessageContent(WidgetTester tester) async {
@@ -1770,6 +1776,7 @@ void main() {
17701776
await tester.tap(
17711777
find.widgetWithText(ZulipWebUiKitButton, 'Save'), warnIfMissed: false);
17721778
await tester.pump(Duration.zero);
1779+
checkNoDialog(tester);
17731780
check(connection.lastRequest).equals(lastRequest);
17741781
}
17751782

@@ -1788,6 +1795,7 @@ void main() {
17881795
connection.prepare(apiException: eg.apiBadRequest());
17891796
await tester.tap(find.widgetWithText(ZulipWebUiKitButton, 'Save'));
17901797
await tester.pump(Duration.zero);
1798+
await takeErrorDialogAndPump(tester);
17911799
await tester.tap(find.text('EDIT NOT SAVED'));
17921800
await tester.pump();
17931801
connection.takeRequests();
@@ -1966,6 +1974,7 @@ void main() {
19661974
await tester.tap(find.widgetWithText(ZulipWebUiKitButton, 'Save'));
19671975
connection.takeRequests();
19681976
await tester.pump(Duration.zero);
1977+
await takeErrorDialogAndPump(tester);
19691978
checkNotInEditingMode(tester, narrow: narrow);
19701979
check(find.text('EDIT NOT SAVED')).findsOne();
19711980

test/widgets/message_list_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,8 @@ void main() {
22992299
await tester.pump(Duration.zero);
23002300
checkEditInProgress(tester);
23012301
await tester.pump(Duration(seconds: 1));
2302+
// (the error dialog is tested elsewhere;
2303+
// it's triggered in the "Save" tap handler, not store.editMessage)
23022304
checkEditFailed(tester);
23032305

23042306
connection.prepare(json: GetMessageResult(

0 commit comments

Comments
 (0)