diff --git a/Sources/Integration/Session/Session+Contacts.swift b/Sources/Integration/Session/Session+Contacts.swift index 2b507bdb2886be609ab4c3f0e7c313414f58dcdb..7bbe5254ab00b17b8053323586347ef819f10ff1 100644 --- a/Sources/Integration/Session/Session+Contacts.swift +++ b/Sources/Integration/Session/Session+Contacts.swift @@ -94,7 +94,7 @@ extension Session { } public func retryRequest(_ contact: Contact) throws { - log(string: "Retrying to request a contact", type: .info) + let name = (contact.nickname ?? contact.username) ?? "" client.bindings.add(contact.marshaled!, from: myQR) { [weak self, contact] in var contact = contact @@ -103,11 +103,21 @@ extension Session { do { switch $0 { case .success: - log(string: "Retrying to request a contact -- Success", type: .info) contact.authStatus = .requested - case .failure(let error): - log(string: "Retrying to request a contact -- Failed: \(error.localizedDescription)", type: .error) + + self.toastController.enqueueToast(model: .init( + title: Localized.Requests.Sent.Toast.resent(name), + leftImage: Asset.sharedSuccess.image + )) + + case .failure: contact.createdAt = Date() + + self.toastController.enqueueToast(model: .init( + title: Localized.Requests.Sent.Toast.resentFailed(name), + color: Asset.accentDanger.color, + leftImage: Asset.requestFailedToaster.image + )) } _ = try self.dbManager.saveContact(contact) diff --git a/Sources/SearchFeature/Controllers/SearchLeftController.swift b/Sources/SearchFeature/Controllers/SearchLeftController.swift index 0ca4f4b05c0d464f16b57a3dd6d74acfde177ca4..d305c6140292d3ec728224c60855b5b007b958e8 100644 --- a/Sources/SearchFeature/Controllers/SearchLeftController.swift +++ b/Sources/SearchFeature/Controllers/SearchLeftController.swift @@ -61,16 +61,31 @@ final class SearchLeftController: UIViewController { contact = connection } - let title = (contact.nickname ?? contact.username) ?? "" + let h1Text: String + var h2Text: String? + + h1Text = (contact.nickname ?? contact.username) ?? "" + + if let _ = contact.nickname, let username = contact.username { + h2Text = username + } cell.setup( - title: title, + title: h1Text, image: contact.photo, - firstSubtitle: contact.username, + firstSubtitle: h2Text, secondSubtitle: contact.email, thirdSubtitle: contact.phone, - showSeparator: false + showSeparator: false, + sent: contact.authStatus == .requested ) + + cell.didTapStateButton = { [weak self] in + guard let self = self else { return } + self.viewModel.didTapResend(contact: contact) + cell.updateToResent() + } + return cell } } @@ -396,6 +411,10 @@ extension SearchLeftController: UITableViewDelegate { } } + func tableView(_ tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) { + (view as! UITableViewHeaderFooterView).textLabel?.textColor = Asset.neutralWeak.color + } + private func didTap(contact: Contact) { guard contact.authStatus == .stranger else { coordinator.toContact(contact, from: self) diff --git a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift index 76be7aa947d2cb558e353030ae28574f0fa36558..b6d8a5f1526531f34af8c227e0347e3e92af2db3 100644 --- a/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift +++ b/Sources/SearchFeature/ViewModels/SearchLeftViewModel.swift @@ -78,6 +78,17 @@ final class SearchLeftViewModel { }.store(in: &searchCancellables) } + func didTapResend(contact: Contact) { + hudSubject.send(.on) + + do { + try self.session.retryRequest(contact) + hudSubject.send(.none) + } catch { + hudSubject.send(.error(.init(with: error))) + } + } + func didTapRequest(contact: Contact) { hudSubject.send(.on) var contact = contact diff --git a/Sources/Shared/AutoGenerated/Strings.swift b/Sources/Shared/AutoGenerated/Strings.swift index fdc5717f7ad533cba9eeee180e9b8e8fc8cb3648..ed861800297b7c53e92a0e83f19aa322de123ec4 100644 --- a/Sources/Shared/AutoGenerated/Strings.swift +++ b/Sources/Shared/AutoGenerated/Strings.swift @@ -965,6 +965,10 @@ public enum Localized { public static func resent(_ p1: Any) -> String { return Localized.tr("Localizable", "requests.sent.toast.resent", String(describing: p1)) } + /// Request couldn't be resent to %@ + public static func resentFailed(_ p1: Any) -> String { + return Localized.tr("Localizable", "requests.sent.toast.resentFailed", String(describing: p1)) + } /// Request successfully sent to %@ public static func sent(_ p1: Any) -> String { return Localized.tr("Localizable", "requests.sent.toast.sent", String(describing: p1)) diff --git a/Sources/Shared/Resources/en.lproj/Localizable.strings b/Sources/Shared/Resources/en.lproj/Localizable.strings index df7ee49277ef12881a8b7df7db61fe8aea3f2aa0..dd95d4002c125c9caa98007bf7074c172bf5aaf8 100644 --- a/Sources/Shared/Resources/en.lproj/Localizable.strings +++ b/Sources/Shared/Resources/en.lproj/Localizable.strings @@ -357,6 +357,8 @@ = "Request successfully sent to %@"; "requests.sent.toast.resent" = "Request successfully resent to %@"; +"requests.sent.toast.resentFailed" += "Request couldn't be resent to %@"; // RequestsFeature - Failed diff --git a/Sources/Shared/Views/AvatarCell.swift b/Sources/Shared/Views/AvatarCell.swift index d16e93b4cf617ef92cea8dcfa31c90bc702bde05..43f0e3fd6686464b6d66c31770627134e9c075c0 100644 --- a/Sources/Shared/Views/AvatarCell.swift +++ b/Sources/Shared/Views/AvatarCell.swift @@ -104,7 +104,8 @@ public final class AvatarCell: UITableViewCell { firstSubtitle: String? = nil, secondSubtitle: String? = nil, thirdSubtitle: String? = nil, - showSeparator: Bool = true + showSeparator: Bool = true, + sent: Bool = false ) { h1Label.text = title @@ -131,45 +132,28 @@ public final class AvatarCell: UITableViewCell { avatarView.setupProfile(title: title, image: image, size: .medium) separatorView.alpha = showSeparator ? 1.0 : 0.0 - } - public func setupForRequestSent(resent: Bool) { cancellables.removeAll() - var buttonTitle: String? = nil - var buttonImage: UIImage? = nil - var buttonTitleColor: UIColor? = nil + if sent { + stateButton.imageView.image = Asset.requestsResend.image + stateButton.titleLabel.text = Localized.Requests.Cell.requested + stateButton.titleLabel.textColor = Asset.brandPrimary.color - if resent { - buttonTitle = Localized.Requests.Cell.resent - buttonImage = Asset.requestsResent.image - buttonTitleColor = Asset.neutralWeak.color - } else { - buttonTitle = Localized.Requests.Cell.requested - buttonImage = Asset.requestsResend.image - buttonTitleColor = Asset.brandPrimary.color + stateButton + .publisher(for: .touchUpInside) + .sink { [unowned self] in didTapStateButton() } + .store(in: &cancellables) } - - setupStateButton( - image: buttonImage, - title: buttonTitle, - color: buttonTitleColor - ) } - private func setupStateButton( - image: UIImage?, - title: String?, - color: UIColor? - ) { - stateButton.imageView.image = image - stateButton.titleLabel.text = title - stateButton.titleLabel.textColor = color - - stateButton - .publisher(for: .touchUpInside) - .sink { [unowned self] in didTapStateButton() } - .store(in: &cancellables) + public func updateToResent() { + stateButton.imageView.image = Asset.requestsResent.image + stateButton.titleLabel.text = Localized.Requests.Cell.resent + stateButton.titleLabel.textColor = Asset.neutralWeak.color + + cancellables.forEach { $0.cancel() } + cancellables.removeAll() } private func setupConstraints() {