feat(ui): Show errors

This commit is contained in:
2022-11-22 21:58:55 +01:00
parent 04c0c1c0e2
commit 0eeac949ea
5 changed files with 75 additions and 1 deletions

View File

@@ -1,6 +1,8 @@
import 'package:moxxmpp/moxxmpp.dart';
import 'package:moxxyv2/i18n/strings.g.dart';
import 'package:omemo_dart/omemo_dart.dart';
const unspecifiedError = -1;
const noError = 0;
const fileUploadFailedError = 1;
const messageNotEncryptedForDevice = 2;
@@ -14,6 +16,9 @@ const messageContactDoesNotSupportOmemo = 9;
const messageChatEncryptedButFileNot = 10;
const messageFailedToEncryptFile = 11;
const fileDownloadFailedError = 12;
const messageServiceUnavailable = 13;
const messageRemoteServerTimeout = 14;
const messageRemoteServerNotFound = 15;
int errorTypeFromException(dynamic exception) {
if (exception is NoDecryptionKeyException) {
@@ -32,3 +37,24 @@ int errorTypeFromException(dynamic exception) {
return noError;
}
String errorToTranslatableString(int error) {
assert(error != noError, 'Calling errorToTranslatableString with noError makes no sense');
switch (error) {
case fileUploadFailedError: return t.errors.message.fileUploadFailed;
case messageContactDoesNotSupportOmemo: return t.errors.message.contactDoesntSupportOmemo;
case fileDownloadFailedError: return t.errors.message.fileDownloadFailed;
case messageServiceUnavailable: return t.errors.message.serviceUnavailable;
case messageRemoteServerTimeout: return t.errors.message.remoteServerTimeout;
case messageRemoteServerNotFound: return t.errors.message.remoteServerNotFound;
case messageFailedToEncrypt: return t.errors.message.failedToEncrypt;
case messageFailedToDecryptFile: return t.errors.message.failedToDecryptFile;
case messageChatEncryptedButFileNot: return t.errors.message.fileNotEncrypted;
case messageFailedToEncryptFile: return t.errors.message.failedToEncryptFile;
case unspecifiedError: return t.errors.message.unspecified;
}
assert(false, 'Invalid error code $error used');
return '';
}

View File

@@ -142,4 +142,13 @@ class Message with _$Message {
/// Returns true if the message can open the selection menu by longpressing. False if
/// not.
bool get isLongpressable => !isRetracted;
/// Returns true if the menu item to show the error should be shown in the
/// longpress menu.
bool get errorMenuVisible {
return isError() && (
errorType! < messageNotEncryptedForDevice ||
errorType! > messageInvalidNumber
);
}
}

View File

@@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_vibrate/flutter_vibrate.dart';
import 'package:moxxyv2/i18n/strings.g.dart';
//import 'package:moxxyv2/shared/error_types.dart';
import 'package:moxxyv2/shared/error_types.dart';
import 'package:moxxyv2/shared/helpers.dart';
import 'package:moxxyv2/shared/models/message.dart';
import 'package:moxxyv2/shared/warning_types.dart';
@@ -323,6 +323,19 @@ class ChatBubbleState extends State<ChatBubble>
},
),
] : [],
...widget.message.errorMenuVisible ? [
_buildMessageOption(
Icons.info_outline,
'Show Error',
() {
showInfoDialog(
'Error',
errorToTranslatableString(widget.message.errorType!),
context,
);
},
),
] : [],
...widget.message.isWarning() ? [
_buildMessageOption(
Icons.warning,