Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mark bots as such, improve chat-deletion confirmation #2264

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions deltachat-ios/Chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,15 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
subtitle = String.localized("device_talk_subtitle")
} else if dcChat.isSelfTalk {
subtitle = String.localized("chat_self_talk_subtitle")
} else if !dcChat.isProtected && chatContactIds.count >= 1 {
subtitle = dcContext.getContact(id: chatContactIds[0]).email
} else if chatContactIds.count >= 1 {
let dcContact = dcContext.getContact(id: chatContactIds[0])
if dcContact.isBot {
subtitle = String.localized("bot")
} else if !dcChat.isProtected {
subtitle = dcContact.email
} else {
subtitle = nil
}
} else {
subtitle = nil
}
Expand Down Expand Up @@ -1364,7 +1371,8 @@ class ChatViewController: UITableViewController, UITableViewDropDelegate {
}

private func askToDeleteChat() {
let title = String.localized(stringID: "ask_delete_chat", parameter: 1)
let chat = dcContext.getChat(chatId: chatId)
let title = String.localizedStringWithFormat(String.localized("ask_delete_named_chat"), chat.name)
confirmationAlert(title: title, actionTitle: String.localized("delete"), actionStyle: .destructive,
actionHandler: { [weak self] _ in
guard let self else { return }
Expand Down
20 changes: 13 additions & 7 deletions deltachat-ios/Controller/ChatListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -742,15 +742,21 @@ class ChatListViewController: UITableViewController {
}

private func showDeleteMultipleChatConfirmationAlert() {
let selected = tableView.indexPathsForSelectedRows?.count ?? 0
if selected == 0 {
let selectedCount = tableView.indexPathsForSelectedRows?.count ?? 0
if selectedCount == 0 {
return
}
let alert = UIAlertController(
title: nil,
message: String.localized(stringID: "ask_delete_chat", parameter: selected),
preferredStyle: .safeActionSheet
)

let message: String
if selectedCount == 1,
let chatIds = viewModel?.chatIdsFor(indexPaths: tableView.indexPathsForSelectedRows),
let chatId = chatIds.first {
message = String.localizedStringWithFormat(String.localized("ask_delete_named_chat"), dcContext.getChat(chatId: chatId).name)
} else {
message = String.localized(stringID: "ask_delete_chat", parameter: selectedCount)
}

let alert = UIAlertController(title: nil, message: message, preferredStyle: .safeActionSheet)
alert.addAction(UIAlertAction(title: String.localized("delete"), style: .destructive, handler: { [weak self] _ in
guard let self, let viewModel = self.viewModel else { return }
viewModel.deleteChats(indexPaths: self.tableView.indexPathsForSelectedRows)
Expand Down
6 changes: 5 additions & 1 deletion deltachat-ios/Controller/ContactDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ class ContactDetailViewController: UITableViewController {
navigationItem.rightBarButtonItem = UIBarButtonItem(
title: String.localized("global_menu_edit_desktop"),
style: .plain, target: self, action: #selector(editButtonPressed))
self.title = String.localized("tab_contact")
if self.viewModel.isBot {
self.title = String.localized("bot")
} else {
self.title = String.localized("tab_contact")
}
} else {
self.title = String.localized("profile")
}
Expand Down
4 changes: 4 additions & 0 deletions deltachat-ios/DC/DcContact.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ public class DcContact {
return Int(dc_contact_get_verifier_id(contactPointer))
}

public var isBot: Bool {
return dc_contact_is_bot(contactPointer) != 0
}

public var isBlocked: Bool {
return dc_contact_is_blocked(contactPointer) == 1
}
Expand Down
2 changes: 2 additions & 0 deletions deltachat-ios/ViewModel/ContactDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class ContactDetailViewModel {
let chatId: Int
let isSavedMessages: Bool
let isDeviceTalk: Bool
let isBot: Bool
let greenCheckmark: Bool
var lastSeen: Int64
private var sharedChats: DcChatlist
Expand All @@ -61,6 +62,7 @@ class ContactDetailViewModel {
isDeviceTalk = false
greenCheckmark = dcContact.isVerified
}
self.isBot = dcContact.isBot
self.sharedChats = context.getChatlist(flags: 0, queryString: nil, queryId: contactId)

sections.append(.chatOptions)
Expand Down
Loading