Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
mfclarke-cnx committed Feb 6, 2024
1 parent 18c361b commit 94bdc35
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions PostHog/PostHogSDK.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
let optOut = theStorage.getBool(forKey: .optOut)
config.optOut = optOut ?? config.optOut
}

#if !os(watchOS)
queue = PostHogQueue(config, theStorage, theApi, reachability)
#else
Expand All @@ -117,7 +117,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30

registerNotifications()
captureScreenViews()

rotateSession()

DispatchQueue.main.async {
Expand Down Expand Up @@ -150,15 +150,15 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30

private func dynamicContext() -> [String: Any] {
var properties = getRegisteredProperties()

var groups: [String: String]?
groupsLock.withLock {
groups = getGroups()
}
if groups != nil, !groups!.isEmpty {
properties["$groups"] = groups!
}

if let sessionId = sessionId {
properties["$session_id"] = sessionId
}
Expand Down Expand Up @@ -371,7 +371,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
guard let queue = queue else {
return
}

queue.add(PostHogEvent(
event: event,
distinctId: getDistinctId(),
Expand All @@ -383,7 +383,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30

if !isInBackground {
sessionLock.withLock {
sessionLastTimestamp = Date().timeIntervalSince1970
sessionLastTimestamp = Date().timeIntervalSince1970
}
}
}
Expand Down Expand Up @@ -597,18 +597,18 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
}
return enabled
}

private func rotateSessionIdIfRequired() {
guard let _ = sessionId, let sessionLastTimestamp = sessionLastTimestamp else {
guard sessionId != nil, let sessionLastTimestamp = sessionLastTimestamp else {
rotateSession()
return
}
if (Date().timeIntervalSince1970 - sessionLastTimestamp > sessionChangeThreshold) {

if Date().timeIntervalSince1970 - sessionLastTimestamp > sessionChangeThreshold {
rotateSession()
}
}

private func rotateSession() {
let newSessionId = UUID().uuidString
let newSessionLastTimestamp = Date().timeIntervalSince1970
Expand Down Expand Up @@ -718,7 +718,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
#endif
}
}

@objc func handleAppDidFinishLaunching() {
captureAppInstallLifecycle()
}
Expand Down Expand Up @@ -781,7 +781,7 @@ private let sessionChangeThreshold: TimeInterval = 60 * 30
capturedAppInstalled = true
}
}

@objc func handleAppDidBecomeActive() {
rotateSessionIdIfRequired()

Expand Down

0 comments on commit 94bdc35

Please sign in to comment.