fix: null pointer

This commit is contained in:
otsmr 2026-02-12 21:54:53 +01:00
parent 0f16ab68b7
commit e6160990fe
3 changed files with 21 additions and 12 deletions

View file

@ -71,12 +71,14 @@ Future<bool> handleContactRequest(
final contact = await twonlyDB.contactsDao
.getContactByUserId(fromUserId)
.getSingleOrNull();
if (contact != null) {
await twonlyDB.groupsDao.createNewDirectChat(
fromUserId,
GroupsCompanion(
groupName: Value(getContactDisplayName(contact!)),
groupName: Value(getContactDisplayName(contact)),
),
);
}
case EncryptedContent_ContactRequest_Type.REJECT:
Log.info('Got a contact reject from $fromUserId');
await twonlyDB.contactsDao.updateContact(

View file

@ -139,12 +139,21 @@ Future<void> handleMediaUpdate(
.getMessageById(mediaUpdate.targetMessageId)
.getSingleOrNull();
if (message == null) {
Log.error(
// this can happen, in case the message was already deleted.
Log.info(
'Got media update to message ${mediaUpdate.targetMessageId} but message not found.',
);
return;
}
if (message.mediaId == null) {
// this can happen, in case the message was already deleted.
Log.warn(
'Got media update for message ${mediaUpdate.targetMessageId} which does not have a mediaId defined.',
);
return;
}
final mediaFile =
await twonlyDB.mediaFilesDao.getMediaFileById(message!.mediaId!);
await twonlyDB.mediaFilesDao.getMediaFileById(message.mediaId!);
if (mediaFile == null) {
Log.info(
'Got media file update, but media file was not found ${message.mediaId}',

View file

@ -231,9 +231,7 @@ Future<void> downloadFileFast(
await handleEncryptedFile(media.mediaId);
return;
} else {
if (response.statusCode == 404 ||
response.statusCode == 403 ||
response.statusCode == 400) {
if (response.statusCode == 404 || response.statusCode == 403) {
Log.error(
'Got ${response.statusCode} from server. Requesting upload again',
);