feat(ui): Show errors
This commit is contained in:
parent
04c0c1c0e2
commit
0eeac949ea
@ -37,6 +37,19 @@
|
||||
"startTlsFailed": "Failed to establish a secure connection",
|
||||
"noConnection": "Failed to establish a connection",
|
||||
"unspecified": "Unspecified error"
|
||||
},
|
||||
"message": {
|
||||
"unspecified": "Unknown error",
|
||||
"fileUploadFailed": "The file upload failed",
|
||||
"contactDoesntSupportOmemo": "The contact does not support encryption using OMEMO:2",
|
||||
"fileDownloadFailed": "The file download failed",
|
||||
"serviceUnavailable": "The message could not be delivered to the contact",
|
||||
"remoteServerTimeout": "The message could not be delivered to the contact's server",
|
||||
"remoteServerNotFound": "The message could not be delivered to the contact's server as it cannot be found",
|
||||
"failedToEncrypt": "The message could not be encrypted",
|
||||
"failedToEncryptFile": "The file could not be encrypted",
|
||||
"failedToDecryptFile": "The file could not be decrypted",
|
||||
"fileNotEncrypted": "The chat is encrypted but the file is not encrypted"
|
||||
}
|
||||
},
|
||||
"warnings": {
|
||||
|
@ -37,6 +37,19 @@
|
||||
"startTlsFailed": "Konnte keine sichere Verbindung zum Server aufbauen",
|
||||
"noConnection": "Konnte keine Verbindung zum Server aufbauen",
|
||||
"unspecified": "Unbestimmter Fehler"
|
||||
},
|
||||
"message": {
|
||||
"unspecified": "Unbekannter Fehler",
|
||||
"fileUploadFailed": "Das Hochladen der Datei ist fehlgeschlagen",
|
||||
"contactDoesntSupportOmemo": "Der Kontakt unterstützt Verschlüsselung mit OMEMO:2 nicht",
|
||||
"fileDownloadFailed": "Das Herunterladen der Datei ist fehlgeschlagen",
|
||||
"serviceUnavailable": "Die Nachricht konnte nicht gesendet werden",
|
||||
"remoteServerTimeout": "Die Nachricht konnte nicht zugestellt werden",
|
||||
"remoteServerNotFound": "Die Nachricht konnte nicht gesendet werden, da der Empfängerserver unbekannt ist",
|
||||
"failedToEncrypt": "Die Nachricht konnte nicht verschlüsselt werden",
|
||||
"failedToEncryptFile": "Die Datei konnte nicht verschlüsselt werden",
|
||||
"failedToDecryptFile": "Die Datei konnte nicht entschlüsselt werden",
|
||||
"fileNotEncrypted": "Der Chat ist verschlüsselt, aber die Datei wurde unverschlüsselt übertragen"
|
||||
}
|
||||
},
|
||||
"warnings": {
|
||||
|
@ -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 '';
|
||||
}
|
||||
|
@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user