mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-01-15 07:48:40 +00:00
improve logging
This commit is contained in:
parent
5371114e21
commit
f57c2fec79
11 changed files with 63 additions and 52 deletions
|
|
@ -119,11 +119,10 @@ class MessagesDao extends DatabaseAccessor<TwonlyDB> with _$MessagesDaoMixin {
|
|||
..where(
|
||||
(m) =>
|
||||
m.groupId.equals(group.groupId) &
|
||||
// m.messageId.equals(lastMessage.messageId).not() &
|
||||
(m.mediaStored.equals(true) &
|
||||
m.isDeletedFromSender.equals(true) |
|
||||
m.mediaStored.equals(false)) &
|
||||
(m.openedByAll.isSmallerThanValue(deletionTime) |
|
||||
(m.openedAt.isSmallerThanValue(deletionTime) |
|
||||
(m.isDeletedFromSender.equals(true) &
|
||||
m.createdAt.isSmallerThanValue(deletionTime))),
|
||||
))
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class ConnectPreKeyStore extends PreKeyStore {
|
|||
.get();
|
||||
if (preKeyRecord.isEmpty) {
|
||||
throw InvalidKeyIdException(
|
||||
'[PREKEY] No such preKey record! - $preKeyId',
|
||||
'[PREKEY] No such preKey record!',
|
||||
);
|
||||
}
|
||||
final preKey = preKeyRecord.first.preKey;
|
||||
|
|
|
|||
|
|
@ -78,12 +78,7 @@ class ApiService {
|
|||
await _channel!.ready;
|
||||
Log.info('websocket connected to $apiUrl');
|
||||
return true;
|
||||
} on WebSocketChannelException catch (e) {
|
||||
if (!e.message
|
||||
.toString()
|
||||
.contains('No address associated with hostname')) {
|
||||
Log.error('could not connect to api got: $e');
|
||||
}
|
||||
} catch (_) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -311,17 +306,17 @@ class ApiService {
|
|||
|
||||
final res = asResult(await _waitForResponse(seq));
|
||||
if (res.isError) {
|
||||
Log.error('got error from server: ${res.error}');
|
||||
Log.warn('Got error from server: ${res.error}');
|
||||
if (res.error == ErrorCode.AppVersionOutdated) {
|
||||
globalCallbackAppIsOutdated();
|
||||
Log.error('App Version is OUTDATED.');
|
||||
Log.warn('App Version is OUTDATED.');
|
||||
appIsOutdated = true;
|
||||
await close(() {});
|
||||
return Result.error(ErrorCode.InternalError);
|
||||
}
|
||||
if (res.error == ErrorCode.NewDeviceRegistered) {
|
||||
globalCallbackNewDeviceRegistered();
|
||||
Log.error(
|
||||
Log.warn(
|
||||
'Device is disabled, as a newer device restore twonly Backup.',
|
||||
);
|
||||
appIsOutdated = true;
|
||||
|
|
@ -336,13 +331,13 @@ class ApiService {
|
|||
// this will send the request one more time.
|
||||
return sendRequestSync(request, authenticated: false);
|
||||
} else {
|
||||
Log.error('session is not authenticated');
|
||||
Log.warn('Session is not authenticated');
|
||||
return Result.error(ErrorCode.InternalError);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (res.error == ErrorCode.UserIdNotFound && contactId != null) {
|
||||
Log.error('Contact deleted their account $contactId.');
|
||||
Log.warn('Contact deleted their account $contactId.');
|
||||
final contact = await twonlyDB.contactsDao
|
||||
.getContactByUserId(contactId)
|
||||
.getSingleOrNull();
|
||||
|
|
|
|||
|
|
@ -13,33 +13,45 @@ Future<void> handleMessageUpdate(
|
|||
Log.info(
|
||||
'Opened message $targetMessageId',
|
||||
);
|
||||
await twonlyDB.messagesDao.handleMessageOpened(
|
||||
contactId,
|
||||
targetMessageId,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
try {
|
||||
await twonlyDB.messagesDao.handleMessageOpened(
|
||||
contactId,
|
||||
targetMessageId,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
} catch (e) {
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
case EncryptedContent_MessageUpdate_Type.DELETE:
|
||||
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
||||
return;
|
||||
}
|
||||
Log.info('Delete message ${messageUpdate.senderMessageId}');
|
||||
await twonlyDB.messagesDao.handleMessageDeletion(
|
||||
contactId,
|
||||
messageUpdate.senderMessageId,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
try {
|
||||
await twonlyDB.messagesDao.handleMessageDeletion(
|
||||
contactId,
|
||||
messageUpdate.senderMessageId,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
} catch (e) {
|
||||
Log.warn(e);
|
||||
}
|
||||
case EncryptedContent_MessageUpdate_Type.EDIT_TEXT:
|
||||
if (!await isSender(contactId, messageUpdate.senderMessageId)) {
|
||||
return;
|
||||
}
|
||||
Log.info('Edit message ${messageUpdate.senderMessageId}');
|
||||
await twonlyDB.messagesDao.handleTextEdit(
|
||||
contactId,
|
||||
messageUpdate.senderMessageId,
|
||||
messageUpdate.text,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
try {
|
||||
await twonlyDB.messagesDao.handleTextEdit(
|
||||
contactId,
|
||||
messageUpdate.senderMessageId,
|
||||
messageUpdate.text,
|
||||
fromTimestamp(messageUpdate.timestamp),
|
||||
);
|
||||
} catch (e) {
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ Future<void> finishStartedPreprocessing() async {
|
|||
}
|
||||
await startBackgroundMediaUpload(service);
|
||||
} catch (e) {
|
||||
Log.error(e);
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ Future<(Uint8List, Uint8List?)?> tryToSendCompleteMessage({
|
|||
);
|
||||
|
||||
if (resp.isError) {
|
||||
Log.error('Could not transmit message $receiptId got ${resp.error}.');
|
||||
Log.warn('Could not transmit message got ${resp.error}.');
|
||||
if (resp.error == ErrorCode.UserIdNotFound) {
|
||||
await twonlyDB.receiptsDao.deleteReceipt(receiptId);
|
||||
await twonlyDB.contactsDao.updateContact(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:drift/drift.dart';
|
||||
import 'package:hashlib/random.dart';
|
||||
import 'package:mutex/mutex.dart';
|
||||
|
|
@ -63,7 +62,7 @@ Future<void> handleClient2ClientMessage(int fromUserId, Uint8List body) async {
|
|||
|
||||
await protectReceiptCheck.protect(() async {
|
||||
if (await twonlyDB.receiptsDao.isDuplicated(receiptId)) {
|
||||
Log.error('Got duplicated message from the server. Ignoring it.');
|
||||
Log.warn('Got duplicated message from the server.');
|
||||
return;
|
||||
}
|
||||
await twonlyDB.receiptsDao.gotReceipt(receiptId);
|
||||
|
|
@ -135,19 +134,23 @@ Future<void> handleClient2ClientMessage(int fromUserId, Uint8List body) async {
|
|||
..receiptId = receiptId
|
||||
..type = Message_Type.PLAINTEXT_CONTENT
|
||||
..plaintextContent = responsePlaintextContent;
|
||||
Log.error('Sending decryption error ($receiptId)');
|
||||
Log.error('Sending decryption error');
|
||||
} else {
|
||||
response = Message()..type = Message_Type.SENDER_DELIVERY_RECEIPT;
|
||||
}
|
||||
|
||||
await twonlyDB.receiptsDao.insertReceipt(
|
||||
ReceiptsCompanion(
|
||||
receiptId: Value(receiptId),
|
||||
contactId: Value(fromUserId),
|
||||
message: Value(response.writeToBuffer()),
|
||||
contactWillSendsReceipt: const Value(false),
|
||||
),
|
||||
);
|
||||
try {
|
||||
await twonlyDB.receiptsDao.insertReceipt(
|
||||
ReceiptsCompanion(
|
||||
receiptId: Value(receiptId),
|
||||
contactId: Value(fromUserId),
|
||||
message: Value(response.writeToBuffer()),
|
||||
contactWillSendsReceipt: const Value(false),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
Log.warn(e);
|
||||
}
|
||||
await tryToSendCompleteMessage(receiptId: receiptId);
|
||||
}
|
||||
case Message_Type.TEST_NOTIFICATION:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ Future<void> compressImage(
|
|||
|
||||
if (compressedBytes == null) {
|
||||
throw Exception(
|
||||
'Could not compress media file: $sourceFile. Sending original file.',
|
||||
'Could not compress media file: Sending original file.',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ Future<void> compressImage(
|
|||
|
||||
await destinationFile.writeAsBytes(compressedBytes);
|
||||
} catch (e) {
|
||||
Log.error('$e');
|
||||
Log.warn('$e');
|
||||
sourceFile.copySync(destinationFile.path);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ Future<Uint8List?> encryptPushNotification(
|
|||
content.kind != PushKind.testNotification) {
|
||||
// this will be enforced after every app uses this system... :/
|
||||
// return null;
|
||||
Log.error('Using insecure key as the receiver does not send a push key!');
|
||||
Log.warn('Using insecure key as the receiver does not send a push key!');
|
||||
|
||||
await sendCipherText(
|
||||
toUserId,
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Future<void> removeTwonlySafeFromServer() async {
|
|||
);
|
||||
Log.info('Download deleted with: ${response.statusCode}');
|
||||
} catch (e) {
|
||||
Log.error('Could not connect to the server.');
|
||||
Log.error('Could not connect upload the backup.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,13 @@ class _LastMessageTimeState extends State<LastMessageTime> {
|
|||
lastMessageInSeconds =
|
||||
DateTime.now().difference(widget.dateTime!).inSeconds;
|
||||
}
|
||||
setState(() {
|
||||
if (lastMessageInSeconds < 0) {
|
||||
lastMessageInSeconds = 0;
|
||||
}
|
||||
});
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
if (lastMessageInSeconds < 0) {
|
||||
lastMessageInSeconds = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue