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

Fixes db issue where my contact wasn't created

parent c7b8637e
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.
......@@ -41,20 +41,14 @@ extension Session {
switch $0 {
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
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)
}
completion(.success(nil))
case .failure(let error):
completion(.failure(error))
......
......@@ -194,6 +194,26 @@ 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()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment