feat(ui): Display warnings for messages
This commit is contained in:
parent
a0c7078593
commit
0327f254a2
@ -21,6 +21,7 @@ Future<void> createDatabase(Database db, int version) async {
|
||||
isFileUploadNotification INTEGER NOT NULL,
|
||||
encrypted INTEGER NOT NULL,
|
||||
errorType INTEGER,
|
||||
warningType INTEGER,
|
||||
mediaUrl TEXT,
|
||||
mediaType TEXT,
|
||||
thumbnailData TEXT,
|
||||
|
@ -260,6 +260,7 @@ class DatabaseService {
|
||||
String? quoteId,
|
||||
String? filename,
|
||||
int? errorType,
|
||||
int? warningType,
|
||||
Map<String, String>? plaintextHashes,
|
||||
Map<String, String>? ciphertextHashes,
|
||||
}
|
||||
@ -275,6 +276,7 @@ class DatabaseService {
|
||||
isFileUploadNotification,
|
||||
encrypted,
|
||||
errorType: errorType,
|
||||
warningType: warningType,
|
||||
mediaUrl: mediaUrl,
|
||||
key: key,
|
||||
iv: iv,
|
||||
@ -345,6 +347,7 @@ class DatabaseService {
|
||||
bool? displayed,
|
||||
bool? acked,
|
||||
int? errorType,
|
||||
int? warningType,
|
||||
bool? isFileUploadNotification,
|
||||
String? srcUrl,
|
||||
String? key,
|
||||
@ -379,6 +382,9 @@ class DatabaseService {
|
||||
if (errorType != null) {
|
||||
m['errorType'] = errorType;
|
||||
}
|
||||
if (warningType != null) {
|
||||
m['warningType'] = warningType;
|
||||
}
|
||||
if (isFileUploadNotification != null) {
|
||||
m['isFileUploadNotification'] = boolToInt(isFileUploadNotification);
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import 'package:moxxyv2/service/service.dart';
|
||||
import 'package:moxxyv2/shared/error_types.dart';
|
||||
import 'package:moxxyv2/shared/events.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/managers/namespaces.dart';
|
||||
import 'package:moxxyv2/xmpp/message.dart';
|
||||
@ -361,6 +362,7 @@ class HttpFileTransferService {
|
||||
// TODO(PapaTutuWawa): Trigger event
|
||||
_log.warning('HTTP GET of ${job.location.url} returned ${response?.statusCode}');
|
||||
} else {
|
||||
var integrityCheckPassed = true;
|
||||
if (job.location.key != null && job.location.iv != null) {
|
||||
// The file was encrypted
|
||||
final result = await GetIt.I.get<CryptographyService>().decryptFile(
|
||||
@ -387,6 +389,8 @@ class HttpFileTransferService {
|
||||
return;
|
||||
}
|
||||
|
||||
integrityCheckPassed = result.plaintextOkay && result.ciphertextOkay;
|
||||
|
||||
// TODO(PapaTutuWawa): Calculate the file's hash and compare to the provided ones
|
||||
// Cleanup the temporary file
|
||||
unawaited(Directory(pathlib.dirname(downloadPath)).delete(recursive: true));
|
||||
@ -422,6 +426,9 @@ class HttpFileTransferService {
|
||||
mediaWidth: mediaWidth,
|
||||
mediaHeight: mediaHeight,
|
||||
isFileUploadNotification: false,
|
||||
warningType: integrityCheckPassed ?
|
||||
warningFileIntegrityCheckFailed :
|
||||
null,
|
||||
);
|
||||
|
||||
sendEvent(MessageUpdatedEvent(message: msg.copyWith(isDownloading: false)));
|
||||
|
@ -51,6 +51,7 @@ class MessageService {
|
||||
String? quoteId,
|
||||
String? filename,
|
||||
int? errorType,
|
||||
int? warningType,
|
||||
Map<String, String>? plaintextHashes,
|
||||
Map<String, String>? ciphertextHashes,
|
||||
}
|
||||
@ -77,6 +78,7 @@ class MessageService {
|
||||
quoteId: quoteId,
|
||||
filename: filename,
|
||||
errorType: errorType,
|
||||
warningType: warningType,
|
||||
plaintextHashes: plaintextHashes,
|
||||
ciphertextHashes: ciphertextHashes,
|
||||
);
|
||||
@ -109,6 +111,7 @@ class MessageService {
|
||||
bool? displayed,
|
||||
bool? acked,
|
||||
int? errorType,
|
||||
int? warningType,
|
||||
bool? isFileUploadNotification,
|
||||
String? srcUrl,
|
||||
String? key,
|
||||
@ -125,6 +128,7 @@ class MessageService {
|
||||
displayed: displayed,
|
||||
acked: acked,
|
||||
errorType: errorType,
|
||||
warningType: warningType,
|
||||
isFileUploadNotification: isFileUploadNotification,
|
||||
srcUrl: srcUrl,
|
||||
key: key,
|
||||
|
@ -2,6 +2,7 @@ import 'dart:convert';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:moxxyv2/service/database/helpers.dart';
|
||||
import 'package:moxxyv2/shared/error_types.dart';
|
||||
import 'package:moxxyv2/shared/warning_types.dart';
|
||||
|
||||
part 'message.freezed.dart';
|
||||
part 'message.g.dart';
|
||||
@ -36,6 +37,7 @@ class Message with _$Message {
|
||||
bool encrypted,
|
||||
{
|
||||
int? errorType,
|
||||
int? warningType,
|
||||
String? mediaUrl,
|
||||
@Default(false) bool isDownloading,
|
||||
@Default(false) bool isUploading,
|
||||
@ -102,4 +104,9 @@ class Message with _$Message {
|
||||
bool isError() {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
2
lib/shared/warning_types.dart
Normal file
2
lib/shared/warning_types.dart
Normal file
@ -0,0 +1,2 @@
|
||||
const noWarning = 0;
|
||||
const warningFileIntegrityCheckFailed = 1;
|
@ -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() ? [
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 3),
|
||||
|
Loading…
Reference in New Issue
Block a user