Skip to content
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
4 changes: 2 additions & 2 deletions Modules/Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Modules/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let package = Package(
.package(url: "https://github.com/apple/swift-collections", from: "1.0.0"),
.package(url: "https://github.com/Automattic/Automattic-Tracks-iOS", from: "3.5.2"),
.package(url: "https://github.com/Automattic/AutomatticAbout-swift", from: "1.1.5"),
.package(url: "https://github.com/Automattic/Gravatar-SDK-iOS", from: "3.2.0"),
.package(url: "https://github.com/Automattic/Gravatar-SDK-iOS", from: "3.4.0"),
.package(url: "https://github.com/Automattic/Gridicons-iOS", branch: "develop"),
.package(url: "https://github.com/Automattic/ScreenObject", from: "0.3.0"),
.package(url: "https://github.com/buildkite/test-collector-swift", from: "0.3.0"),
Expand Down
43 changes: 28 additions & 15 deletions WordPress/Classes/ViewRelated/Me/Me Main/MeViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import BuildSettingsKit
import WordPressData
import WordPressShared
import AutomatticAbout
import GravatarUI

public class MeViewController: UITableViewController {
var handler: ImmuTableViewHandler!
Expand Down Expand Up @@ -37,6 +38,7 @@ public class MeViewController: UITableViewController {
/// considered to be ` .compact` size class, so it has to be invoked manually.
headerView.configureHorizontalMode()
}
headerView.delegate = self

ImmuTable.registerRows([
VerifyEmailRow.self,
Expand Down Expand Up @@ -130,7 +132,7 @@ public class MeViewController: UITableViewController {
icon: UIImage(named: "site-menu-people")?.withRenderingMode(.alwaysTemplate),
tintColor: .label,
accessoryType: accessoryType,
action: pushMyProfile(),
action: presentGravatarAboutEditorAction(),
accessibilityIdentifier: "myProfile")

let qrLogin = NavigationItemRow(
Expand Down Expand Up @@ -251,24 +253,27 @@ public class MeViewController: UITableViewController {

// MARK: - Actions

fileprivate var myProfileViewController: UIViewController? {
guard let account = self.defaultAccount() else {
let error = "Tried to push My Profile without a default account. This shouldn't happen"
assertionFailure(error)
DDLogError("\(error)")
return nil
fileprivate func presentGravatarAboutEditorAction() -> ImmuTableAction {
return { [unowned self] row in
presentGravatarQuickEditor(initialPage: .aboutEditor)
}

return MyProfileViewController(account: account)
}

fileprivate func pushMyProfile() -> ImmuTableAction {
return { [unowned self] row in
if let myProfileViewController = self.myProfileViewController {
WPAppAnalytics.track(.openedMyProfile)
self.showOrPushController(myProfileViewController)
}
fileprivate func presentGravatarQuickEditor(initialPage: AvatarPickerAndAboutEditorConfiguration.Page) {
let scope = QuickEditorScopeOption.avatarPickerAndAboutInfoEditor(.init(
contentLayout: .horizontal(),
fields: [.displayName, .aboutMe, .firstName, .lastName],
initialPage: initialPage
))

let presenter = GravatarQuickEditorPresenter() { [weak self] in
self?.refreshAccountDetailsAndSettings()
}

presenter?.presentQuickEditor(
on: self,
scope: scope
)
}

fileprivate func pushAccountSettings() -> ImmuTableAction {
Expand Down Expand Up @@ -634,6 +639,14 @@ extension MeViewController {
}
}

// MARK: - Header avatar tap handler (MeHeaderViewDelegate)

extension MeViewController: MeHeaderViewDelegate {
func meHeaderViewDidTapOnIconView(_ view: MeHeaderView) {
presentGravatarQuickEditor(initialPage: .avatarPicker)
}
}

private enum Strings {
static let submitFeedback = NSLocalizedString("meMenu.submitFeedback", value: "Send Feedback", comment: "Me tab menu items")
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,54 +10,74 @@ struct GravatarQuickEditorPresenter {
let authToken: String
let emailVerificationStatus: WPAccount.VerificationStatus

init?(email: String) {
let onAccountUpdated: (() -> Void)?

init?(onAccountUpdated: (() -> Void)? = nil) {
let context = ContextManager.shared.mainContext
guard let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context), let authToken = account.authToken else {
guard
let account = try? WPAccount.lookupDefaultWordPressComAccount(in: context),
let authToken = account.authToken,
let email = account.email
else {
return nil
}
self.email = email
self.authToken = authToken
self.emailVerificationStatus = account.verificationStatus
self.onAccountUpdated = onAccountUpdated
}

func presentQuickEditor(on presentingViewController: UIViewController) {
func presentQuickEditor(on presentingViewController: UIViewController, scope: QuickEditorScopeOption) {
guard emailVerificationStatus == .verified else {
let alert = UIAlertController(
title: nil,
message: NSLocalizedString(
"avatar.update.email.verification.required",
value: "To update your avatar, you need to verify your email address first.",
comment: "An error message displayed when attempting to update an avatar while the user's email address is not verified."
),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: SharedStrings.Button.ok, style: .default))
presentingViewController.present(alert, animated: true)
presentAlert(on: presentingViewController)
return
}
let presenter = QuickEditorPresenter(
email: Email(email),
scope: .avatarPicker(AvatarPickerConfiguration(contentLayout: .horizontal())),
configuration: .init(
interfaceStyle: presentingViewController.traitCollection.userInterfaceStyle
),
scopeOption: scope,
token: authToken
)
presenter.present(
in: presentingViewController,
onAvatarUpdated: {
AuthenticatorAnalyticsTracker.shared.track(click: .selectAvatar)
Task {
// Purge the cache otherwise the old avatars remain around.
await ImageDownloader.shared.clearURLSessionCache()
await ImageDownloader.shared.clearMemoryCache()
NotificationCenter.default.post(name: .GravatarQEAvatarUpdateNotification,
object: self,
userInfo: [GravatarQEAvatarUpdateNotificationKeys.email.rawValue: email])
onUpdate: { update in
switch update {
case is QuickEditorUpdate.Avatar:
onAvatarUpdate()
case is QuickEditorUpdate.AboutInfo:
onAccountUpdated?()
default: break
}
}, onDismiss: {
// No op.
}
)
}

private func presentAlert(on presentingViewController: UIViewController) {
let alert = UIAlertController(
title: nil,
message: NSLocalizedString(
"profile.update.email.verification.required",
value: "To update your profile, you need to verify your email address first.",
comment: "An error message displayed when attempting to update their profile while the user's email address is not verified."
),
preferredStyle: .alert
)
alert.addAction(UIAlertAction(title: SharedStrings.Button.ok, style: .default))
presentingViewController.present(alert, animated: true)
}

private func onAvatarUpdate() {
AuthenticatorAnalyticsTracker.shared.track(click: .selectAvatar)
Task {
// Purge the cache otherwise the old avatars remain around.
await ImageDownloader.shared.clearURLSessionCache()
await ImageDownloader.shared.clearMemoryCache()
NotificationCenter.default.post(
name: .GravatarQEAvatarUpdateNotification,
object: self,
userInfo: [GravatarQEAvatarUpdateNotificationKeys.email.rawValue: email]
)
}
}
}
112 changes: 0 additions & 112 deletions WordPress/Classes/ViewRelated/Me/My Profile/MyProfileHeaderView.swift

This file was deleted.

This file was deleted.

Loading