Don't crash on contact inserts.

This commit is contained in:
Burak Kaan Köse
2025-02-28 18:21:31 +01:00
parent 970a521b66
commit 6080646e89

View File

@@ -1,7 +1,9 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MimeKit; using MimeKit;
using Serilog;
using SqlKata; using SqlKata;
using Wino.Core.Domain.Entities.Shared; using Wino.Core.Domain.Entities.Shared;
using Wino.Core.Domain.Interfaces; using Wino.Core.Domain.Interfaces;
@@ -51,13 +53,20 @@ public class ContactService : BaseDatabaseService, IContactService
{ {
var currentContact = await GetAddressInformationByAddressAsync(info.Address).ConfigureAwait(false); var currentContact = await GetAddressInformationByAddressAsync(info.Address).ConfigureAwait(false);
if (currentContact == null) try
{ {
await Connection.InsertAsync(info).ConfigureAwait(false); if (currentContact == null)
{
await Connection.InsertAsync(info).ConfigureAwait(false);
}
else if (!currentContact.IsRootContact) // Don't update root contacts. They belong to accounts.
{
await Connection.InsertOrReplaceAsync(info).ConfigureAwait(false);
}
} }
else if (!currentContact.IsRootContact) // Don't update root contacts. They belong to accounts. catch (Exception ex)
{ {
await Connection.InsertOrReplaceAsync(info).ConfigureAwait(false); Log.Error("Failed to add contact information to the database.", ex);
} }
} }
} }