Skip to content

Commit

Permalink
show 'verified by' information in profiles (#1949)
Browse files Browse the repository at this point in the history
* add 'verified' row to profiles

* show verfier information

* show verifier-information also if there is no chat with the contact

* open verifier contact on tap

* show name+address as verifier
  • Loading branch information
r10s authored Oct 29, 2023
1 parent a0223d1 commit 40314e7
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 2 deletions.
4 changes: 4 additions & 0 deletions DcCore/DcCore/DC/Wrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,10 @@ public class DcContact {
return dc_contact_is_verified(contactPointer) > 0
}

public func getVerifierId() -> Int {
return Int(dc_contact_get_verifier_id(contactPointer))
}

public var isBlocked: Bool {
return dc_contact_is_blocked(contactPointer) == 1
}
Expand Down
36 changes: 36 additions & 0 deletions deltachat-ios/Controller/ContactDetailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class ContactDetailViewController: UITableViewController {
return cell
}()

private lazy var verifiedByCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.imageView?.image = UIImage(named: "verified")?.scaleDownImage(toMax: 24)
return cell
}()

private lazy var allMediaCell: UITableViewCell = {
let cell = UITableViewCell(style: .value1, reuseIdentifier: nil)
cell.textLabel?.text = String.localized("media")
Expand Down Expand Up @@ -170,6 +176,8 @@ class ContactDetailViewController: UITableViewController {
switch cellType {
case .chatOptions:
switch viewModel.chatOptionFor(row: row) {
case .verifiedBy:
return verifiedByCell
case .allMedia:
return allMediaCell
case .ephemeralMessages:
Expand Down Expand Up @@ -309,6 +317,23 @@ class ContactDetailViewController: UITableViewController {
ephemeralMessagesCell.detailTextLabel?.text = String.localized(viewModel.chatIsEphemeral ? "on" : "off")
allMediaCell.detailTextLabel?.text = viewModel.chatId == 0 ? String.localized("none") : viewModel.context.getAllMediaCount(chatId: viewModel.chatId)
statusCell.setText(text: viewModel.isSavedMessages ? String.localized("saved_messages_explain") : viewModel.contact.status)

if viewModel.contact.isVerified {
let verifierId = viewModel.contact.getVerifierId()
let verifiedInfo: String
if verifierId == DC_CONTACT_ID_SELF {
verifiedByCell.accessoryType = .none
verifiedInfo = String.localized("verified_by_you")
} else if verifierId != 0 {
verifiedByCell.accessoryType = .disclosureIndicator
verifiedInfo = String.localizedStringWithFormat(String.localized("verified_by"),
viewModel.context.getContact(id: verifierId).nameNAddr)
} else {
verifiedByCell.accessoryType = .none
verifiedInfo = String.localized("vefified")
}
verifiedByCell.textLabel?.text = verifiedInfo
}
}

// MARK: - actions
Expand Down Expand Up @@ -339,6 +364,12 @@ class ContactDetailViewController: UITableViewController {
private func handleChatOption(indexPath: IndexPath) {
let action = viewModel.chatOptionFor(row: indexPath.row)
switch action {
case .verifiedBy:
tableView.deselectRow(at: indexPath, animated: true)
let verifierId = viewModel.contact.getVerifierId()
if verifierId != 0 && verifierId != DC_CONTACT_ID_SELF && verifierId != viewModel.contactId {
showContact(contactId: verifierId)
}
case .allMedia:
showAllMedia()
case .ephemeralMessages:
Expand Down Expand Up @@ -482,6 +513,11 @@ class ContactDetailViewController: UITableViewController {
}
}

private func showContact(contactId: Int) {
let contactViewController = ContactDetailViewController(dcContext: viewModel.context, contactId: contactId)
navigationController?.pushViewController(contactViewController, animated: true)
}

private func showEditContact(contactId: Int) {
let editContactController = EditContactController(dcContext: viewModel.context, contactIdForUpdate: contactId)
navigationController?.pushViewController(editContactController, animated: true)
Expand Down
9 changes: 7 additions & 2 deletions deltachat-ios/ViewModel/ContactDetailViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ContactDetailViewModel {
}

enum ChatOption {
case verifiedBy
case allMedia
case ephemeralMessages
case startChat
Expand Down Expand Up @@ -70,8 +71,12 @@ class ContactDetailViewModel {
}
sections.append(.chatActions)

chatOptions = []
if dcContact.isVerified {
chatOptions.append(.verifiedBy)
}
chatOptions.append(.allMedia)
if chatId != 0 {
chatOptions = [.allMedia]
if !isDeviceTalk {
chatOptions.append(.ephemeralMessages)
}
Expand All @@ -88,7 +93,7 @@ class ContactDetailViewModel {
chatActions.append(.clearChat)
chatActions.append(.deleteChat)
} else {
chatOptions = [.allMedia, .startChat]
chatOptions.append(.startChat)
chatActions = [.showEncrInfo, .copyToClipboard, .blockContact]
}
}
Expand Down

0 comments on commit 40314e7

Please sign in to comment.