Skip to content

Commit

Permalink
hot-fix: cancel send media also show error toast
Browse files Browse the repository at this point in the history
  • Loading branch information
sherlockvn authored and hoangdat committed Jan 10, 2024
1 parent 65e7fd9 commit 2f5a611
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 11 deletions.
9 changes: 5 additions & 4 deletions lib/pages/chat/send_file_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:fluffychat/domain/usecase/send_files_on_web_with_caption_interac
import 'package:fluffychat/domain/usecase/send_media_on_web_with_caption_interactor.dart';
import 'package:fluffychat/pages/chat/input_bar/focus_suggestion_controller.dart';
import 'package:fluffychat/pages/chat/send_file_dialog_view.dart';
import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart';
import 'package:flutter/material.dart';

import 'package:matrix/matrix.dart';
Expand Down Expand Up @@ -51,29 +52,29 @@ class SendFileDialogController extends State<SendFileDialog> {
void sendMediaWithCaption() {
if (widget.room == null) {
Logs().e("sendMediaWithCaption:: room is null");
Navigator.of(context).pop();
Navigator.of(context).pop(SendMediaWithCaptionStatus.error);
return;
}
sendMediaOnWebWithCaptionInteractor.execute(
room: widget.room!,
media: widget.files.first,
caption: textEditingController.text,
);
Navigator.of(context).pop(true);
Navigator.of(context).pop(SendMediaWithCaptionStatus.done);
}

void sendFilesWithCaption() {
if (widget.room == null) {
Logs().e("sendFilesWithCaption:: room is null");
Navigator.of(context).pop();
Navigator.of(context).pop(SendMediaWithCaptionStatus.error);
return;
}
sendFilesOnWebWithCaptionInteractor.execute(
room: widget.room!,
files: widget.files,
caption: textEditingController.text,
);
Navigator.of(context).pop(true);
Navigator.of(context).pop(SendMediaWithCaptionStatus.done);
}

void send() {
Expand Down
5 changes: 4 additions & 1 deletion lib/pages/chat/send_file_dialog_view.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:fluffychat/pages/chat/input_bar/input_bar.dart';
import 'package:fluffychat/pages/chat/send_file_dialog.dart';
import 'package:fluffychat/pages/image_viewer/image_viewer.dart';
import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart';
import 'package:fluffychat/presentation/extensions/send_file_web_extension.dart';
import 'package:fluffychat/utils/interactive_viewer_gallery.dart';
import 'package:fluffychat/utils/matrix_sdk_extensions/matrix_file_extension.dart';
Expand Down Expand Up @@ -73,7 +74,9 @@ class SendFileDialogView extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.end,
children: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
onPressed: () => Navigator.of(context).pop(
SendMediaWithCaptionStatus.cancel,
),
style: ButtonStyle(
shape: MaterialStatePropertyAll(
RoundedRectangleBorder(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
enum SendMediaWithCaptionStatus {
cancel,
done,
error,
}
22 changes: 16 additions & 6 deletions lib/presentation/mixins/send_files_with_caption_web_mixin.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:fluffychat/config/app_config.dart';
import 'package:fluffychat/pages/chat/send_file_dialog.dart';
import 'package:fluffychat/presentation/enum/chat/send_media_with_caption_status_enum.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/utils/platform_infos.dart';
Expand All @@ -14,7 +15,7 @@ mixin SendFilesWithCaptionWebMixin {
}) async {
if (matrixFilesList.length <= AppConfig.maxFilesSendPerDialog &&
matrixFilesList.isNotEmpty) {
showDialog(
final result = await showDialog(
context: context,
useRootNavigator: PlatformInfos.isWeb,
builder: (context) {
Expand All @@ -24,17 +25,26 @@ mixin SendFilesWithCaptionWebMixin {
);
},
);
if (result is SendMediaWithCaptionStatus) {
switch (result) {
case SendMediaWithCaptionStatus.done:
break;
case SendMediaWithCaptionStatus.error:
TwakeSnackBar.show(
context,
L10n.of(context)!.failedToSendFiles,
);
break;
case SendMediaWithCaptionStatus.cancel:
break;
}
}
} else if (matrixFilesList.length > AppConfig.maxFilesSendPerDialog) {
TwakeSnackBar.show(
context,
L10n.of(context)!
.countFilesSendPerDialog(AppConfig.maxFilesSendPerDialog),
);
} else {
TwakeSnackBar.show(
context,
L10n.of(context)!.failedToSendFiles,
);
}
}
}

0 comments on commit 2f5a611

Please sign in to comment.