feat: 增加门店身份注销流程

This commit is contained in:
2026-08-31 09:43:14 +08:00
parent 396597a160
commit e529bb5942
35 changed files with 6062 additions and 45 deletions
@@ -116,6 +116,8 @@ final class PushNotificationManager: NSObject {
private var isInitialized = false
private var didRequestAuthorization = false
private var uploadTask: Task<Void, Never>?
private var uploadAttemptID: UUID?
private var isAccountBindingSuspended = false
private var queuedForcedUpload = false
private var isFetchingRegistrationID = false
private var queuedForcedFetch = false
@@ -161,7 +163,7 @@ final class PushNotificationManager: NSObject {
/// 登录成功后请求通知权限,并强制绑定当前账号。
func handleLoginCompleted() {
initializeIfPrivacyAccepted()
guard isInitialized, appStore.session.isLoggedIn else { return }
guard !isAccountBindingSuspended, isInitialized, appStore.session.isLoggedIn else { return }
if !didRequestAuthorization {
didRequestAuthorization = true
sdk.requestAuthorization(delegate: self)
@@ -171,7 +173,7 @@ final class PushNotificationManager: NSObject {
/// 账号切换后把同一设备重新绑定到新的业务账号。
func handleAccountSwitched() {
guard appStore.session.isLoggedIn else { return }
guard !isAccountBindingSuspended, appStore.session.isLoggedIn else { return }
bindCurrentAccount()
}
@@ -179,11 +181,22 @@ final class PushNotificationManager: NSObject {
func handleLogout() {
uploadTask?.cancel()
uploadTask = nil
uploadAttemptID = nil
queuedForcedUpload = false
router.resetPendingRoute()
Task { await updateApplicationIconBadgeCount(0) }
}
/// 注销核验或受限期间暂停业务账号绑定,保留 Token、Registration ID 与待处理通知。
func setAccountBindingSuspended(_ suspended: Bool) {
isAccountBindingSuspended = suspended
guard suspended else { return }
uploadTask?.cancel()
uploadTask = nil
uploadAttemptID = nil
queuedForcedUpload = false
}
/// 将桌面 App Icon 角标更新为最新未读消息数量。
func updateApplicationIconBadgeCount(_ count: Int) async {
await applicationIconBadgeSetter.setBadgeCount(max(count, 0))
@@ -191,13 +204,14 @@ final class PushNotificationManager: NSObject {
/// App 回到前台时补偿失败或尚未完成的 Registration ID 上报。
func retryPendingRegistrationUpload() {
guard appStore.session.isLoggedIn else { return }
guard !isAccountBindingSuspended, appStore.session.isLoggedIn else { return }
uploadCachedRegistrationID(force: false)
refreshRegistrationID(forceUpload: false)
}
/// 登录根页面建立后继续执行通知点击暂存的路由。
func routePendingNotificationIfPossible() {
guard !isAccountBindingSuspended else { return }
router.routePendingIfPossible()
}
@@ -323,7 +337,7 @@ final class PushNotificationManager: NSObject {
}
private func upload(registrationID: String, force: Bool) {
guard appStore.session.isLoggedIn,
guard !isAccountBindingSuspended, appStore.session.isLoggedIn,
let uploadedKey = appStore.session.accountScopedKey(Key.uploadedRegistrationIDSuffix)
else { return }
@@ -336,12 +350,15 @@ final class PushNotificationManager: NSObject {
}
let accountScope = appStore.session.accountCachePrefix
let attemptID = UUID()
uploadAttemptID = attemptID
uploadTask = Task { [weak self] in
guard let self else { return }
var succeeded = false
do {
try await self.api.registerJPushID(registrationID)
if self.appStore.session.accountCachePrefix == accountScope {
if self.uploadAttemptID == attemptID, !self.isAccountBindingSuspended,
self.appStore.session.accountCachePrefix == accountScope {
self.defaults.set(registrationID, forKey: uploadedKey)
}
succeeded = true
@@ -353,7 +370,9 @@ final class PushNotificationManager: NSObject {
#endif
}
guard self.uploadAttemptID == attemptID else { return }
self.uploadTask = nil
self.uploadAttemptID = nil
let shouldForceAgain = self.queuedForcedUpload
self.queuedForcedUpload = false
if succeeded, shouldForceAgain {