Skip to content
Snippets Groups Projects
Commit 8a8fc6fd authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Merge branch 'fix-bug-restore-own-contact' into 'development'

Fixes db issue where my contact wasn't created

See merge request elixxir/client-ios!52
parents c7b8637e 443d6f4b
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!52Fixes db issue where my contact wasn't created
...@@ -41,20 +41,13 @@ extension Session { ...@@ -41,20 +41,13 @@ extension Session {
switch $0 { switch $0 {
case .success(_): case .success(_):
_ = try? self.dbManager.saveContact(.init(
id: self.client.bindings.myId,
marshaled: self.client.bindings.meMarshalled,
username: value,
email: nil,
phone: nil,
nickname: nil,
photo: nil,
authStatus: .friend,
isRecent: false,
createdAt: Date()
))
self.username = value self.username = value
if var me = try? self.myContact() {
me.username = value
_ = try? self.dbManager.saveContact(me)
}
completion(.success(nil)) completion(.success(nil))
case .failure(let error): case .failure(let error):
completion(.failure(error)) completion(.failure(error))
......
...@@ -183,6 +183,15 @@ public final class Session: SessionType { ...@@ -183,6 +183,15 @@ public final class Session: SessionType {
} }
private func continueInitialization() throws { private func continueInitialization() throws {
var myContact = try self.myContact()
myContact.marshaled = client.bindings.meMarshalled
myContact.username = username
myContact.email = email
myContact.phone = phone
myContact.authStatus = .friend
myContact.isRecent = false
_ = try dbManager.saveContact(myContact)
setupBindings() setupBindings()
networkMonitor.start() networkMonitor.start()
...@@ -467,4 +476,12 @@ public final class Session: SessionType { ...@@ -467,4 +476,12 @@ public final class Session: SessionType {
} }
.store(in: &cancellables) .store(in: &cancellables)
} }
func myContact() throws -> Contact {
if let contact = try dbManager.fetchContacts(.init(id: [client.bindings.myId])).first {
return contact
} else {
return try dbManager.saveContact(.init(id: client.bindings.myId))
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment