From 3c9d270070ca63cb55b301c3cb2870f8608fb987 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Wed, 7 Sep 2022 18:31:40 -0300 Subject: [PATCH 01/17] Add localized strings, chenge enum name to add all talk page strings --- Wikipedia/Code/TalkPageViewController.swift | 33 +++++++++++-------- .../en.lproj/Localizable.strings | 6 +++- .../qqq.lproj/Localizable.strings | 6 +++- 3 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 90eee635fad..8fac34bc2bb 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -23,13 +23,13 @@ class TalkPageViewController: ViewController { // MARK: - Overflow menu properties fileprivate var userTalkOverflowSubmenuActions: [UIAction] { - let contributionsAction = UIAction(title: MenuLocalizedStrings.contributions, image: UIImage(named: "user-contributions"), handler: { _ in + let contributionsAction = UIAction(title: TalkPageLocalizedStrings.contributions, image: UIImage(named: "user-contributions"), handler: { _ in }) - let userGroupsAction = UIAction(title: MenuLocalizedStrings.userGroups, image: UIImage(systemName: "person.2"), handler: { _ in + let userGroupsAction = UIAction(title: TalkPageLocalizedStrings.userGroups, image: UIImage(systemName: "person.2"), handler: { _ in }) - let logsAction = UIAction(title: MenuLocalizedStrings.logs, image: UIImage(systemName: "list.bullet"), handler: { _ in + let logsAction = UIAction(title: TalkPageLocalizedStrings.logs, image: UIImage(systemName: "list.bullet"), handler: { _ in }) return [contributionsAction, userGroupsAction, logsAction] @@ -37,30 +37,30 @@ class TalkPageViewController: ViewController { fileprivate var overflowSubmenuActions: [UIAction] { - let goToArchivesAction = UIAction(title: MenuLocalizedStrings.archives, image: UIImage(systemName: "archivebox"), handler: { _ in + let goToArchivesAction = UIAction(title: TalkPageLocalizedStrings.archives, image: UIImage(systemName: "archivebox"), handler: { _ in }) - let pageInfoAction = UIAction(title: MenuLocalizedStrings.pageInfo, image: UIImage(systemName: "info.circle"), handler: { _ in + let pageInfoAction = UIAction(title: TalkPageLocalizedStrings.pageInfo, image: UIImage(systemName: "info.circle"), handler: { _ in }) - let goToPermalinkAction = UIAction(title: MenuLocalizedStrings.permaLink, image: UIImage(systemName: "link"), handler: { _ in + let goToPermalinkAction = UIAction(title: TalkPageLocalizedStrings.permaLink, image: UIImage(systemName: "link"), handler: { _ in }) - let relatedLinksAction = UIAction(title: MenuLocalizedStrings.relatedLinks, image: UIImage(systemName: "arrowshape.turn.up.forward"), handler: { _ in + let relatedLinksAction = UIAction(title: TalkPageLocalizedStrings.relatedLinks, image: UIImage(systemName: "arrowshape.turn.up.forward"), handler: { _ in }) var actions = [goToArchivesAction, pageInfoAction, goToPermalinkAction, relatedLinksAction] if viewModel.pageType == .user { - let aboutTalkUserPagesAction = UIAction(title: MenuLocalizedStrings.aboutUserTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in + let aboutTalkUserPagesAction = UIAction(title: TalkPageLocalizedStrings.aboutUserTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in }) actions.insert(contentsOf: userTalkOverflowSubmenuActions, at: 1) actions.append(aboutTalkUserPagesAction) } else { - let changeLanguageAction = UIAction(title: MenuLocalizedStrings.changeLanguage, image: UIImage(named: "language-talk-page"), handler: { _ in + let changeLanguageAction = UIAction(title: TalkPageLocalizedStrings.changeLanguage, image: UIImage(named: "language-talk-page"), handler: { _ in }) - let aboutTalkPagesAction = UIAction(title: MenuLocalizedStrings.aboutArticleTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in + let aboutTalkPagesAction = UIAction(title: TalkPageLocalizedStrings.aboutArticleTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in }) actions.insert(changeLanguageAction, at: 3) @@ -71,7 +71,7 @@ class TalkPageViewController: ViewController { var overflowMenu: UIMenu { - let openAllAction = UIAction(title: MenuLocalizedStrings.openAllThreads, image: UIImage(systemName: "square.stack"), handler: { _ in + let openAllAction = UIAction(title: TalkPageLocalizedStrings.openAllThreads, image: UIImage(systemName: "square.stack"), handler: { _ in }) @@ -79,7 +79,7 @@ class TalkPageViewController: ViewController { }) - let openInWebAction = UIAction(title: MenuLocalizedStrings.readInWeb, image: UIImage(systemName: "display"), handler: { _ in + let openInWebAction = UIAction(title: TalkPageLocalizedStrings.readInWeb, image: UIImage(systemName: "display"), handler: { _ in }) @@ -329,9 +329,9 @@ extension TalkPageViewController: TalkPageReplyComposeDelegate { } extension TalkPageViewController { - enum MenuLocalizedStrings { + enum TalkPageLocalizedStrings { static let openAllThreads = WMFLocalizedString("talk-page-menu-open-all", value: "Open all threads", comment: "Title for menu option open all talk page threads") - static let readInWeb = WMFLocalizedString("talk-page-open-in-web", value: "Read in web", comment: "Title for menu option to open a talk page in a web browser") + static let readInWeb = WMFLocalizedString("talk-page-read-in-web", value: "Read in web", comment: "Title for menu option to read a talk page in a web browser") static let archives = WMFLocalizedString("talk-page-archives", value: "Archives", comment: "Title for menu option that redirects to talk page archives") static let pageInfo = WMFLocalizedString("talk-page-page-info", value: "Page information", comment: "Title for menu option to go to the talk page information link") static let permaLink = WMFLocalizedString("talk-page-permanent-link", value: "Permanent link", comment: "Title for menu option to open the talk page's permanent link in a web browser") @@ -342,5 +342,10 @@ extension TalkPageViewController { static let contributions = WMFLocalizedString("talk-page-user-contributions", value: "Contributions", comment: "Title for menu option for information on the user's contributions") static let userGroups = WMFLocalizedString("talk-pages-user-groups", value: "User groups", comment: "Title for menu option for information on the user's user groups") static let logs = WMFLocalizedString("talk-pages-user-logs", value: "Logs", comment: "Title for menu option to consult the user's public logs") + + static let subscribedAlertTitle = WMFLocalizedString("talk-page-subscribed-alert-title", value: "You have subscribed!", comment: "Title for alert informing that the user subscribed to a topic") + static let unsubscribedAlertTitle = WMFLocalizedString("talk-page-unsubscribed-alert-title", value: "You have unsubscribed.", comment: "Title for alert informing that the user unsubscribed to a topic") + static let subscribedAlertSubtitle = WMFLocalizedString("talk-page-subscribed-alert-subtitle", value: "You will receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will receive notifications for a subscribed topic") + static let unsubscribedAlertSubtitle = WMFLocalizedString("talk-page-unsubscribed-alert-subtitle", value: "ou will no longer receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will no longer receive notifications for a topic") } } diff --git a/Wikipedia/Localizations/en.lproj/Localizable.strings b/Wikipedia/Localizations/en.lproj/Localizable.strings index 2a76550dfc2..2bdd7ed0a93 100644 --- a/Wikipedia/Localizations/en.lproj/Localizable.strings +++ b/Wikipedia/Localizations/en.lproj/Localizable.strings @@ -998,10 +998,10 @@ "talk-page-new-topic-body-placeholder-text" = "Compose new discussion"; "talk-page-new-topic-success-text" = "Your discussion was successfully published"; "talk-page-new-topic-title" = "New discussion"; -"talk-page-open-in-web" = "Read in web"; "talk-page-page-info" = "Page information"; "talk-page-permanent-link" = "Permanent link"; "talk-page-publish-terms-and-licenses" = "By saving changes, you agree to the $1Terms of Use$2, and agree to release your contribution under the $3CC BY-SA 3.0$4 and the $5GFDL$6 licenses."; +"talk-page-read-in-web" = "Read in web"; "talk-page-related-links" = "What links here"; "talk-page-reply-button" = "Reply"; "talk-page-reply-terms-and-licenses" = "Note your reply will be automatically signed with your username. By saving changes, you agree to the $1Terms of Use$2, and agree to release your contribution under the $3CC BY-SA 3.0$4 and the $5GFDL$6 licenses."; @@ -1009,10 +1009,14 @@ "talk-page-revision-history" = "Revision history"; "talk-page-share-button" = "Share talk page"; "talk-page-subscribe-to-topic" = "Subscribe"; +"talk-page-subscribed-alert-subtitle" = "You will receive notifications about new comments in this topic."; +"talk-page-subscribed-alert-title" = "You have subscribed!"; "talk-page-title-article-talk" = "Article Talk"; "talk-page-title-user-talk" = "User Talk"; "talk-page-topic-title" = "Discussion"; "talk-page-unsubscribe-to-topic" = "Unsubscribe"; +"talk-page-unsubscribed-alert-subtitle" = "ou will no longer receive notifications about new comments in this topic."; +"talk-page-unsubscribed-alert-title" = "You have unsubscribed."; "talk-page-user-about" = "About user talk pages"; "talk-page-user-contributions" = "Contributions"; "talk-pages-coffee-roll-read-more" = "Read more"; diff --git a/Wikipedia/Localizations/qqq.lproj/Localizable.strings b/Wikipedia/Localizations/qqq.lproj/Localizable.strings index dd136f3032e..fe94fa07e4b 100644 --- a/Wikipedia/Localizations/qqq.lproj/Localizable.strings +++ b/Wikipedia/Localizations/qqq.lproj/Localizable.strings @@ -998,10 +998,10 @@ "talk-page-new-topic-body-placeholder-text" = "Placeholder text which appears initially in the new topic body field for talk pages."; "talk-page-new-topic-success-text" = "Banner text that appears after a new discussion was successfully published on a talk page."; "talk-page-new-topic-title" = "Title of page when composing a new topic on talk pages."; -"talk-page-open-in-web" = "Title for menu option to open a talk page in a web browser"; "talk-page-page-info" = "Title for menu option to go to the talk page information link"; "talk-page-permanent-link" = "Title for menu option to open the talk page's permanent link in a web browser"; "talk-page-publish-terms-and-licenses" = "Text for information about the Terms of Use and edit licenses on talk pages. Parameters:\n* $1 - app-specific non-text formatting, $2 - app-specific non-text formatting, $3 - app-specific non-text formatting, $4 - app-specific non-text formatting, $5 - app-specific non-text formatting, $6 - app-specific non-text formatting."; +"talk-page-read-in-web" = "Title for menu option to read a talk page in a web browser"; "talk-page-related-links" = "Title for menu option that redirects to a page that shows related links"; "talk-page-reply-button" = "Text used on button to reply to talk page messages."; "talk-page-reply-terms-and-licenses" = "Text for information about the Terms of Use and edit licenses on talk pages when replying. Parameters:\n* $1 - app-specific non-text formatting, $2 - app-specific non-text formatting, $3 - app-specific non-text formatting, $4 - app-specific non-text formatting, $5 - app-specific non-text formatting, $6 - app-specific non-text formatting."; @@ -1009,10 +1009,14 @@ "talk-page-revision-history" = "Title for option that leads to talk pages revision history"; "talk-page-share-button" = "Title for share talk page button"; "talk-page-subscribe-to-topic" = "Text used on button to subscribe to talk page topic."; +"talk-page-subscribed-alert-subtitle" = "Subtitle for alert informing that the user will receive notifications for a subscribed topic"; +"talk-page-subscribed-alert-title" = "Title for alert informing that the user subscribed to a topic"; "talk-page-title-article-talk" = "This title label is displayed at the top of a talk page topic list, if the talk page type is an article talk page."; "talk-page-title-user-talk" = "This title label is displayed at the top of a talk page topic list, if the talk page type is a user talk page."; "talk-page-topic-title" = "This header label is displayed at the top of a talk page topic thread."; "talk-page-unsubscribe-to-topic" = "Text used on button to unsubscribe from talk page topic."; +"talk-page-unsubscribed-alert-subtitle" = "Subtitle for alert informing that the user will no longer receive notifications for a topic"; +"talk-page-unsubscribed-alert-title" = "Title for alert informing that the user unsubscribed to a topic"; "talk-page-user-about" = "Title for menu option for information on user talk pages"; "talk-page-user-contributions" = "Title for menu option for information on the user's contributions"; "talk-pages-coffee-roll-read-more" = "Title of user and article talk pages button to read more of the coffee roll."; From da51b096e24fd435e4665902e3e01586f7c988c2 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Wed, 7 Sep 2022 18:32:16 -0300 Subject: [PATCH 02/17] Add alert to subscription action --- Wikipedia/Code/TalkPageViewController.swift | 12 ++++++++++++ Wikipedia/Code/WMFAlertManager.swift | 6 ++++++ .../en.lproj/Localizable.strings | Bin 381686 -> 383070 bytes 3 files changed, 18 insertions(+) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 8fac34bc2bb..324e2030990 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -302,6 +302,18 @@ extension TalkPageViewController: TalkPageCellDelegate { configuredCellViewModel.isSubscribed.toggle() cell.configure(viewModel: configuredCellViewModel) + + let title = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle + let subtitle = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle + + let image = configuredCellViewModel.isSubscribed ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") + + if UIAccessibility.isVoiceOverRunning { + UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) + } else { + WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) + + } } } diff --git a/Wikipedia/Code/WMFAlertManager.swift b/Wikipedia/Code/WMFAlertManager.swift index 0f87106ecbd..7eeba8f336f 100644 --- a/Wikipedia/Code/WMFAlertManager.swift +++ b/Wikipedia/Code/WMFAlertManager.swift @@ -79,6 +79,12 @@ open class WMFAlertManager: NSObject, RMessageProtocol, Themeable { RMessage.showNotification(in: nil, title: message, subtitle: nil, iconImage: nil, type: .error, customTypeName: nil, duration: sticky ? -1 : 2, callback: tapCallBack, buttonTitle: nil, buttonCallback: nil, at: .top, canBeDismissedByUser: true) }) } + + @objc func showBottomAlertWithMessage(_ message: String, subtitle: String, image: UIImage, dismissPreviousAlerts:Bool, tapCallBack: (() -> Void)? = nil) { + showAlert(dismissPreviousAlerts, alertBlock: { () -> Void in + RMessage.showNotification(withTitle: message, subtitle: subtitle, iconImage: UIImage(named: "language"), type: .normal, customTypeName: nil, duration: 10, callback: tapCallBack, buttonTitle: nil, buttonCallback: nil, at: .bottom, canBeDismissedByUser: true) + }) + } @objc func showAlert(_ dismissPreviousAlerts:Bool, alertBlock: @escaping () -> Void) { DispatchQueue.main.async { diff --git a/Wikipedia/iOS Native Localizations/en.lproj/Localizable.strings b/Wikipedia/iOS Native Localizations/en.lproj/Localizable.strings index 4c6944e6c6c28a326e603ac700b916a6be802b49..130bc156c3fe81fafbfe1a55b7fea3c98ea0f41e 100644 GIT binary patch delta 686 zcmeyiRQ%os@rD-07N!>F7M3lnZ=9xQ&1Dps{-=XkWcw>;Rt~o54Ngof>_rTz42cXW z(=Y0>N>Ar=X0@AM;KjroK<=Hh1pC()5W}j{(NwYiH%Wly1q860EGYEuow2F7l4ETgaU*Egaot&>_V5$Lj?+#)GY-VmqJMeJ_~OEZ~$chZU8L+ zX_o=l0u`5_Nd;1ufI6iNla372p!1qzqgR|T?@CgB#B dp!fn5w_aBTf&-VptO6jH4oL+Jx6oY$j(Q^4Dgyuj From 92b20c00e59c60a2a21dd1eb342f9fad48e92bd3 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Wed, 7 Sep 2022 18:38:15 -0300 Subject: [PATCH 03/17] Move strings to enum --- Wikipedia/Code/TalkPageViewController.swift | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 324e2030990..c3ca9ea885d 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -111,7 +111,7 @@ class TalkPageViewController: ViewController { override func viewDidLoad() { super.viewDidLoad() - navigationItem.title = WMFLocalizedString("talk-pages-view-title", value: "Talk", comment: "Title of user and article talk pages view.") + navigationItem.title = TalkPageLocalizedStrings.title // Not adding fallback for other versions since we're dropping iOS 13 on the next release // TODO: this version check should be removed @@ -234,10 +234,10 @@ class TalkPageViewController: ViewController { toolbar.items = [shareButton, .flexibleSpaceToolbar(), revisionButton, .flexibleSpaceToolbar(), findButton,.flexibleSpaceToolbar(), addTopicButton] - shareButton.accessibilityLabel = WMFLocalizedString("talk-page-share-button", value: "Share talk page", comment: "Title for share talk page button") - findButton.accessibilityLabel = WMFLocalizedString("talk-page-find-in-page-button", value: "Find in page", comment: "Title for find content in page button") + shareButton.accessibilityLabel = TalkPageLocalizedStrings.shareButtonAccesibilityLabel + findButton.accessibilityLabel = TalkPageLocalizedStrings.findButtonAccesibilityLabel revisionButton.accessibilityLabel = CommonStrings.revisionHistory - addTopicButton.accessibilityLabel = WMFLocalizedString("talk-page-add-topic-button", value: "Add topic", comment: "Title for add topic to talk page button") + addTopicButton.accessibilityLabel = TalkPageLocalizedStrings.addTopicButtonAccesibilityLabel } } @@ -342,6 +342,7 @@ extension TalkPageViewController: TalkPageReplyComposeDelegate { extension TalkPageViewController { enum TalkPageLocalizedStrings { + static let title = WMFLocalizedString("talk-pages-view-title", value: "Talk", comment: "Title of user and article talk pages view.") static let openAllThreads = WMFLocalizedString("talk-page-menu-open-all", value: "Open all threads", comment: "Title for menu option open all talk page threads") static let readInWeb = WMFLocalizedString("talk-page-read-in-web", value: "Read in web", comment: "Title for menu option to read a talk page in a web browser") static let archives = WMFLocalizedString("talk-page-archives", value: "Archives", comment: "Title for menu option that redirects to talk page archives") @@ -359,5 +360,9 @@ extension TalkPageViewController { static let unsubscribedAlertTitle = WMFLocalizedString("talk-page-unsubscribed-alert-title", value: "You have unsubscribed.", comment: "Title for alert informing that the user unsubscribed to a topic") static let subscribedAlertSubtitle = WMFLocalizedString("talk-page-subscribed-alert-subtitle", value: "You will receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will receive notifications for a subscribed topic") static let unsubscribedAlertSubtitle = WMFLocalizedString("talk-page-unsubscribed-alert-subtitle", value: "ou will no longer receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will no longer receive notifications for a topic") + + static let shareButtonAccesibilityLabel = WMFLocalizedString("talk-page-share-button", value: "Share talk page", comment: "Title for share talk page button") + static let findButtonAccesibilityLabel = WMFLocalizedString("talk-page-find-in-page-button", value: "Find in page", comment: "Title for find content in page button") + static let addTopicButtonAccesibilityLabel = WMFLocalizedString("talk-page-add-topic-button", value: "Add topic", comment: "Title for add topic to talk page button") } } From f6585c4898fd21d64091d98b50ecd9216b2027c3 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 14:12:29 -0300 Subject: [PATCH 04/17] Add call to API to subscribe to topic --- Wikipedia/Code/TalkPageViewController.swift | 35 +++++++++++++-------- Wikipedia/Code/TalkPageViewModel.swift | 13 ++++++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index c3ca9ea885d..31ce837034a 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -1,5 +1,6 @@ import UIKit import WMF +import CocoaLumberjackSwift class TalkPageViewController: ViewController { @@ -299,20 +300,28 @@ extension TalkPageViewController: TalkPageCellDelegate { } let configuredCellViewModel = viewModel.topics[indexOfConfiguredCell] - configuredCellViewModel.isSubscribed.toggle() - cell.configure(viewModel: configuredCellViewModel) - - let title = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle - let subtitle = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle - - let image = configuredCellViewModel.isSubscribed ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") - - if UIAccessibility.isVoiceOverRunning { - UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) - } else { - WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) - + let shouldSubscribe = !configuredCellViewModel.isSubscribed + viewModel.updateSubscriptionToTopic(topic: configuredCellViewModel.topicTitle, shouldSubscribe: shouldSubscribe) { result in + switch result { + case .failure(let error): + DDLogError("Failure updating subscription: \(error)") + //TODO: Handle error state + case .success: + cell.configure(viewModel: configuredCellViewModel) + + let title = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle + let subtitle = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle + + let image = configuredCellViewModel.isSubscribed ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") + + if UIAccessibility.isVoiceOverRunning { + UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) + } else { + WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) + + } + } } } } diff --git a/Wikipedia/Code/TalkPageViewModel.swift b/Wikipedia/Code/TalkPageViewModel.swift index c7f96c30e03..e250207d860 100644 --- a/Wikipedia/Code/TalkPageViewModel.swift +++ b/Wikipedia/Code/TalkPageViewModel.swift @@ -76,6 +76,19 @@ final class TalkPageViewModel { } } + func updateSubscriptionToTopic(topic: String, shouldSubscribe: Bool, completion: @escaping (Result) -> Void) { + dataController.subscribeToTopic(topicName: topic, shouldSubscribe: shouldSubscribe) { [self] result in + switch result { + case let .success(result) : + let topicUpdated = topics.filter { $0.topicTitle == topic} + topicUpdated[0].isSubscribed = result + completion(.success(result)) + case let .failure(error): + completion(.failure(error)) + } + } + } + // MARK: - Private private func populateHeaderData(articleSummary: WMFArticle?, items: [TalkPageItem]) { From ab508618c95679bbed9b196ce8d2f90f5dc129e5 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 14:22:31 -0300 Subject: [PATCH 05/17] Refactor alert logic to separate function --- Wikipedia/Code/TalkPageViewController.swift | 112 +++++++++--------- Wikipedia/Code/WMFAlertManager.swift | 2 +- .../en.lproj/Localizable.strings | 2 +- .../en.lproj/Localizable.strings | Bin 383070 -> 383072 bytes 4 files changed, 60 insertions(+), 56 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 31ce837034a..14b6158cea4 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -3,9 +3,9 @@ import WMF import CocoaLumberjackSwift class TalkPageViewController: ViewController { - + // MARK: - Properties - + fileprivate let viewModel: TalkPageViewModel fileprivate var headerView: TalkPageHeaderView? @@ -26,16 +26,16 @@ class TalkPageViewController: ViewController { fileprivate var userTalkOverflowSubmenuActions: [UIAction] { let contributionsAction = UIAction(title: TalkPageLocalizedStrings.contributions, image: UIImage(named: "user-contributions"), handler: { _ in }) - + let userGroupsAction = UIAction(title: TalkPageLocalizedStrings.userGroups, image: UIImage(systemName: "person.2"), handler: { _ in }) - + let logsAction = UIAction(title: TalkPageLocalizedStrings.logs, image: UIImage(systemName: "list.bullet"), handler: { _ in }) - + return [contributionsAction, userGroupsAction, logsAction] } - + fileprivate var overflowSubmenuActions: [UIAction] { let goToArchivesAction = UIAction(title: TalkPageLocalizedStrings.archives, image: UIImage(systemName: "archivebox"), handler: { _ in @@ -73,7 +73,7 @@ class TalkPageViewController: ViewController { var overflowMenu: UIMenu { let openAllAction = UIAction(title: TalkPageLocalizedStrings.openAllThreads, image: UIImage(systemName: "square.stack"), handler: { _ in - + }) let revisionHistoryAction = UIAction(title: CommonStrings.revisionHistory, image: UIImage(systemName: "clock.arrow.circlepath"), handler: { _ in @@ -86,34 +86,34 @@ class TalkPageViewController: ViewController { let submenu = UIMenu(title: String(), options: .displayInline, children: overflowSubmenuActions) let mainMenu = UIMenu(title: String(), children: [openAllAction, revisionHistoryAction, openInWebAction, submenu]) - + return mainMenu } - + // MARK: - Lifecycle - + init(theme: Theme, viewModel: TalkPageViewModel) { self.viewModel = viewModel super.init(theme: theme) viewModel.delegate = self } - + required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + override func loadView() { let talkPageView = TalkPageView(frame: UIScreen.main.bounds) view = talkPageView scrollView = talkPageView.collectionView } - + override func viewDidLoad() { super.viewDidLoad() - + navigationItem.title = TalkPageLocalizedStrings.title - + // Not adding fallback for other versions since we're dropping iOS 13 on the next release // TODO: this version check should be removed if #available(iOS 14.0, *) { @@ -121,43 +121,43 @@ class TalkPageViewController: ViewController { navigationItem.rightBarButtonItem = rightBarButtonItem rightBarButtonItem.tintColor = theme.colors.link } - + talkPageView.collectionView.dataSource = self talkPageView.collectionView.delegate = self - + // Needed for reply compose views to display on top of navigation bar. navigationController?.setNavigationBarHidden(true, animated: false) navigationMode = .forceBar - + viewModel.fetchTalkPage() setupToolbar() } - + private func setupHeaderView() { let headerView = TalkPageHeaderView() self.headerView = headerView - + headerView.configure(viewModel: viewModel) navigationBar.isBarHidingEnabled = false navigationBar.isUnderBarViewHidingEnabled = true navigationBar.allowsUnderbarHitsFallThrough = true - + navigationBar.addUnderNavigationBarView(headerView, shouldIgnoreSafeArea: true) useNavigationBarVisibleHeightForScrollViewInsets = false updateScrollViewInsets() - + headerView.apply(theme: theme) } - + // MARK: - Public - - + + // MARK: - Themeable - + override func apply(theme: Theme) { super.apply(theme: theme) - + viewModel.theme = theme headerView?.apply(theme: theme) talkPageView.apply(theme: theme) @@ -207,7 +207,7 @@ class TalkPageViewController: ViewController { talkPageURLComponents?.path = "/wiki/\(viewModel.pageTitle)" return talkPageURLComponents?.url } - + @objc fileprivate func userDidTapShareButton() { guard let talkPageURL = talkPageURL else { return @@ -240,38 +240,38 @@ class TalkPageViewController: ViewController { revisionButton.accessibilityLabel = CommonStrings.revisionHistory addTopicButton.accessibilityLabel = TalkPageLocalizedStrings.addTopicButtonAccesibilityLabel } - + } // MARK: - UICollectionViewDelegate, UICollectionViewDataSource extension TalkPageViewController: UICollectionViewDelegate, UICollectionViewDataSource { - + func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return viewModel.topics.count } - + func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TalkPageCell.reuseIdentifier, for: indexPath) as? TalkPageCell else { - return UICollectionViewCell() + return UICollectionViewCell() } - + let viewModel = viewModel.topics[indexPath.row] - + cell.delegate = self cell.replyDelegate = self cell.configure(viewModel: viewModel) cell.apply(theme: theme) - + return cell } - + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let cell = collectionView.cellForItem(at: indexPath) as? TalkPageCell else { return } - + userDidTapDisclosureButton(cellViewModel: cell.viewModel, cell: cell) } @@ -281,12 +281,12 @@ extension TalkPageViewController: UICollectionViewDelegate, UICollectionViewData // TODO extension TalkPageViewController: TalkPageCellDelegate { - + func userDidTapDisclosureButton(cellViewModel: TalkPageCellViewModel?, cell: TalkPageCell) { guard let cellViewModel = cellViewModel, let indexOfConfiguredCell = viewModel.topics.firstIndex(where: {$0 === cellViewModel}) else { return } - + let configuredCellViewModel = viewModel.topics[indexOfConfiguredCell] configuredCellViewModel.isThreadExpanded.toggle() @@ -298,7 +298,7 @@ extension TalkPageViewController: TalkPageCellDelegate { guard let cellViewModel = cellViewModel, let indexOfConfiguredCell = viewModel.topics.firstIndex(where: {$0 === cellViewModel}) else { return } - + let configuredCellViewModel = viewModel.topics[indexOfConfiguredCell] let shouldSubscribe = !configuredCellViewModel.isSubscribed @@ -306,24 +306,28 @@ extension TalkPageViewController: TalkPageCellDelegate { switch result { case .failure(let error): DDLogError("Failure updating subscription: \(error)") - //TODO: Handle error state + // TODO: Handle error state case .success: - cell.configure(viewModel: configuredCellViewModel) - - let title = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle - let subtitle = configuredCellViewModel.isSubscribed ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle - - let image = configuredCellViewModel.isSubscribed ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") - - if UIAccessibility.isVoiceOverRunning { - UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) - } else { - WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) - + DispatchQueue.main.async { + cell.configure(viewModel: configuredCellViewModel) + self.handleSubscriptionAlert(isSubscribedToTopic: configuredCellViewModel.isSubscribed) } } } } + + fileprivate func handleSubscriptionAlert(isSubscribedToTopic: Bool) { + let title = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle + let subtitle = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle + let image = isSubscribedToTopic ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") + + if UIAccessibility.isVoiceOverRunning { + UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) + } else { + WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) + } + } + } extension TalkPageViewController: TalkPageViewModelDelegate { @@ -368,7 +372,7 @@ extension TalkPageViewController { static let subscribedAlertTitle = WMFLocalizedString("talk-page-subscribed-alert-title", value: "You have subscribed!", comment: "Title for alert informing that the user subscribed to a topic") static let unsubscribedAlertTitle = WMFLocalizedString("talk-page-unsubscribed-alert-title", value: "You have unsubscribed.", comment: "Title for alert informing that the user unsubscribed to a topic") static let subscribedAlertSubtitle = WMFLocalizedString("talk-page-subscribed-alert-subtitle", value: "You will receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will receive notifications for a subscribed topic") - static let unsubscribedAlertSubtitle = WMFLocalizedString("talk-page-unsubscribed-alert-subtitle", value: "ou will no longer receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will no longer receive notifications for a topic") + static let unsubscribedAlertSubtitle = WMFLocalizedString("talk-page-unsubscribed-alert-subtitle", value: "You will no longer receive notifications about new comments in this topic.", comment: "Subtitle for alert informing that the user will no longer receive notifications for a topic") static let shareButtonAccesibilityLabel = WMFLocalizedString("talk-page-share-button", value: "Share talk page", comment: "Title for share talk page button") static let findButtonAccesibilityLabel = WMFLocalizedString("talk-page-find-in-page-button", value: "Find in page", comment: "Title for find content in page button") diff --git a/Wikipedia/Code/WMFAlertManager.swift b/Wikipedia/Code/WMFAlertManager.swift index 7eeba8f336f..8cd3a02c07c 100644 --- a/Wikipedia/Code/WMFAlertManager.swift +++ b/Wikipedia/Code/WMFAlertManager.swift @@ -82,7 +82,7 @@ open class WMFAlertManager: NSObject, RMessageProtocol, Themeable { @objc func showBottomAlertWithMessage(_ message: String, subtitle: String, image: UIImage, dismissPreviousAlerts:Bool, tapCallBack: (() -> Void)? = nil) { showAlert(dismissPreviousAlerts, alertBlock: { () -> Void in - RMessage.showNotification(withTitle: message, subtitle: subtitle, iconImage: UIImage(named: "language"), type: .normal, customTypeName: nil, duration: 10, callback: tapCallBack, buttonTitle: nil, buttonCallback: nil, at: .bottom, canBeDismissedByUser: true) + RMessage.showNotification(withTitle: message, subtitle: subtitle, iconImage: image, type: .normal, customTypeName: nil, duration: 5, callback: tapCallBack, buttonTitle: nil, buttonCallback: nil, at: .bottom, canBeDismissedByUser: true) }) } diff --git a/Wikipedia/Localizations/en.lproj/Localizable.strings b/Wikipedia/Localizations/en.lproj/Localizable.strings index 2bdd7ed0a93..7407cdb3465 100644 --- a/Wikipedia/Localizations/en.lproj/Localizable.strings +++ b/Wikipedia/Localizations/en.lproj/Localizable.strings @@ -1015,7 +1015,7 @@ "talk-page-title-user-talk" = "User Talk"; "talk-page-topic-title" = "Discussion"; "talk-page-unsubscribe-to-topic" = "Unsubscribe"; -"talk-page-unsubscribed-alert-subtitle" = "ou will no longer receive notifications about new comments in this topic."; +"talk-page-unsubscribed-alert-subtitle" = "You will no longer receive notifications about new comments in this topic."; "talk-page-unsubscribed-alert-title" = "You have unsubscribed."; "talk-page-user-about" = "About user talk pages"; "talk-page-user-contributions" = "Contributions"; diff --git a/Wikipedia/iOS Native Localizations/en.lproj/Localizable.strings b/Wikipedia/iOS Native Localizations/en.lproj/Localizable.strings index 130bc156c3fe81fafbfe1a55b7fea3c98ea0f41e..04eb311c9176104fdab234a1f374e799713e43ff 100644 GIT binary patch delta 35 rcmcb&LHxl6@rD-07N!>F7M3lnU!td9n9am7{apwv*LIc|)~Ff)4oMBw delta 25 hcmaE`LHynZ@rD-07N!>F7M3lnU!u2vi)PKL0RWN#3gQ3& From 3cbc4e9b47a2cc1a49499070fdee02fca3eb4e0d Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 14:25:26 -0300 Subject: [PATCH 06/17] Move function out of extension to class --- Wikipedia/Code/TalkPageViewController.swift | 25 ++++++++++----------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 14b6158cea4..6e6c1d084e9 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -241,6 +241,18 @@ class TalkPageViewController: ViewController { addTopicButton.accessibilityLabel = TalkPageLocalizedStrings.addTopicButtonAccesibilityLabel } + fileprivate func handleSubscriptionAlert(isSubscribedToTopic: Bool) { + let title = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle + let subtitle = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle + let image = isSubscribedToTopic ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") + + if UIAccessibility.isVoiceOverRunning { + UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) + } else { + WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) + } + } + } // MARK: - UICollectionViewDelegate, UICollectionViewDataSource @@ -315,19 +327,6 @@ extension TalkPageViewController: TalkPageCellDelegate { } } } - - fileprivate func handleSubscriptionAlert(isSubscribedToTopic: Bool) { - let title = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertTitle : TalkPageLocalizedStrings.unsubscribedAlertTitle - let subtitle = isSubscribedToTopic ? TalkPageLocalizedStrings.subscribedAlertSubtitle : TalkPageLocalizedStrings.unsubscribedAlertSubtitle - let image = isSubscribedToTopic ? UIImage(systemName: "bell.fill") : UIImage(systemName: "bell.slash.fill") - - if UIAccessibility.isVoiceOverRunning { - UIAccessibility.post(notification: UIAccessibility.Notification.announcement, argument: title) - } else { - WMFAlertManager.sharedInstance.showBottomAlertWithMessage(title, subtitle: subtitle, image: image ?? UIImage(), dismissPreviousAlerts: true) - } - } - } extension TalkPageViewController: TalkPageViewModelDelegate { From af5dd2c8b7128b6764aff83e031d4de369307b9e Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 14:26:57 -0300 Subject: [PATCH 07/17] remove orphaned todo comment --- Wikipedia/Code/TalkPageViewController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 6e6c1d084e9..4d78e0e81ed 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -291,7 +291,6 @@ extension TalkPageViewController: UICollectionViewDelegate, UICollectionViewData // MARK: - TalkPageCellDelegate -// TODO extension TalkPageViewController: TalkPageCellDelegate { func userDidTapDisclosureButton(cellViewModel: TalkPageCellViewModel?, cell: TalkPageCell) { From a2be971e28a7d7f4ed2c8565c4410d3aaaafc009 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 14:33:45 -0300 Subject: [PATCH 08/17] Remove whitespace --- Wikipedia/Code/TalkPageViewController.swift | 69 ++++++++++----------- 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 4d78e0e81ed..4e129dd0672 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -3,9 +3,9 @@ import WMF import CocoaLumberjackSwift class TalkPageViewController: ViewController { - + // MARK: - Properties - + fileprivate let viewModel: TalkPageViewModel fileprivate var headerView: TalkPageHeaderView? @@ -26,35 +26,35 @@ class TalkPageViewController: ViewController { fileprivate var userTalkOverflowSubmenuActions: [UIAction] { let contributionsAction = UIAction(title: TalkPageLocalizedStrings.contributions, image: UIImage(named: "user-contributions"), handler: { _ in }) - + let userGroupsAction = UIAction(title: TalkPageLocalizedStrings.userGroups, image: UIImage(systemName: "person.2"), handler: { _ in }) - + let logsAction = UIAction(title: TalkPageLocalizedStrings.logs, image: UIImage(systemName: "list.bullet"), handler: { _ in }) - + return [contributionsAction, userGroupsAction, logsAction] } - + fileprivate var overflowSubmenuActions: [UIAction] { - + let goToArchivesAction = UIAction(title: TalkPageLocalizedStrings.archives, image: UIImage(systemName: "archivebox"), handler: { _ in }) - + let pageInfoAction = UIAction(title: TalkPageLocalizedStrings.pageInfo, image: UIImage(systemName: "info.circle"), handler: { _ in }) - + let goToPermalinkAction = UIAction(title: TalkPageLocalizedStrings.permaLink, image: UIImage(systemName: "link"), handler: { _ in }) - + let relatedLinksAction = UIAction(title: TalkPageLocalizedStrings.relatedLinks, image: UIImage(systemName: "arrowshape.turn.up.forward"), handler: { _ in }) - + var actions = [goToArchivesAction, pageInfoAction, goToPermalinkAction, relatedLinksAction] - + if viewModel.pageType == .user { let aboutTalkUserPagesAction = UIAction(title: TalkPageLocalizedStrings.aboutUserTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in - + }) actions.insert(contentsOf: userTalkOverflowSubmenuActions, at: 1) actions.append(aboutTalkUserPagesAction) @@ -62,18 +62,18 @@ class TalkPageViewController: ViewController { let changeLanguageAction = UIAction(title: TalkPageLocalizedStrings.changeLanguage, image: UIImage(named: "language-talk-page"), handler: { _ in }) let aboutTalkPagesAction = UIAction(title: TalkPageLocalizedStrings.aboutArticleTalk, image: UIImage(systemName: "doc.plaintext"), handler: { _ in - + }) actions.insert(changeLanguageAction, at: 3) actions.append(aboutTalkPagesAction) } return actions } - + var overflowMenu: UIMenu { let openAllAction = UIAction(title: TalkPageLocalizedStrings.openAllThreads, image: UIImage(systemName: "square.stack"), handler: { _ in - + }) let revisionHistoryAction = UIAction(title: CommonStrings.revisionHistory, image: UIImage(systemName: "clock.arrow.circlepath"), handler: { _ in @@ -86,12 +86,12 @@ class TalkPageViewController: ViewController { let submenu = UIMenu(title: String(), options: .displayInline, children: overflowSubmenuActions) let mainMenu = UIMenu(title: String(), children: [openAllAction, revisionHistoryAction, openInWebAction, submenu]) - + return mainMenu } - + // MARK: - Lifecycle - + init(theme: Theme, viewModel: TalkPageViewModel) { self.viewModel = viewModel super.init(theme: theme) @@ -111,9 +111,9 @@ class TalkPageViewController: ViewController { override func viewDidLoad() { super.viewDidLoad() - + navigationItem.title = TalkPageLocalizedStrings.title - + // Not adding fallback for other versions since we're dropping iOS 13 on the next release // TODO: this version check should be removed if #available(iOS 14.0, *) { @@ -121,19 +121,19 @@ class TalkPageViewController: ViewController { navigationItem.rightBarButtonItem = rightBarButtonItem rightBarButtonItem.tintColor = theme.colors.link } - + talkPageView.collectionView.dataSource = self talkPageView.collectionView.delegate = self - + // Needed for reply compose views to display on top of navigation bar. navigationController?.setNavigationBarHidden(true, animated: false) navigationMode = .forceBar - + viewModel.fetchTalkPage() setupToolbar() } - + private func setupHeaderView() { let headerView = TalkPageHeaderView() self.headerView = headerView @@ -149,12 +149,11 @@ class TalkPageViewController: ViewController { headerView.apply(theme: theme) } - + // MARK: - Public - - + // MARK: - Themeable - + override func apply(theme: Theme) { super.apply(theme: theme) @@ -267,18 +266,18 @@ extension TalkPageViewController: UICollectionViewDelegate, UICollectionViewData guard let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TalkPageCell.reuseIdentifier, for: indexPath) as? TalkPageCell else { return UICollectionViewCell() } - + let viewModel = viewModel.topics[indexPath.row] - + cell.delegate = self cell.replyDelegate = self - + cell.configure(viewModel: viewModel) cell.apply(theme: theme) - + return cell } - + func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { guard let cell = collectionView.cellForItem(at: indexPath) as? TalkPageCell else { return @@ -304,7 +303,7 @@ extension TalkPageViewController: TalkPageCellDelegate { cell.configure(viewModel: configuredCellViewModel) talkPageView.collectionView.collectionViewLayout.invalidateLayout() } - + func userDidTapSubscribeButton(cellViewModel: TalkPageCellViewModel?, cell: TalkPageCell) { guard let cellViewModel = cellViewModel, let indexOfConfiguredCell = viewModel.topics.firstIndex(where: {$0 === cellViewModel}) else { return From 60dcba5f1930bf6200df61a31171da23bdcfaa43 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Thu, 8 Sep 2022 15:09:40 -0300 Subject: [PATCH 09/17] Add fetchSubscriptions method to data controller --- Wikipedia/Code/TalkPageDataController.swift | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Wikipedia/Code/TalkPageDataController.swift b/Wikipedia/Code/TalkPageDataController.swift index 27514614d89..e3dca456bf5 100644 --- a/Wikipedia/Code/TalkPageDataController.swift +++ b/Wikipedia/Code/TalkPageDataController.swift @@ -65,6 +65,17 @@ class TalkPageDataController { talkPageFetcher.subscribeToTopic(talkPageTitle: pageTitle, siteURL: siteURL, topic: topicName, shouldSubscribe: shouldSubscribe, completion: completion) } + func fetchSubscriptions(for topics: [String], completion: @escaping (Result<[String], Error>) -> Void) { + talkPageFetcher.getSubscribedTopics(siteURL: siteURL, topics: topics) { result in + switch result { + case let .success(result): + completion(.success(result)) + case let .failure(error): + completion(.failure(error)) + } + } + } + // MARK: Private private func fetchTalkPageItems(dispatchGroup group: DispatchGroup, completion: @escaping ([TalkPageItem], [Error]) -> Void) { From 75732f1cf23c3118f86db3fa482f330d87cc26fc Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 10:28:49 -0300 Subject: [PATCH 10/17] Remove call to API from talk page vc --- Wikipedia/Code/TalkPageViewController.swift | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index 4e129dd0672..e9330cdfded 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -310,20 +310,8 @@ extension TalkPageViewController: TalkPageCellDelegate { } let configuredCellViewModel = viewModel.topics[indexOfConfiguredCell] - - let shouldSubscribe = !configuredCellViewModel.isSubscribed - viewModel.updateSubscriptionToTopic(topic: configuredCellViewModel.topicTitle, shouldSubscribe: shouldSubscribe) { result in - switch result { - case .failure(let error): - DDLogError("Failure updating subscription: \(error)") - // TODO: Handle error state - case .success: - DispatchQueue.main.async { - cell.configure(viewModel: configuredCellViewModel) - self.handleSubscriptionAlert(isSubscribedToTopic: configuredCellViewModel.isSubscribed) - } - } - } + cell.configure(viewModel: configuredCellViewModel) + self.handleSubscriptionAlert(isSubscribedToTopic: configuredCellViewModel.isSubscribed) } } From df1037c3b40477d1639380aa18c3a6913e8ad846 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 12:39:43 -0300 Subject: [PATCH 11/17] Fix RMessage alert view icon dispaly issue --- Wikipedia/Third Party Code/RMessage/RMessageView.m | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index 85401f6818f..f3124651b33 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -633,7 +633,7 @@ - (void)setupImagesAndBackground _iconImageView.clipsToBounds = YES; } else { self.iconRelativeCornerRadius = 0.f; - _iconImageView.clipsToBounds = NO; + _iconImageView.clipsToBounds = YES; } [self setupIconImageView]; } @@ -765,7 +765,7 @@ - (void)setupIconImageView constant:15.f]; NSLayoutConstraint *imgViewTrailing = [NSLayoutConstraint constraintWithItem:self.iconImageView attribute:NSLayoutAttributeTrailing - relatedBy:NSLayoutRelationEqual + relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:self.titleSubtitleContainerView attribute:NSLayoutAttributeLeading multiplier:1.f @@ -777,8 +777,16 @@ - (void)setupIconImageView attribute:NSLayoutAttributeBottom multiplier:1.f constant:-10.f]; + NSLayoutConstraint *titleViewLeading = [NSLayoutConstraint constraintWithItem:self.titleSubtitleContainerView + attribute:NSLayoutAttributeLeading + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeLeading + multiplier:1.f + constant:50.f]; + [self addSubview:self.iconImageView]; - [[self class] activateConstraints:@[imgViewCenterY, imgViewLeading, imgViewTrailing, imgViewBottom] inSuperview:self]; + [[self class] activateConstraints:@[imgViewCenterY, imgViewLeading, imgViewTrailing, imgViewBottom, titleViewLeading] inSuperview:self]; } - (void)setupGestureRecognizers From 74a055e3155e8f1fd7162658fce075555dda1a99 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 12:41:57 -0300 Subject: [PATCH 12/17] Keep consistent identation in file --- Wikipedia/Third Party Code/RMessage/RMessageView.m | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index f3124651b33..beeb795c890 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -777,13 +777,13 @@ - (void)setupIconImageView attribute:NSLayoutAttributeBottom multiplier:1.f constant:-10.f]; - NSLayoutConstraint *titleViewLeading = [NSLayoutConstraint constraintWithItem:self.titleSubtitleContainerView - attribute:NSLayoutAttributeLeading - relatedBy:NSLayoutRelationEqual - toItem:self - attribute:NSLayoutAttributeLeading - multiplier:1.f - constant:50.f]; + NSLayoutConstraint *titleViewLeading = [NSLayoutConstraint constraintWithItem:self.titleSubtitleContainerView + attribute:NSLayoutAttributeLeading + relatedBy:NSLayoutRelationEqual + toItem:self + attribute:NSLayoutAttributeLeading + multiplier:1.f + constant:50.f]; [self addSubview:self.iconImageView]; [[self class] activateConstraints:@[imgViewCenterY, imgViewLeading, imgViewTrailing, imgViewBottom, titleViewLeading] inSuperview:self]; From fd3999f03de2b8f423de353cb6c7e939a1f34a77 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 14:58:16 -0300 Subject: [PATCH 13/17] Add bottom padding to RMessage alert --- Wikipedia/Third Party Code/RMessage/RMessageView.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index beeb795c890..80036109d04 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -894,7 +894,8 @@ - (void)layoutMessageForNavigationControllerPresentation // If tool bar present animate above toolbar offset -= messageNavigationController.toolbar.bounds.size.height; } - self.topToVCFinalConstant = offset; + CGFloat safeAreaExtraPadding = 30.0f; + self.topToVCFinalConstant = offset - safeAreaExtraPadding; [self.viewController.view addSubview:self]; } } @@ -904,6 +905,8 @@ - (void)layoutMessageForStandardPresentation [self layoutIfNeeded]; if (self.messagePosition == RMessagePositionBottom) { self.topToVCFinalConstant = -self.bounds.size.height - [self customVerticalOffset]; + self.titleSubtitleContainerViewCenterYConstraint.constant = + [UIApplication sharedApplication].statusBarFrame.size.height / 2.f; } else { self.topToVCFinalConstant = [self customVerticalOffset]; self.titleSubtitleContainerViewCenterYConstraint.constant = From 4a72f4a7aa2c78921d309551e8347a15e0944aa5 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 15:03:42 -0300 Subject: [PATCH 14/17] Revert change --- Wikipedia/Code/TalkPageViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/Wikipedia/Code/TalkPageViewController.swift b/Wikipedia/Code/TalkPageViewController.swift index e9330cdfded..ad4963d1c83 100644 --- a/Wikipedia/Code/TalkPageViewController.swift +++ b/Wikipedia/Code/TalkPageViewController.swift @@ -310,6 +310,7 @@ extension TalkPageViewController: TalkPageCellDelegate { } let configuredCellViewModel = viewModel.topics[indexOfConfiguredCell] + configuredCellViewModel.isSubscribed.toggle() cell.configure(viewModel: configuredCellViewModel) self.handleSubscriptionAlert(isSubscribedToTopic: configuredCellViewModel.isSubscribed) } From 4f284f1541f1b9f61e8ff6e4646f0ccd188af134 Mon Sep 17 00:00:00 2001 From: mazevedo Date: Fri, 9 Sep 2022 15:09:32 -0300 Subject: [PATCH 15/17] remove uncessary code --- Wikipedia/Third Party Code/RMessage/RMessageView.m | 2 -- 1 file changed, 2 deletions(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index 80036109d04..6b3ba940ee3 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -905,8 +905,6 @@ - (void)layoutMessageForStandardPresentation [self layoutIfNeeded]; if (self.messagePosition == RMessagePositionBottom) { self.topToVCFinalConstant = -self.bounds.size.height - [self customVerticalOffset]; - self.titleSubtitleContainerViewCenterYConstraint.constant = - [UIApplication sharedApplication].statusBarFrame.size.height / 2.f; } else { self.topToVCFinalConstant = [self customVerticalOffset]; self.titleSubtitleContainerViewCenterYConstraint.constant = From 966837e476e136e6fc6ca85f7f3777771bf8810b Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Fri, 9 Sep 2022 15:11:53 -0500 Subject: [PATCH 16/17] Minor tweaks for bottom safe area & leading space for icon --- .../Third Party Code/RMessage/RMessageView.m | 21 ++++++++----------- .../RMessage/RMessageView.xib | 16 +++++++------- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index 6b3ba940ee3..c0fe81948be 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -29,6 +29,7 @@ @interface RMessageView () @property (nonatomic, weak) IBOutlet UILabel *subtitleLabel; @property (nonatomic, weak) IBOutlet UIButton *button; @property (nonatomic, weak) IBOutlet UIStackView *stackView; +@property (weak, nonatomic) IBOutlet NSLayoutConstraint *titleSubtitleContainerViewLeadingConstraint; @property (nonatomic, weak) IBOutlet NSLayoutConstraint *titleSubtitleContainerViewCenterYConstraint; @property (weak, nonatomic) IBOutlet UIImageView *closeImageView; @@ -448,7 +449,7 @@ - (void)setupLayout self.topToVCLayoutConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual - toItem:self.superview + toItem:self.superview.safeAreaLayoutGuide attribute:NSLayoutAttributeBottom multiplier:1.f constant:0.f]; @@ -461,6 +462,7 @@ - (void)setupLayout attribute:NSLayoutAttributeCenterX multiplier:1.f constant:0.f]; + centerXConstraint.identifier = @"RMessageView to superview centerX"; NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual @@ -468,6 +470,7 @@ - (void)setupLayout attribute:NSLayoutAttributeLeading multiplier:1.f constant:0.f]; + leadingConstraint.identifier = @"RMessageView to superview leading"; NSLayoutConstraint *trailingConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual @@ -475,6 +478,7 @@ - (void)setupLayout attribute:NSLayoutAttributeTrailing multiplier:1.f constant:0.f]; + trailingConstraint.identifier = @"RMessageView to superview trailing"; [[self class] activateConstraints:@[centerXConstraint, leadingConstraint, trailingConstraint, self.topToVCLayoutConstraint] inSuperview:self.superview]; @@ -759,7 +763,7 @@ - (void)setupIconImageView NSLayoutConstraint *imgViewLeading = [NSLayoutConstraint constraintWithItem:self.iconImageView attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual - toItem:self + toItem:self.safeAreaLayoutGuide attribute:NSLayoutAttributeLeading multiplier:1.f constant:15.f]; @@ -777,16 +781,10 @@ - (void)setupIconImageView attribute:NSLayoutAttributeBottom multiplier:1.f constant:-10.f]; - NSLayoutConstraint *titleViewLeading = [NSLayoutConstraint constraintWithItem:self.titleSubtitleContainerView - attribute:NSLayoutAttributeLeading - relatedBy:NSLayoutRelationEqual - toItem:self - attribute:NSLayoutAttributeLeading - multiplier:1.f - constant:50.f]; + self.titleSubtitleContainerViewLeadingConstraint.constant = 50.0; [self addSubview:self.iconImageView]; - [[self class] activateConstraints:@[imgViewCenterY, imgViewLeading, imgViewTrailing, imgViewBottom, titleViewLeading] inSuperview:self]; + [[self class] activateConstraints:@[imgViewCenterY, imgViewLeading, imgViewTrailing, imgViewBottom] inSuperview:self]; } - (void)setupGestureRecognizers @@ -894,8 +892,7 @@ - (void)layoutMessageForNavigationControllerPresentation // If tool bar present animate above toolbar offset -= messageNavigationController.toolbar.bounds.size.height; } - CGFloat safeAreaExtraPadding = 30.0f; - self.topToVCFinalConstant = offset - safeAreaExtraPadding; + self.topToVCFinalConstant = offset; [self.viewController.view addSubview:self]; } } diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.xib b/Wikipedia/Third Party Code/RMessage/RMessageView.xib index c2bebf83c3f..4fa451089eb 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.xib +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.xib @@ -1,11 +1,9 @@ - - - - + + - + @@ -33,7 +31,7 @@ - @@ -41,7 +39,7 @@ - + @@ -76,11 +74,15 @@ + + + + From 05ca6b18396d4caed5fed2db03ffc03228a8205a Mon Sep 17 00:00:00 2001 From: Toni Sevener Date: Fri, 9 Sep 2022 15:24:58 -0500 Subject: [PATCH 17/17] Remove test code --- Wikipedia/Third Party Code/RMessage/RMessageView.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/Wikipedia/Third Party Code/RMessage/RMessageView.m b/Wikipedia/Third Party Code/RMessage/RMessageView.m index c0fe81948be..f0cbebdba83 100755 --- a/Wikipedia/Third Party Code/RMessage/RMessageView.m +++ b/Wikipedia/Third Party Code/RMessage/RMessageView.m @@ -462,7 +462,6 @@ - (void)setupLayout attribute:NSLayoutAttributeCenterX multiplier:1.f constant:0.f]; - centerXConstraint.identifier = @"RMessageView to superview centerX"; NSLayoutConstraint *leadingConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeLeading relatedBy:NSLayoutRelationEqual @@ -470,7 +469,6 @@ - (void)setupLayout attribute:NSLayoutAttributeLeading multiplier:1.f constant:0.f]; - leadingConstraint.identifier = @"RMessageView to superview leading"; NSLayoutConstraint *trailingConstraint = [NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeTrailing relatedBy:NSLayoutRelationEqual @@ -478,7 +476,6 @@ - (void)setupLayout attribute:NSLayoutAttributeTrailing multiplier:1.f constant:0.f]; - trailingConstraint.identifier = @"RMessageView to superview trailing"; [[self class] activateConstraints:@[centerXConstraint, leadingConstraint, trailingConstraint, self.topToVCLayoutConstraint] inSuperview:self.superview];