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

Working on groups issue

parent 5945869c
No related branches found
No related tags found
2 merge requests!40v1.1.2b166,!38Using new database structure
...@@ -200,6 +200,29 @@ extension Session { ...@@ -200,6 +200,29 @@ extension Session {
} }
try client.bindings.removeContact(contact.marshaled!) try client.bindings.removeContact(contact.marshaled!)
try dbManager.deleteContact(contact)
/// Currently this cascades into deleting
/// all messages w/ contact.id == senderId
/// But this shouldn't be the always the case
/// because if we have a group / this contact
/// the messages will be gone as well.
///
/// Suggestion: If there's a group where this user belongs to
/// we will just cleanup the contact model stored on the db
/// leaving only username and id which are the equivalent to
/// .stranger contacts.
///
//try dbManager.deleteContact(contact)
_ = try? dbManager.deleteMessages(Message.Query(chat: .direct(myId, contact.id)))
var contact = contact
contact.email = nil
contact.phone = nil
contact.photo = nil
contact.isRecent = false
contact.marshaled = nil
contact.authStatus = .stranger
contact.nickname = contact.username
_ = try? dbManager.saveContact(contact)
} }
} }
...@@ -305,9 +305,11 @@ public final class Session: SessionType { ...@@ -305,9 +305,11 @@ public final class Session: SessionType {
private func setupBindings() { private func setupBindings() {
client.requests client.requests
.sink { [unowned self] in .sink { [unowned self] contact in
if let _ = try? dbManager.fetchContacts(.init(id: [$0.id])).first { let query = Contact.Query(id: [contact.id])
return
if let prexistent = try? dbManager.fetchContacts(query).first {
guard prexistent.authStatus == .stranger else { return }
} }
if self.inappnotifications { if self.inappnotifications {
...@@ -315,7 +317,7 @@ public final class Session: SessionType { ...@@ -315,7 +317,7 @@ public final class Session: SessionType {
DeviceFeedback.shake(.notification) DeviceFeedback.shake(.notification)
} }
verify(contact: $0) verify(contact: contact)
}.store(in: &cancellables) }.store(in: &cancellables)
client.requestsSent client.requestsSent
......
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