Skip to content

Commit 8cafb88

Browse files
Merge branch 'task/show-timestamp-in-ev-details' of github.com:gojek/clickstream-ios into task/show-timestamp-in-ev-details
2 parents c8ec0d6 + 619fd0a commit 8cafb88

File tree

11 files changed

+187
-60
lines changed

11 files changed

+187
-60
lines changed

Clickstream.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
Pod::Spec.new do |s|
1010
s.name = "Clickstream"
11-
s.version = "1.1.22"
11+
s.version = "2.0.14"
1212
s.summary = "Real time Analytics SDK"
1313
s.description = "Clickstream is an event agnostic, real-time data ingestion analytics SDK"
1414

Clickstream.xcodeproj/project.pbxproj

Lines changed: 92 additions & 37 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright (c) 2016 Ashley Mills
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in
11+
all copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19+
THE SOFTWARE.

Podfile.lock

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
PODS:
2-
- GRDB.swift (6.14.0):
3-
- GRDB.swift/standard (= 6.14.0)
4-
- GRDB.swift/standard (6.14.0)
2+
- GRDB.swift (6.15.1):
3+
- GRDB.swift/standard (= 6.15.1)
4+
- GRDB.swift/standard (6.15.1)
55
- ReachabilitySwift (5.0.0)
6-
- SwiftProtobuf (1.21.0)
6+
- SwiftProtobuf (1.22.0)
77

88
DEPENDENCIES:
99
- GRDB.swift (~> 6.7)
@@ -13,14 +13,13 @@ DEPENDENCIES:
1313
SPEC REPOS:
1414
https://github.com/CocoaPods/Specs.git:
1515
- GRDB.swift
16-
trunk:
1716
- ReachabilitySwift
1817
- SwiftProtobuf
1918

2019
SPEC CHECKSUMS:
21-
GRDB.swift: d31072a99e8d3d9f5410f1a938018ccb51b881e2
20+
GRDB.swift: a6b7e9900aa300d0cbf1f1c5f47b8f32ae51e30c
2221
ReachabilitySwift: 985039c6f7b23a1da463388634119492ff86c825
23-
SwiftProtobuf: afced68785854575756db965e9da52bbf3dc45e7
22+
SwiftProtobuf: 40bd808372cb8706108f22d28f8ab4a6b9bc6989
2423

2524
PODFILE CHECKSUM: 2c97fb10dcb1fcd309b15a9c7e84ddc137998638
2625

Sources/Clickstream/Core/Data/Constants/Constants.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ enum Constants {
5555
}
5656

5757
enum EventVisualizer {
58+
static var eventGID = "eventGuid"
5859
static var eventGuid = "meta.eventGuid"
5960
static var guid = "guid"
6061
static var eventTimestamp = "eventTimestamp"

Sources/Clickstream/Core/Interface/ClickStream.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ public final class Clickstream {
107107

108108
static var updateConnectionStatus: Bool = false
109109

110+
static var timerCrashFixFlag: Bool = false
111+
110112
/// Use this property to pass application name without any space or special characters.
111113
static var appPrefix: String = ""
112114

@@ -167,6 +169,7 @@ public final class Clickstream {
167169
eventClassification: ClickstreamEventClassification,
168170
delegate: ClickstreamDelegate? = nil,
169171
updateConnectionStatus: Bool = false,
172+
timerCrashFixFlag: Bool = false,
170173
appPrefix: String) throws -> Clickstream? {
171174
do {
172175
return try initializeClickstream(
@@ -175,6 +178,7 @@ public final class Clickstream {
175178
eventClassification: eventClassification,
176179
delegate: delegate,
177180
updateConnectionStatus: updateConnectionStatus,
181+
timerCrashFixFlag: timerCrashFixFlag,
178182
appPrefix: appPrefix)
179183
} catch {
180184
print("Cannot initialise Clickstream. Dependencies could not be initialised.",.critical)
@@ -188,6 +192,7 @@ public final class Clickstream {
188192
eventClassification: ClickstreamEventClassification,
189193
delegate: ClickstreamDelegate? = nil,
190194
updateConnectionStatus: Bool = false,
195+
timerCrashFixFlag: Bool = false,
191196
appPrefix: String) throws -> Clickstream? {
192197
do {
193198
return try initializeClickstream(
@@ -196,6 +201,7 @@ public final class Clickstream {
196201
eventClassification: eventClassification,
197202
delegate: delegate,
198203
updateConnectionStatus: updateConnectionStatus,
204+
timerCrashFixFlag: timerCrashFixFlag,
199205
appPrefix: appPrefix)
200206
} catch {
201207
print("Cannot initialise Clickstream. Dependencies could not be initialised.",.critical)
@@ -210,6 +216,7 @@ public final class Clickstream {
210216
eventClassification: ClickstreamEventClassification,
211217
delegate: ClickstreamDelegate? = nil,
212218
updateConnectionStatus: Bool = false,
219+
timerCrashFixFlag: Bool = false,
213220
appPrefix: String) throws -> Clickstream? {
214221
let semaphore = DispatchSemaphore(value: 1)
215222
defer {
@@ -223,6 +230,7 @@ public final class Clickstream {
223230
Clickstream.configurations = configurations
224231
Clickstream.eventClassifier = eventClassification
225232
Clickstream.updateConnectionStatus = updateConnectionStatus
233+
Clickstream.timerCrashFixFlag = timerCrashFixFlag
226234
Clickstream.appPrefix = appPrefix.lowercased().replacingOccurrences(of: " ", with: "")
227235

228236
// All the dependency injections pertaining to the clickstream blocks happen here!

Sources/Clickstream/NetworkManager/Infrastructure/Utilities/DispatchSourceTimer+RepeatingTimer.swift

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,13 @@ import Foundation
1414
/// already resumed (noted by https://github.com/SiftScience/sift-ios/issues/52)
1515
class RepeatingTimer {
1616

17-
let timeInterval: TimeInterval
17+
static let shared = RepeatingTimer()
18+
19+
var timeInterval: TimeInterval = 0
20+
21+
private var suspensionCount = 0
22+
23+
private init() { }
1824

1925
init(timeInterval: TimeInterval) {
2026
self.timeInterval = timeInterval
@@ -53,19 +59,33 @@ class RepeatingTimer {
5359
if state.value == .resumed {
5460
return
5561
}
62+
suspensionCount -= 1
5663
state.mutate { state in
5764
state = .resumed
5865
}
59-
timer.resume()
66+
if Clickstream.timerCrashFixFlag {
67+
if suspensionCount > 0 {
68+
self.timer.resume()
69+
}
70+
} else {
71+
timer.resume()
72+
}
6073
}
6174

6275
func suspend() {
6376
if state.value == .suspended {
6477
return
6578
}
79+
suspensionCount += 1
6680
state.mutate { state in
6781
state = .suspended
6882
}
69-
timer.suspend()
83+
if Clickstream.timerCrashFixFlag {
84+
if suspensionCount > 0 {
85+
timer.suspend()
86+
}
87+
} else {
88+
timer.suspend()
89+
}
7090
}
7191
}

Sources/Clickstream/NetworkManager/Infrastructure/Utilities/KeepAliveService.swift

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,28 @@ final class DefaultKeepAliveServiceWithSafeTimer: KeepAliveService {
8989

9090
@discardableResult
9191
private func makeTimer() -> RepeatingTimer? {
92-
let timerDuration = duration*reachability.connectionRetryCoefficient
93-
timer = RepeatingTimer(timeInterval: timerDuration)
94-
timer?.eventHandler = { [weak self] in
95-
guard let checkedSelf = self else { return }
96-
checkedSelf.performQueue.async {
97-
checkedSelf.subscriber?()
92+
if Clickstream.timerCrashFixFlag {
93+
let timerDuration = duration*reachability.connectionRetryCoefficient
94+
RepeatingTimer.shared.timeInterval = timerDuration
95+
self.timer = RepeatingTimer.shared
96+
timer?.eventHandler = { [weak self] in
97+
guard let checkedSelf = self else { return }
98+
checkedSelf.performQueue.async {
99+
checkedSelf.subscriber?()
100+
}
101+
}
102+
return timer
103+
} else {
104+
let timerDuration = duration*reachability.connectionRetryCoefficient
105+
self.timer = RepeatingTimer(timeInterval: timerDuration)
106+
timer?.eventHandler = { [weak self] in
107+
guard let checkedSelf = self else { return }
108+
checkedSelf.performQueue.async {
109+
checkedSelf.subscriber?()
110+
}
98111
}
112+
return timer
99113
}
100-
return timer
101114
}
102115

103116
func stop() {

Sources/EventVisualizer/src/EventDetails/EventDetailsViewModel.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import Foundation
1010
import SwiftProtobuf
11+
import UIKit
1112

1213
protocol EventDetailsModelInput: AnyObject {
1314

Sources/EventVisualizer/src/EventsList/EventsListViewModel.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ final class EventsListViewModel: EventsListViewModelInput {
6363
let timestamp = message.asDictionary["\(Constants.EventVisualizer.deviceTimestamp)"] as? Date {
6464
eventTimeStamp = "\(timestamp)"
6565
state = EventsHelper.shared.getState(of: eventGuid)
66+
} else if let eventGuid = message.asDictionary["storage.meta.storage.\(Constants.EventVisualizer.eventGID)"] as? String,
67+
let timestamp = message.asDictionary["storage.\(Constants.EventVisualizer.eventTimestamp)"] as? SwiftProtobuf.Google_Protobuf_Timestamp {
68+
eventTimeStamp = "\(timestamp.date)"
69+
state = EventsHelper.shared.getState(of: eventGuid)
6670
}
6771
}
6872
return EventDisplayKeys(eventTimeStamp: eventTimeStamp, state: state)

Sources/EventVisualizer/src/Helpers/EventsHelper.swift

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,9 @@ extension EventsHelper: EventStateViewable {
9191
/// - eventBatch: this is the eventBatchGuid for a particular event batch
9292
/// - state: this is the state in which the event is in
9393
public func updateStatus(providedEventGuid: String? = nil, eventBatchID eventBatch: String? = nil, state: EventState) {
94-
if let providedEventGuid = providedEventGuid, let foundIndex = indexOfEvent(with: providedEventGuid) {
94+
if let providedEventGuid = providedEventGuid,
95+
let foundIndex = indexOfEvent(with: providedEventGuid),
96+
foundIndex < EventsHelper.shared.eventsCaptured.count {
9597

9698
EventsHelper.shared.eventsCaptured[foundIndex].state = state
9799
if let eventBatch = eventBatch {
@@ -100,7 +102,9 @@ extension EventsHelper: EventStateViewable {
100102
} else if let eventBatch = eventBatch {
101103
let foundIndexs = indexOfEventBatch(with: eventBatch)
102104
for eventIndex in foundIndexs {
103-
EventsHelper.shared.eventsCaptured[eventIndex].state = state
105+
if eventIndex < EventsHelper.shared.eventsCaptured.count {
106+
EventsHelper.shared.eventsCaptured[eventIndex].state = state
107+
}
104108
}
105109
}
106110
}
@@ -113,12 +117,15 @@ extension EventsHelper: EventStateViewable {
113117
if let currentEventGuid = flattenedDict[Constants.EventVisualizer.eventGuid] as? String, currentEventGuid == eventGuid {
114118
return index
115119
} else if let currentEventGuid = flattenedDict["storage.\(Constants.EventVisualizer.eventGuid)"] as? String,
116-
currentEventGuid == eventGuid {
120+
currentEventGuid == eventGuid {
117121
return index
118122
} else if let currentEventGuid = flattenedDict[Constants.EventVisualizer.guid] as? String,
119123
currentEventGuid == eventGuid {
120-
return index
121-
}
124+
return index
125+
} else if let currentEventGuid = flattenedDict["storage.meta.storage.\(Constants.EventVisualizer.eventGID)"] as? String,
126+
currentEventGuid == eventGuid {
127+
return index
128+
}
122129
}
123130
}
124131
return nil

0 commit comments

Comments
 (0)