Skip to content
This repository has been archived by the owner on Jun 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2167 from RocketChat/fix/notification_open_other_…
Browse files Browse the repository at this point in the history
…server

[FIX] Not opening correct room after tapping notification when in other server
  • Loading branch information
rafaelks authored Sep 4, 2018
2 parents 8fdd9c2 + 1b72c8b commit f257e91
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
10 changes: 6 additions & 4 deletions Rocket.Chat/Managers/AppManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ struct AppManager {

extension AppManager {

static func changeSelectedServer(index: Int) {
static func changeSelectedServer(index: Int, completion: (() -> Void)? = nil) {
guard index != DatabaseManager.selectedIndex else {
DatabaseManager.changeDatabaseInstance(index: index)
reloadApp()
reloadApp(completion: completion)
return
}

Expand All @@ -131,7 +131,7 @@ extension AppManager {
AuthSettingsManager.shared.updateCachedSettings()
AuthManager.recoverAuthIfNeeded()

reloadApp()
reloadApp(completion: completion)
}
}

Expand Down Expand Up @@ -185,7 +185,7 @@ extension AppManager {
}
}

static func reloadApp() {
static func reloadApp(completion: (() -> Void)? = nil) {
SocketManager.sharedInstance.connectionHandlers.removeAllObjects()
SocketManager.disconnect { (_, _) in
DispatchQueue.main.async {
Expand All @@ -212,6 +212,8 @@ extension AppManager {
} else {
WindowManager.open(.auth(serverUrl: "", credentials: nil))
}

completion?()
}
}
}
Expand Down
16 changes: 11 additions & 5 deletions Rocket.Chat/Managers/PushManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,21 @@ extension PushManager {
// side effect: needed for Subscription.notificationSubscription()
AppManager.initialRoomId = notification.roomId

if index != DatabaseManager.selectedIndex {
AppManager.changeSelectedServer(index: index)
} else {
if let auth = AuthManager.isAuthenticated() {
func openRoom() {
if let auth = AuthManager.isAuthenticated() {
let openSubscription = MainSplitViewController.chatViewController?.subscription
if let subscription = Subscription.notificationSubscription(auth: auth), subscription != openSubscription {
AppManager.open(room: subscription, animated: false)
}
}
}
}

if index != DatabaseManager.selectedIndex {
AppManager.changeSelectedServer(index: index) {
openRoom()
}
} else {
openRoom()
}

guard let realm = DatabaseManager.databaseInstace(index: index) else {
Expand Down

0 comments on commit f257e91

Please # to comment.