feat(ui): Display warnings for messages

This commit is contained in:
PapaTutuWawa 2022-10-01 17:28:29 +02:00
parent a0c7078593
commit 0327f254a2
7 changed files with 37 additions and 0 deletions

View File

@ -21,6 +21,7 @@ Future<void> createDatabase(Database db, int version) async {
isFileUploadNotification INTEGER NOT NULL, isFileUploadNotification INTEGER NOT NULL,
encrypted INTEGER NOT NULL, encrypted INTEGER NOT NULL,
errorType INTEGER, errorType INTEGER,
warningType INTEGER,
mediaUrl TEXT, mediaUrl TEXT,
mediaType TEXT, mediaType TEXT,
thumbnailData TEXT, thumbnailData TEXT,

View File

@ -260,6 +260,7 @@ class DatabaseService {
String? quoteId, String? quoteId,
String? filename, String? filename,
int? errorType, int? errorType,
int? warningType,
Map<String, String>? plaintextHashes, Map<String, String>? plaintextHashes,
Map<String, String>? ciphertextHashes, Map<String, String>? ciphertextHashes,
} }
@ -275,6 +276,7 @@ class DatabaseService {
isFileUploadNotification, isFileUploadNotification,
encrypted, encrypted,
errorType: errorType, errorType: errorType,
warningType: warningType,
mediaUrl: mediaUrl, mediaUrl: mediaUrl,
key: key, key: key,
iv: iv, iv: iv,
@ -345,6 +347,7 @@ class DatabaseService {
bool? displayed, bool? displayed,
bool? acked, bool? acked,
int? errorType, int? errorType,
int? warningType,
bool? isFileUploadNotification, bool? isFileUploadNotification,
String? srcUrl, String? srcUrl,
String? key, String? key,
@ -379,6 +382,9 @@ class DatabaseService {
if (errorType != null) { if (errorType != null) {
m['errorType'] = errorType; m['errorType'] = errorType;
} }
if (warningType != null) {
m['warningType'] = warningType;
}
if (isFileUploadNotification != null) { if (isFileUploadNotification != null) {
m['isFileUploadNotification'] = boolToInt(isFileUploadNotification); m['isFileUploadNotification'] = boolToInt(isFileUploadNotification);
} }

View File

@ -24,6 +24,7 @@ import 'package:moxxyv2/service/service.dart';
import 'package:moxxyv2/shared/error_types.dart'; import 'package:moxxyv2/shared/error_types.dart';
import 'package:moxxyv2/shared/events.dart'; import 'package:moxxyv2/shared/events.dart';
import 'package:moxxyv2/shared/models/media.dart'; import 'package:moxxyv2/shared/models/media.dart';
import 'package:moxxyv2/shared/warning_types.dart';
import 'package:moxxyv2/xmpp/connection.dart'; import 'package:moxxyv2/xmpp/connection.dart';
import 'package:moxxyv2/xmpp/managers/namespaces.dart'; import 'package:moxxyv2/xmpp/managers/namespaces.dart';
import 'package:moxxyv2/xmpp/message.dart'; import 'package:moxxyv2/xmpp/message.dart';
@ -361,6 +362,7 @@ class HttpFileTransferService {
// TODO(PapaTutuWawa): Trigger event // TODO(PapaTutuWawa): Trigger event
_log.warning('HTTP GET of ${job.location.url} returned ${response?.statusCode}'); _log.warning('HTTP GET of ${job.location.url} returned ${response?.statusCode}');
} else { } else {
var integrityCheckPassed = true;
if (job.location.key != null && job.location.iv != null) { if (job.location.key != null && job.location.iv != null) {
// The file was encrypted // The file was encrypted
final result = await GetIt.I.get<CryptographyService>().decryptFile( final result = await GetIt.I.get<CryptographyService>().decryptFile(
@ -387,6 +389,8 @@ class HttpFileTransferService {
return; return;
} }
integrityCheckPassed = result.plaintextOkay && result.ciphertextOkay;
// TODO(PapaTutuWawa): Calculate the file's hash and compare to the provided ones // TODO(PapaTutuWawa): Calculate the file's hash and compare to the provided ones
// Cleanup the temporary file // Cleanup the temporary file
unawaited(Directory(pathlib.dirname(downloadPath)).delete(recursive: true)); unawaited(Directory(pathlib.dirname(downloadPath)).delete(recursive: true));
@ -422,6 +426,9 @@ class HttpFileTransferService {
mediaWidth: mediaWidth, mediaWidth: mediaWidth,
mediaHeight: mediaHeight, mediaHeight: mediaHeight,
isFileUploadNotification: false, isFileUploadNotification: false,
warningType: integrityCheckPassed ?
warningFileIntegrityCheckFailed :
null,
); );
sendEvent(MessageUpdatedEvent(message: msg.copyWith(isDownloading: false))); sendEvent(MessageUpdatedEvent(message: msg.copyWith(isDownloading: false)));

View File

@ -51,6 +51,7 @@ class MessageService {
String? quoteId, String? quoteId,
String? filename, String? filename,
int? errorType, int? errorType,
int? warningType,
Map<String, String>? plaintextHashes, Map<String, String>? plaintextHashes,
Map<String, String>? ciphertextHashes, Map<String, String>? ciphertextHashes,
} }
@ -77,6 +78,7 @@ class MessageService {
quoteId: quoteId, quoteId: quoteId,
filename: filename, filename: filename,
errorType: errorType, errorType: errorType,
warningType: warningType,
plaintextHashes: plaintextHashes, plaintextHashes: plaintextHashes,
ciphertextHashes: ciphertextHashes, ciphertextHashes: ciphertextHashes,
); );
@ -109,6 +111,7 @@ class MessageService {
bool? displayed, bool? displayed,
bool? acked, bool? acked,
int? errorType, int? errorType,
int? warningType,
bool? isFileUploadNotification, bool? isFileUploadNotification,
String? srcUrl, String? srcUrl,
String? key, String? key,
@ -125,6 +128,7 @@ class MessageService {
displayed: displayed, displayed: displayed,
acked: acked, acked: acked,
errorType: errorType, errorType: errorType,
warningType: warningType,
isFileUploadNotification: isFileUploadNotification, isFileUploadNotification: isFileUploadNotification,
srcUrl: srcUrl, srcUrl: srcUrl,
key: key, key: key,

View File

@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:freezed_annotation/freezed_annotation.dart'; import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:moxxyv2/service/database/helpers.dart'; import 'package:moxxyv2/service/database/helpers.dart';
import 'package:moxxyv2/shared/error_types.dart'; import 'package:moxxyv2/shared/error_types.dart';
import 'package:moxxyv2/shared/warning_types.dart';
part 'message.freezed.dart'; part 'message.freezed.dart';
part 'message.g.dart'; part 'message.g.dart';
@ -36,6 +37,7 @@ class Message with _$Message {
bool encrypted, bool encrypted,
{ {
int? errorType, int? errorType,
int? warningType,
String? mediaUrl, String? mediaUrl,
@Default(false) bool isDownloading, @Default(false) bool isDownloading,
@Default(false) bool isUploading, @Default(false) bool isUploading,
@ -102,4 +104,9 @@ class Message with _$Message {
bool isError() { bool isError() {
return errorType != null && errorType != noError; return errorType != null && errorType != noError;
} }
/// Returns true if the message is a warning. If not, then returns false.
bool isWarning() {
return warningType != null && warningType != noWarning;
}
} }

View File

@ -0,0 +1,2 @@
const noWarning = 0;
const warningFileIntegrityCheckFailed = 1;

View File

@ -105,6 +105,16 @@ class MessageBubbleBottomState extends State<MessageBubbleBottom> {
), ),
), ),
] : [], ] : [],
...widget.message.isWarning() ? [
const Padding(
padding: EdgeInsets.only(left: 3),
child: Icon(
Icons.warning,
size: _bubbleBottomIconSize,
color: Colors.yellow,
),
),
] : [],
..._showCheckmark() ? [ ..._showCheckmark() ? [
const Padding( const Padding(
padding: EdgeInsets.only(left: 3), padding: EdgeInsets.only(left: 3),