Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,12 @@ class StartRequestCache: RequestCache {
}

class ReceiveReceiptsRequestCache: RequestCache {
// Keep receive receipts requests for up to 30 days.
static let OneMonthInSeconds = TimeInterval(60 * 60 * 24 * 30)
// Sent receipts are kept as dedup markers, so bound retention: an active activity re-emits for at most
// ~12h on relaunch, and updates arrive over the network, so a day covers dedup and retries without piling up.
static let OneDayInSeconds = TimeInterval(60 * 60 * 24)

init() {
super.init(cacheKey: OS_LIVE_ACTIVITIES_EXECUTOR_RECEIVE_RECEIPTS_KEY, ttl: ReceiveReceiptsRequestCache.OneMonthInSeconds)
super.init(cacheKey: OS_LIVE_ACTIVITIES_EXECUTOR_RECEIVE_RECEIPTS_KEY, ttl: ReceiveReceiptsRequestCache.OneDayInSeconds)
}
}

Expand All @@ -141,10 +142,11 @@ class OSLiveActivitiesExecutor: OSPushSubscriptionObserver {

// The live activities request dispatch queue, serial. This synchronizes access to `updateTokens` and `startTokens`.
private var requestDispatch: OSDispatchQueue
private var pollIntervalSeconds = 30
private var pollIntervalSeconds: Int

init(requestDispatch: OSDispatchQueue) {
init(requestDispatch: OSDispatchQueue, pollIntervalSeconds: Int = 30) {
self.requestDispatch = requestDispatch
self.pollIntervalSeconds = pollIntervalSeconds
}

func start() {
Expand Down Expand Up @@ -184,7 +186,7 @@ class OSLiveActivitiesExecutor: OSPushSubscriptionObserver {
}
}

private func pollPendingRequests() {
func pollPendingRequests() {
OneSignalLog.onesignalLog(.LL_VERBOSE, message: "OneSignal.LiveActivities pollPendingRequests")

self.requestDispatch.asyncAfterTime(deadline: .now() + .seconds(pollIntervalSeconds)) { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ public class OneSignalLiveActivitiesManagerImpl: NSObject, OSLiveActivities {
Task {
for await content in activity.contentUpdates {
// Don't track a live activity started / updated "in app" without a notification
if let notificationId = activity.content.state.onesignal?.notificationId {
if let notificationId = content.state.onesignal?.notificationId {
OneSignalLiveActivitiesManagerImpl.addReceiveReceipts(notificationId: notificationId, activityType: "\(activityType)", activityId: activity.attributes.onesignal.activityId)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ class OSRequestLiveActivityReceiveReceipts: OneSignalRequest, OSLiveActivityRequ
var activityType: String
var activityId: String
var requestSuccessful: Bool
var shouldForgetWhenSuccessful: Bool = true
// Kept after success so the persisted cache suppresses re-sends across relaunches.
var shouldForgetWhenSuccessful: Bool = false

func prepareForExecution() -> Bool {
guard let appId = OneSignalIdentifiers.currentAppId else {
Expand Down
Loading
Loading