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

Fixes comments on MR #52

parent 976bea20
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!52Fixes db issue where my contact wasn't created
This commit is part of merge request !52. Comments created here will be created in the context of that merge request.
......@@ -42,11 +42,10 @@ extension Session {
switch $0 {
case .success(_):
self.username = value
let query = Contact.Query(id: [self.client.bindings.myId])
if var myself = try? self.dbManager.fetchContacts(query).first {
myself.username = value
_ = try? self.dbManager.saveContact(myself)
if var me = try? self.myContact() {
me.username = value
_ = try? self.dbManager.saveContact(me)
}
completion(.success(nil))
......
......@@ -183,6 +183,15 @@ public final class Session: SessionType {
}
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()
networkMonitor.start()
......@@ -194,26 +203,6 @@ public final class Session: SessionType {
}
.store(in: &cancellables)
/// Create a contact for myself, for foreign key purposes
///
if var myself = try? dbManager.fetchContacts(.init(id: [client.bindings.myId])).first {
myself.username = username
_ = try? dbManager.saveContact(myself)
} else {
_ = try? dbManager.saveContact(.init(
id: client.bindings.myId,
marshaled: client.bindings.meMarshalled,
username: username,
email: email,
phone: phone,
nickname: nil,
photo: nil,
authStatus: .friend,
isRecent: false,
createdAt: Date()
))
}
registerUnfinishedUploadTransfers()
registerUnfinishedDownloadTransfers()
......@@ -487,4 +476,12 @@ public final class Session: SessionType {
}
.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