-
-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the apps routing structure to enable app-wide navigation thr…
…ough a Router to improve how deep link URLs are handled
- Loading branch information
Showing
24 changed files
with
1,051 additions
and
574 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import Combine | ||
import SwiftUI | ||
|
||
class AppState: ObservableObject { | ||
@Published | ||
var router: Router | ||
|
||
@Published | ||
var unreadChannelMessages: Int | ||
|
||
@Published | ||
var unreadDirectMessages: Int | ||
|
||
var totalUnreadMessages: Int { | ||
unreadChannelMessages + unreadDirectMessages | ||
} | ||
|
||
private var cancellables: Set<AnyCancellable> = [] | ||
|
||
init(router: Router) { | ||
self.router = router | ||
self.unreadChannelMessages = 0 | ||
self.unreadDirectMessages = 0 | ||
|
||
// Keep app icon badge count in sync with messages read status | ||
$unreadChannelMessages.combineLatest($unreadDirectMessages) | ||
.sink(receiveValue: { badgeCounts in | ||
UNUserNotificationCenter.current() | ||
.setBadgeCount(badgeCounts.0 + badgeCounts.1) | ||
}) | ||
.store(in: &cancellables) | ||
} | ||
} |
Oops, something went wrong.