|
@@ -393,6 +393,27 @@ class ChatListController: UITableViewController {
|
|
timer = nil
|
|
timer = nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public func handleMailto() {
|
|
|
|
+ if let mailtoAddress = RelayHelper.sharedInstance.mailtoAddress {
|
|
|
|
+ // FIXME: the line below should work
|
|
|
|
+ // var contactId = dcContext.lookupContactIdByAddress(mailtoAddress)
|
|
|
|
+
|
|
|
|
+ // workaround:
|
|
|
|
+ let contacts: [Int] = dcContext.getContacts(flags: DC_GCL_ADD_SELF, queryString: mailtoAddress)
|
|
|
|
+ let index = contacts.firstIndex(where: { dcContext.getContact(id: $0).email == mailtoAddress }) ?? -1
|
|
|
|
+ var contactId = 0
|
|
|
|
+ if index >= 0 {
|
|
|
|
+ contactId = contacts[index]
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if contactId != 0 && dcContext.getChatIdByContactId(contactId: contactId) != 0 {
|
|
|
|
+ showChat(chatId: dcContext.getChatIdByContactId(contactId: contactId), animated: false)
|
|
|
|
+ } else {
|
|
|
|
+ askToChatWith(address: mailtoAddress)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
// MARK: - alerts
|
|
// MARK: - alerts
|
|
private func showDeleteChatConfirmationAlert(chatId: Int) {
|
|
private func showDeleteChatConfirmationAlert(chatId: Int) {
|
|
let alert = UIAlertController(
|
|
let alert = UIAlertController(
|
|
@@ -429,24 +450,30 @@ class ChatListController: UITableViewController {
|
|
present(alert, animated: true, completion: nil)
|
|
present(alert, animated: true, completion: nil)
|
|
}
|
|
}
|
|
|
|
|
|
- private func askToChatWith(contactId: Int) {
|
|
|
|
- let dcContact = dcContext.getContact(id: contactId)
|
|
|
|
- let alert = UIAlertController(
|
|
|
|
- title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), dcContact.nameNAddr),
|
|
|
|
- message: nil,
|
|
|
|
- preferredStyle: .safeActionSheet)
|
|
|
|
- alert.addAction(UIAlertAction(
|
|
|
|
- title: String.localized("start_chat"),
|
|
|
|
- style: .default,
|
|
|
|
- handler: { _ in
|
|
|
|
- self.showNewChat(contactId: contactId)
|
|
|
|
|
|
+ private func askToChatWith(address: String, contactId: Int = 0) {
|
|
|
|
+ var contactId = contactId
|
|
|
|
+ let alert = UIAlertController(title: String.localizedStringWithFormat(String.localized("ask_start_chat_with"), address),
|
|
|
|
+ message: nil,
|
|
|
|
+ preferredStyle: .safeActionSheet)
|
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("start_chat"), style: .default, handler: { [weak self] _ in
|
|
|
|
+ guard let self = self else { return }
|
|
|
|
+ if contactId == 0 {
|
|
|
|
+ contactId = self.dcContext.createContact(name: nil, email: address)
|
|
|
|
+ }
|
|
|
|
+ self.showNewChat(contactId: contactId)
|
|
}))
|
|
}))
|
|
- alert.addAction(UIAlertAction(
|
|
|
|
- title: String.localized("cancel"),
|
|
|
|
- style: .cancel,
|
|
|
|
- handler: { _ in
|
|
|
|
|
|
+ alert.addAction(UIAlertAction(title: String.localized("cancel"), style: .cancel, handler: { _ in
|
|
|
|
+ if RelayHelper.sharedInstance.isMailtoHandling() {
|
|
|
|
+ RelayHelper.sharedInstance.finishMailto()
|
|
|
|
+ }
|
|
}))
|
|
}))
|
|
- self.present(alert, animated: true, completion: nil)
|
|
|
|
|
|
+ present(alert, animated: true, completion: nil)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private func askToChatWith(contactId: Int) {
|
|
|
|
+ let dcContact = dcContext.getContact(id: contactId)
|
|
|
|
+ askToChatWith(address: dcContact.nameNAddr, contactId: contactId)
|
|
}
|
|
}
|
|
|
|
|
|
private func deleteChat(chatId: Int, animated: Bool) {
|
|
private func deleteChat(chatId: Int, animated: Bool) {
|