Commit 72ede3bb by Demid Merzlyakov

Add a new LAST_SEEN_FIPS_CODE_NON_TRACFONE attribute for NWSAlerts targeting.

parent 87102046
...@@ -256,7 +256,7 @@ public class LocationManager { ...@@ -256,7 +256,7 @@ public class LocationManager {
updateNotifications(for: location) updateNotifications(for: location)
getFipsIfNeeded(for: location) getFipsIfNeeded(for: location)
} }
pushNotificationsManager.updateNwsSubscriptions(for: locations) pushNotificationsManager.updateNwsSubscriptions(for: locations, selectedLocation: selectedLocation)
} }
public func getFipsIfNeeded(for location: Location) { public func getFipsIfNeeded(for location: Location) {
...@@ -269,7 +269,7 @@ public class LocationManager { ...@@ -269,7 +269,7 @@ public class LocationManager {
return updatedLocation return updatedLocation
}, completion: { [weak self] in }, completion: { [weak self] in
guard let self = self else { return } guard let self = self else { return }
self.pushNotificationsManager.updateNwsSubscriptions(for: self.locations) self.pushNotificationsManager.updateNwsSubscriptions(for: self.locations, selectedLocation: self.selectedLocation)
}) })
} }
} }
......
...@@ -49,26 +49,35 @@ public class PushNotificationsManager: NSObject { ...@@ -49,26 +49,35 @@ public class PushNotificationsManager: NSObject {
} }
} }
private var lastSetFIPSList: String? = "" internal var lastSetFIPSList: String? = ""
internal var lastSetFIPSCode: String? = ""
private func updateNwsSubscriptions(with fipsList: String?) { private func updateNwsSubscriptions(with fipsList: String?, currentFipsCode: String?) {
let lastFipsCodeAttributeName = "LAST_SEEN_FIPS_CODE_NON_TRACFONE"
if configManager.config.nwsAlertsViaMoEngageEnabled { if configManager.config.nwsAlertsViaMoEngageEnabled {
if fipsList != lastSetFIPSList { if fipsList != lastSetFIPSList {
log.info("Set FIPS_LIST to '\(fipsList ?? "")'") log.info("Set FIPS_LIST to '\(fipsList ?? "")'")
lastSetFIPSList = fipsList lastSetFIPSList = fipsList
} }
if currentFipsCode != lastSetFIPSCode {
log.info("Set \(lastFipsCodeAttributeName) to '\(currentFipsCode ?? "")'")
lastSetFIPSCode = currentFipsCode
}
} }
else { else {
log.info("Set FIPS_LIST to nil, because nwsAlertsViaMoEngage are disabled via config.") log.info("Set FIPS_LIST to nil, because nwsAlertsViaMoEngage are disabled via config.")
log.info("Set \(lastFipsCodeAttributeName) to nil, because nwsAlertsViaMoEngage are disabled via config")
log.info("Set ")
lastSetFIPSList = nil lastSetFIPSList = nil
} }
MoEngage.sharedInstance().setUserAttribute(lastSetFIPSList, forKey: "FIPS_LIST") MoEngage.sharedInstance().setUserAttribute(lastSetFIPSList, forKey: "FIPS_LIST")
MoEngage.sharedInstance().setUserAttribute(lastSetFIPSCode, forKey: lastFipsCodeAttributeName)
} }
public func updateNwsSubscriptions(for locations: [Location]) { public func updateNwsSubscriptions(for locations: [Location], selectedLocation: Location?) {
let fipsCodes = locations.compactMap { $0.fipsCode } let fipsCodes = locations.compactMap { $0.fipsCode }
let newFipsList = fipsCodes.joined(separator: ",") let newFipsList = fipsCodes.joined(separator: ",")
updateNwsSubscriptions(with: newFipsList) updateNwsSubscriptions(with: newFipsList, currentFipsCode: selectedLocation?.fipsCode)
} }
public func set(pushToken: Data) { public func set(pushToken: Data) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment