From 71d1ad0854900a3e51a7c9a7bc5464e40e5a6cff Mon Sep 17 00:00:00 2001
From: Bruno Muniz Azevedo Filho <bruno@elixxir.io>
Date: Tue, 19 Jul 2022 13:24:32 -0300
Subject: [PATCH] Fixes issue where contact resets and disappears data

---
 Sources/Integration/Session/Session.swift | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/Sources/Integration/Session/Session.swift b/Sources/Integration/Session/Session.swift
index ef6180d7..e14c4901 100644
--- a/Sources/Integration/Session/Session.swift
+++ b/Sources/Integration/Session/Session.swift
@@ -403,9 +403,10 @@ public final class Session: SessionType {
                 /// This will get called when my contact restore its contact.
                 /// TODO: Hold a record on the chat that this contact restored.
                 ///
-                var contact = $0
-                contact.authStatus = .friend
-                _ = try? dbManager.saveContact(contact)
+                if var contact = try? dbManager.fetchContacts(.init(id: [$0.id])).first {
+                    contact.authStatus = .friend
+                    _ = try? dbManager.saveContact(contact)
+                }
             }.store(in: &cancellables)
 
         backupService.settingsPublisher
-- 
GitLab