Skip to content

Commit

Permalink
Merge pull request #130 from ProteGO-Safe/release/4.9.1
Browse files Browse the repository at this point in the history
Release/4.9.1
  • Loading branch information
qLb authored Mar 1, 2021
2 parents 1b25b9a + d8f5395 commit 8dc27a7
Show file tree
Hide file tree
Showing 13 changed files with 131 additions and 49 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ playground.xcworkspace
# Package.pins
# Package.resolved
.build/
.idea/
# Add this line if you want to avoid checking in Xcode SPM integration.
# .swiftpm/xcode

Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## 4.9.1
- Added Vaccination stats to dashboard

## 4.9.0
- Added COVID daily stats
- Added subscription for COVID daily stats push notifications
Expand Down
2 changes: 1 addition & 1 deletion Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: 779fe596c92aaa178911e4fb4980414eb2b9ab2e

COCOAPODS: 1.9.1
COCOAPODS: 1.10.0
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ For convenience, there's a `rebuild.sh` script which performs actions mentioned
To launch it, type `sh rebuild.sh` in your console.

## ChangeLog
**4.9.1**
- Added Vaccination stats to dashboard

**4.9.0**
- Added COVID daily stats
Expand Down
4 changes: 2 additions & 2 deletions project.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ targets:
PushMutableContent:
settings:
CODE_SIGN_STYLE: Manual
MARKETING_VERSION: "4.9.0"
MARKETING_VERSION: "4.9.1"
CURRENT_PROJECT_VERSION: 745
TARGETED_DEVICE_FAMILY: 1,2
type: app-extension
Expand Down Expand Up @@ -75,7 +75,7 @@ targets:
deploymentTarget: "12.1"
settings:
CODE_SIGN_STYLE: Manual
MARKETING_VERSION: "4.9.0"
MARKETING_VERSION: "4.9.1"
CURRENT_PROJECT_VERSION: 745
TARGETED_DEVICE_FAMILY: 1
SWIFT_OBJC_BRIDGING_HEADER: $(PROJECT_DIR)/safesafe/App/safesafe-Bridging-Header.h
Expand Down
20 changes: 12 additions & 8 deletions safesafe/Common/Helpers/Dashboard/DashboardWorker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ final class DashboardWorker: DashboardWorkerType {
enum Download {
// Discussion: downloading data from CDN is available only if DashboardStatsModel.updated timestamp is older than requestGap
// then time intervals between next requests are not shorter than requestDebounce value
static let requestGap: Int = 20 * 60 * 60
static let requestDebounce: Int = 5 * 60
static let requestGap: Int = 20 * 60 * 60 // 20h
static let requestDebounce: Int = 5 * 60 // 5min
}
}

Expand Down Expand Up @@ -73,12 +73,16 @@ final class DashboardWorker: DashboardWorkerType {

func parseSharedContainerCovidStats(objects: [[String : Any]]) -> Promise<Void> {
let decoder = JSONDecoder()

guard
let jsonData = try? JSONSerialization.data(withJSONObject: objects, options: .fragmentsAllowed),
let items = try? decoder.decode([PushNotificationCovidStatsModel].self, from: jsonData),
let recentlyUpdatedModel = items.sorted(by: { $0.updated > $1.updated }).first
else {
let items = objects.compactMap { object -> PushNotificationCovidStatsModel? in
guard let jsonData = try? JSONSerialization.data(withJSONObject: object, options: .fragmentsAllowed),
let item = try? decoder.decode(PushNotificationCovidStatsModel.self, from: jsonData) else {
console("Wrong covidStats object: \(object)", type: .error)
return nil
}
return item
}

guard let recentlyUpdatedModel = items.sorted(by: { $0.updated > $1.updated }).first else {
return .init(error: InternalError.nilValue)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ struct DashboardStatsAPIResponse: Codable {
let totalDeaths: Int?
let newRecovered: Int?
let totalRecovered: Int?
let newVaccinations: Int
let totalVaccinations: Int
let newVaccinationsDose1: Int
let totalVaccinationsDose1: Int
let newVaccinationsDose2: Int
let totalVaccinationsDose2: Int
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ struct DashboardStatsResponse: Codable, JSONRepresentable {
let totalDeaths: Int?
let newRecovered: Int?
let totalRecovered: Int?
// Vaccination
let newVaccinations: Int?
let totalVaccinations: Int?
let newVaccinationsDose1: Int?
let totalVaccinationsDose1: Int?
let newVaccinationsDose2: Int?
let totalVaccinationsDose2: Int?

init(with model: DashboardStatsModel) {
self.updated = model.updated
Expand All @@ -27,6 +34,12 @@ struct DashboardStatsResponse: Codable, JSONRepresentable {
self.totalDeaths = model.totalDeaths.value
self.newRecovered = model.currentRecovered.value
self.totalRecovered = model.totalRecovered.value
self.newVaccinations = model.currentVaccinations.value
self.totalVaccinations = model.totalVaccinations.value
self.newVaccinationsDose1 = model.currentVaccinationsDose1.value
self.totalVaccinationsDose1 = model.totalVaccinationsDose1.value
self.newVaccinationsDose2 = model.currentVaccinationsDose2.value
self.totalVaccinationsDose2 = model.totalVaccinationsDose2.value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ final class DashboardStatsModel: Object, LocalStorable {
let totalDeaths = RealmOptional<Int>()
let currentRecovered = RealmOptional<Int>()
let totalRecovered = RealmOptional<Int>()
let currentVaccinations = RealmOptional<Int>()
let totalVaccinations = RealmOptional<Int>()
let currentVaccinationsDose1 = RealmOptional<Int>()
let totalVaccinationsDose1 = RealmOptional<Int>()
let currentVaccinationsDose2 = RealmOptional<Int>()
let totalVaccinationsDose2 = RealmOptional<Int>()

override class func primaryKey() -> String? { "id" }

Expand All @@ -42,6 +48,12 @@ final class DashboardStatsModel: Object, LocalStorable {
self.totalDeaths.value = model.totalDeaths
self.currentRecovered.value = model.newRecovered
self.totalRecovered.value = model.totalRecovered
self.currentVaccinations.value = model.newVaccinations
self.totalVaccinations.value = model.totalVaccinations
self.currentVaccinationsDose1.value = model.newVaccinationsDose1
self.totalVaccinationsDose1.value = model.totalVaccinationsDose1
self.currentVaccinationsDose2.value = model.newVaccinationsDose2
self.totalVaccinationsDose2.value = model.totalVaccinationsDose2
}

func update(with model: PushNotificationCovidStatsModel) {
Expand All @@ -52,5 +64,11 @@ final class DashboardStatsModel: Object, LocalStorable {
self.totalDeaths.value = model.totalDeaths
self.currentRecovered.value = model.newRecovered
self.totalRecovered.value = model.totalRecovered
self.currentVaccinations.value = model.newVaccinations
self.totalVaccinations.value = model.totalVaccinations
self.currentVaccinationsDose1.value = model.newVaccinationsDose1
self.totalVaccinationsDose1.value = model.totalVaccinationsDose1
self.currentVaccinationsDose2.value = model.newVaccinationsDose2
self.totalVaccinationsDose2.value = model.totalVaccinationsDose2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ struct PushNotificationCovidStatsModel: Codable {
let totalDeaths: Int?
let newRecovered: Int?
let totalRecovered: Int?

let newVaccinations: Int
let totalVaccinations: Int
let newVaccinationsDose1: Int
let totalVaccinationsDose1: Int
let newVaccinationsDose2: Int
let totalVaccinationsDose2: Int

var dictionary: [String: Any]? {
guard let data = try? JSONEncoder().encode(self) else { return nil }
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap { $0 as? [String: Any] }
}
guard let data = try? JSONEncoder().encode(self) else {
return nil
}
return (try? JSONSerialization.jsonObject(with: data, options: .allowFragments)).flatMap {
$0 as? [String: Any]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ final class NotificationUserInfoParser {
func covidStatsData(userInfo: [AnyHashable: Any]?) -> String? {
guard
let userInfoJSON = userInfo as? [String: Any],
let routeRaw = userInfoJSON[Key.covidStats.rawValue] as? String
let covidStatsRaw = userInfoJSON[Key.covidStats.rawValue] as? String
else {
return nil
}

return routeRaw
return covidStatsRaw
}

func parseCovidStats(userInfo: [AnyHashable: Any]) -> PushNotificationCovidStatsModel? {
Expand Down
4 changes: 3 additions & 1 deletion safesafe/Services/Local Storage/LocalStorage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,9 @@ extension RealmLocalStorage {
}

console("🔑🔑🔑 Instantiate Realm config with encryption key, length: \(encryptionKey.count)")
return Realm.Configuration(encryptionKey: encryptionKey)
return Realm.Configuration(encryptionKey: encryptionKey, schemaVersion: 1, migrationBlock: { _, oldSchemaVersion in
if (oldSchemaVersion < 1) {}
})
}
}

Expand Down
85 changes: 54 additions & 31 deletions safesafe/Services/Notifications/NotificationManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ final class NotificationManager: NSObject {

enum Topic {
static let devSuffix = "-dev"
static let stageSuffix = "-stage"
static let dailyPrefix = "daily-localized_"
static let generalPrefix = "general"
static let generalLocalizedPrefix = "general-localized"
Expand All @@ -77,19 +78,28 @@ final class NotificationManager: NSObject {
#if LIVE
return [Topic.generalPrefix]
#else
return ["\(Topic.generalPrefix)\(Topic.devSuffix)"]
return [
"\(Topic.generalPrefix)\(Topic.devSuffix)",
"\(Topic.generalPrefix)\(Topic.stageSuffix)"
]
#endif
case .generalLocalized:
#if LIVE
return [Topic.generalLocalizedPrefix]
#else
return ["\(Topic.generalLocalizedPrefix)\(Topic.devSuffix)"]
return [
"\(Topic.generalLocalizedPrefix)\(Topic.devSuffix)",
"\(Topic.generalLocalizedPrefix)\(Topic.stageSuffix)"
]
#endif
case .covidStats:
#if LIVE
return [Topic.covidStatsPrefix]
#else
return ["\(Topic.covidStatsPrefix)\(Topic.devSuffix)"]
return [
"\(Topic.covidStatsPrefix)\(Topic.devSuffix)",
"\(Topic.covidStatsPrefix)\(Topic.stageSuffix)"
]
#endif
case let .daily(startDate):
return dailyTopics(startDate: startDate)
Expand All @@ -111,6 +121,7 @@ final class NotificationManager: NSObject {
topics.append("\(Topic.dailyPrefix)\(formatted)")
#else
topics.append("\(Topic.dailyPrefix)\(formatted)\(Topic.devSuffix)")
topics.append("\(Topic.dailyPrefix)\(formatted)\(Topic.stageSuffix)")
#endif
}

Expand Down Expand Up @@ -210,36 +221,42 @@ extension NotificationManager: NotificationManagerProtocol {
func subscribeForCovidStatsTopicByDefault() {
let didSubscribeForCovidStatsTopic = StoredDefaults.standard.get(key: .didSubscribeForCovidStatsTopicByDefault) ?? false
if !didSubscribeForCovidStatsTopic {
Messaging.messaging().subscribe(toTopic: Topic.covidStats.toString.first!) { error in
if let error = error {
console(error, type: .error)
} else {
StoredDefaults.standard.set(value: true, key: .didSubscribeForCovidStatsTopicByDefault)
StoredDefaults.standard.set(value: true, key: .didUserSubscribeForCovidStatsTopic)
for topic in Topic.covidStats.toString {
Messaging.messaging().subscribe(toTopic: topic) { error in
if let error = error {
console(error, type: .error)
} else {
StoredDefaults.standard.set(value: true, key: .didSubscribeForCovidStatsTopicByDefault)
StoredDefaults.standard.set(value: true, key: .didUserSubscribeForCovidStatsTopic)
}
}
}
}
}

func manageUserCovidStatsTopic(subscribe: Bool, completion: @escaping ((Bool) -> ())) {
if subscribe {
Messaging.messaging().subscribe(toTopic: Topic.covidStats.toString.first!) { error in
if let error = error {
console(error, type: .error)
completion(false)
} else {
StoredDefaults.standard.set(value: true, key: .didUserSubscribeForCovidStatsTopic)
completion(true)
for topic in Topic.covidStats.toString {
Messaging.messaging().subscribe(toTopic: topic) { error in
if let error = error {
console(error, type: .error)
completion(false)
} else {
StoredDefaults.standard.set(value: true, key: .didUserSubscribeForCovidStatsTopic)
completion(true)
}
}
}
} else {
Messaging.messaging().unsubscribe(fromTopic: Topic.covidStats.toString.first!) { error in
if let error = error {
console(error, type: .error)
completion(false)
} else {
StoredDefaults.standard.set(value: false, key: .didUserSubscribeForCovidStatsTopic)
completion(true)
for topic in Topic.covidStats.toString {
Messaging.messaging().unsubscribe(fromTopic: topic) { error in
if let error = error {
console(error, type: .error)
completion(false)
} else {
StoredDefaults.standard.set(value: false, key: .didUserSubscribeForCovidStatsTopic)
completion(true)
}
}
}
}
Expand All @@ -253,14 +270,19 @@ extension NotificationManager: NotificationManagerProtocol {
let formatted = dateFormatter.string(from: date)

#if LIVE
let topic = "\(Topic.dailyPrefix)\(formatted)"
let topics = ["\(Topic.dailyPrefix)\(formatted)"]
#else
let topic = "\(Topic.dailyPrefix)\(formatted)\(Topic.devSuffix)"
let topics = [
"\(Topic.dailyPrefix)\(formatted)\(Topic.devSuffix)",
"\(Topic.dailyPrefix)\(formatted)\(Topic.stageSuffix)"
]
#endif

Messaging.messaging().unsubscribe(fromTopic: topic) { error in
if let error = error {
console(error, type: .error)

for topic in topics {
Messaging.messaging().unsubscribe(fromTopic: topic) { error in
if let error = error {
console(error, type: .error)
}
}
}
}
Expand Down Expand Up @@ -345,10 +367,11 @@ extension NotificationManager: NotificationManagerProtocol {


private func subscribeTopics() {
Messaging.messaging().unsubscribe(fromTopic: Topic.general.toString[0])
Messaging.messaging().subscribe(toTopic: Topic.generalLocalized.toString[0])
Topic.general.toString.forEach(Messaging.messaging().unsubscribe(fromTopic:))
Topic.generalLocalized.toString.forEach(Messaging.messaging().subscribe(toTopic:))

let didSubscribedFCMTopics: Bool = StoredDefaults.standard.get(key: .didSubscribeLocalizedFCMTopics) ?? false

guard !didSubscribedFCMTopics else {
return
}
Expand Down

0 comments on commit 8dc27a7

Please sign in to comment.