Skip to content

Commit

Permalink
Fix 2 crashes.
Browse files Browse the repository at this point in the history
1. MessageInteractor.uploadMessageAttachment(type:_:): BUG IN CLIENT OF LIBDISPATCH: dispatch_sync called on queue already owned by current thread
2. MessageInteractor.uploadMessageAttachment(type:_:)
  • Loading branch information
aforge committed Apr 10, 2023
1 parent e2cc7e4 commit d2a90a3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Tinodios/MessageInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ class MessageInteractor: DefaultComTopic.Listener, MessageBusinessLogic, Message
dg.leave()
})

dg.notify(queue: .main) { [weak self] in
dg.notify(queue: DispatchQueue.global(qos: .userInteractive)) { [weak self] in
let serverMessage = attachmentResult.result
let error = attachmentResult.error
let interactor = self ?? MessageInteractor.existingInteractor(for: topic.name)
Expand Down
26 changes: 19 additions & 7 deletions Tinodios/NewGroupViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,19 +219,31 @@ extension NewGroupViewController: EditMembersDelegate {
func editMembersDidEndEditing(_: UIView, added: [String], removed: [String]) {
selectedUids.formUnion(added)
selectedUids.subtract(removed)
var success = true
// A simple tableView.reloadData() results in a crash. Thus doing this crazy stuff.
let removedPaths = removed.map({(rem: String) -> IndexPath in
let row = selectedContacts.firstIndex(where: { h in h.uniqueId == rem })
assert(row != nil, "Removed non-existent user")
return IndexPath(row: row! + 1, section: 1)
if let row = selectedContacts.firstIndex(where: { h in h.uniqueId == rem }) {
return IndexPath(row: row + 1, section: 1)
} else {
success = false
UiUtils.showToast(message: "Removed non-existent user.")
return IndexPath(row: -1, section: 1)
}
})
guard success else { return }
let newSelection = ContactsManager.default.fetchContacts(withUids: selectedMembers) ?? []
let addedPaths = added.map({(add: String) -> IndexPath in
let row = newSelection.firstIndex(where: { h in h.uniqueId == add })
assert(row != nil, "Added non-existent user")
return IndexPath(row: row! + 1, section: 1)
if let row = newSelection.firstIndex(where: { h in h.uniqueId == add }) {
return IndexPath(row: row + 1, section: 1)
} else {
UiUtils.showToast(message: "Added non-existent user")
return IndexPath(row: -1, section: 1)
}
})
assert(selectedUids.count == newSelection.count)
guard success && selectedUids.count == newSelection.count else {
UiUtils.showToast(message: "Invalid member selection. Try again.")
return
}

tableView.beginUpdates()
selectedContacts = newSelection
Expand Down

0 comments on commit d2a90a3

Please sign in to comment.