Skip to content

Commit

Permalink
Merge pull request wordpress-mobile#13596 from wordpress-mobile/issue…
Browse files Browse the repository at this point in the history
…/13594-synchronizing-settings-on-signup

WordPressComSyncService: Synchronizing Settings
  • Loading branch information
jleandroperez authored Mar 4, 2020
2 parents a67cebb + 3e896a1 commit 396c0d3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
11 changes: 11 additions & 0 deletions WordPress/Classes/Services/AccountSettingsService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ class AccountSettingsService {
}
}

func updateDisplayName(_ displayName: String, finished: ((Bool, Error?) -> ())? = nil) {
remote.updateSetting(.displayName(displayName), success: {
finished?(true, nil)
}) { error in
DDLogError("Error saving account settings change \(error)")
NotificationCenter.default.post(name: NSNotification.Name.AccountSettingsServiceChangeSaveFailed, object: self, userInfo: [NSUnderlyingErrorKey: error])

finished?(false, error)
}
}

func updatePassword(_ password: String, finished: ((Bool, Error?) -> ())? = nil) {
remote.updatePassword(password, success: {
finished?(true, nil)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,24 +212,19 @@ private extension SignupEpilogueViewController {
}

func changeDisplayName(to newDisplayName: String, finished: @escaping (() -> Void)) {

let context = ContextManager.sharedInstance().mainContext

guard let defaultAccount = AccountService(managedObjectContext: context).defaultWordPressComAccount(),
let restApi = defaultAccount.wordPressComRestApi else {
finished()
return
let restApi = defaultAccount.wordPressComRestApi else {
finished()
return
}

let accountSettingService = AccountSettingsService(userID: defaultAccount.userID.intValue, api: restApi)
let accountSettingsChange = AccountSettingsChange.displayName(newDisplayName)

accountSettingService.saveChange(accountSettingsChange) { success in
if success {
WordPressAuthenticator.track(.signupEpilogueDisplayNameUpdateSucceeded, properties: self.tracksProperties())
} else {
WordPressAuthenticator.track(.signupEpilogueDisplayNameUpdateFailed, properties: self.tracksProperties())
}
accountSettingService.updateDisplayName(newDisplayName) { (success, _) in
let event: WPAnalyticsStat = success ? .signupEpilogueDisplayNameUpdateSucceeded : .signupEpilogueDisplayNameUpdateFailed
WordPressAuthenticator.track(event, properties: self.tracksProperties())

finished()
}
}
Expand Down

0 comments on commit 396c0d3

Please sign in to comment.