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 final contact = await twonlyDB.contactsDao
.getContactByUserId(fromUserId) .getContactByUserId(fromUserId)
.getSingleOrNull(); .getSingleOrNull();
if (contact != null) {
await twonlyDB.groupsDao.createNewDirectChat( await twonlyDB.groupsDao.createNewDirectChat(
fromUserId, fromUserId,
GroupsCompanion( GroupsCompanion(
groupName: Value(getContactDisplayName(contact!)), groupName: Value(getContactDisplayName(contact)),
), ),
); );
}
case EncryptedContent_ContactRequest_Type.REJECT: case EncryptedContent_ContactRequest_Type.REJECT:
Log.info('Got a contact reject from $fromUserId'); Log.info('Got a contact reject from $fromUserId');
await twonlyDB.contactsDao.updateContact( await twonlyDB.contactsDao.updateContact(

View file

@ -139,12 +139,21 @@ Future<void> handleMediaUpdate(
.getMessageById(mediaUpdate.targetMessageId) .getMessageById(mediaUpdate.targetMessageId)
.getSingleOrNull(); .getSingleOrNull();
if (message == null) { 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.', '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 = final mediaFile =
await twonlyDB.mediaFilesDao.getMediaFileById(message!.mediaId!); await twonlyDB.mediaFilesDao.getMediaFileById(message.mediaId!);
if (mediaFile == null) { if (mediaFile == null) {
Log.info( Log.info(
'Got media file update, but media file was not found ${message.mediaId}', '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); await handleEncryptedFile(media.mediaId);
return; return;
} else { } else {
if (response.statusCode == 404 || if (response.statusCode == 404 || response.statusCode == 403) {
response.statusCode == 403 ||
response.statusCode == 400) {
Log.error( Log.error(
'Got ${response.statusCode} from server. Requesting upload again', 'Got ${response.statusCode} from server. Requesting upload again',
); );