Support logout by notification

This commit is contained in:
Peter 2019-04-26 14:09:03 +04:00
parent 62773a1714
commit 500a5adbee
6 changed files with 49 additions and 7 deletions

View File

@ -1,2 +1,3 @@
Logging into multiple accounts is now supported.
Tap "Add Account" in Settings — Edit.
Archive chats by swiping from right.
Swipe down to reveal "Archived Chats".

View File

@ -315,7 +315,7 @@ final class AuthorizedApplicationContext {
self.loggedOutDisposable.set(context.account.loggedOut.start(next: { value in
if value {
Logger.shared.log("ApplicationContext", "account logged out")
let _ = logoutFromAccount(id: accountId, accountManager: accountManager).start()
let _ = logoutFromAccount(id: accountId, accountManager: accountManager, alreadyLoggedOutRemotely: false).start()
}
}))
@ -630,7 +630,7 @@ final class AuthorizedApplicationContext {
if isDropAuth {
actions = [TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {}), TextAlertAction(type: .genericAction, title: presentationData.strings.LogoutOptions_LogOut, action: {
if let strongSelf = self {
let _ = logoutFromAccount(id: strongSelf.context.account.id, accountManager: strongSelf.context.sharedContext.accountManager).start()
let _ = logoutFromAccount(id: strongSelf.context.account.id, accountManager: strongSelf.context.sharedContext.accountManager, alreadyLoggedOutRemotely: false).start()
}
})]
} else {

View File

@ -63,6 +63,34 @@ final class ClearNotificationsManager {
self.timer?.invalidate()
}
func clearAll() {
self.getNotificationIds(ClearNotificationIdsCompletion { [weak self] result in
Queue.mainQueue().async {
var removeKeys: [String] = []
for (identifier, _) in result {
removeKeys.append(identifier)
}
if let strongSelf = self, !removeKeys.isEmpty {
strongSelf.removeNotificationIds(removeKeys)
}
}
})
self.getPendingNotificationIds(ClearNotificationIdsCompletion { [weak self] result in
Queue.mainQueue().async {
var removeKeys: [String] = []
for (identifier, _) in result {
removeKeys.append(identifier)
}
if let strongSelf = self, !removeKeys.isEmpty {
strongSelf.removePendingNotificationIds(removeKeys)
}
}
})
}
func append(_ id: MessageId) {
if let current = self.ids[id.peerId] {
if current < id {

View File

@ -29,6 +29,7 @@ final class SharedNotificationManager {
private var inForeground: Bool = false
private var inForegroundDisposable: Disposable?
private var accountManager: AccountManager?
private var accountsAndKeys: [(Account, Bool, MasterNotificationKey)]?
private var accountsAndKeysDisposable: Disposable?
@ -198,6 +199,7 @@ final class SharedNotificationManager {
let aps = payload["aps"] as? [AnyHashable: Any]
var readMessageId: MessageId?
var isForcedLogOut = false
var isCall = false
var isAnnouncement = false
var isLocationPolling = false
@ -223,7 +225,9 @@ final class SharedNotificationManager {
}
}
if let locKey = alert["loc-key"] as? String {
if locKey == "PHONE_CALL_REQUEST" {
if locKey == "SESSION_REVOKE" {
isForcedLogOut = true
} else if locKey == "PHONE_CALL_REQUEST" {
isCall = true
} else if locKey == "GEO_LIVE_PENDING" {
isLocationPolling = true
@ -368,6 +372,15 @@ final class SharedNotificationManager {
}
}
if isForcedLogOut {
self.clearNotificationsManager?.clearAll()
if let accountManager = self.accountManager {
let _ = logoutFromAccount(id: account.id, accountManager: accountManager, alreadyLoggedOutRemotely: true).start()
}
return
}
if notificationRequestId != nil || isMutePolling || isCall {
if !self.inForeground || !isCurrent {
self.beginPollingState(account: account)

@ -1 +1 @@
Subproject commit ddab57db605c641ad3d9ea35a34674a3d3645f9b
Subproject commit 5db0d202e17e9d69507259ce9e3ee00e3317f30a

@ -1 +1 @@
Subproject commit 4b664291c36b6535179791a31c75078155eb4713
Subproject commit a8d2e964f211a32b878a16c4b87059540fbf1e77