Skip to content

Commit 8604faf

Browse files
committed
review: Use Date instead of UInt64 for expiration time
1 parent ca23217 commit 8604faf

File tree

4 files changed

+11
-9
lines changed

4 files changed

+11
-9
lines changed

ElementX/Sources/Services/ElementCall/ElementCallService.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,18 +177,19 @@ class ElementCallService: NSObject, ElementCallServiceProtocol, PKPushRegistryDe
177177
let callID = CallID(callKitID: UUID(), roomID: roomID, rtcNotificationID: rtcNotificationID)
178178
incomingCallID = callID
179179

180-
guard let expirationTimestamp = (payload.dictionaryPayload[ElementCallServiceNotificationKey.expirationTimestampMillis.rawValue] as? NSNumber)?.uint64Value else {
180+
guard let expirationDate = (payload.dictionaryPayload[ElementCallServiceNotificationKey.expirationDate.rawValue] as? Date) else {
181181
MXLog.error("Something went wrong, missing expiration timestamp for incoming voip call: \(payload)")
182182
return
183183
}
184-
let nowTimestampMillis = UInt64(timeClock.nowDate().timeIntervalSince1970 * 1000)
185184

186-
guard nowTimestampMillis < expirationTimestamp else {
185+
let nowDate = timeClock.nowDate()
186+
187+
guard nowDate < expirationDate else {
187188
MXLog.warning("Call expired for room \(roomID), ignoring incoming push")
188189
return
189190
}
190191

191-
let ringDurationMillis = min(expirationTimestamp - nowTimestampMillis, 90000)
192+
let ringDurationMillis = min(expirationDate.timeIntervalSince1970 - nowDate.timeIntervalSince1970, 90) * 1000
192193

193194
let roomDisplayName = payload.dictionaryPayload[ElementCallServiceNotificationKey.roomDisplayName.rawValue] as? String
194195

ElementX/Sources/Services/ElementCall/ElementCallServiceConstants.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ enum ElementCallServiceNotificationKey: String {
1414
/// When an incoming call is set to ring, there will be a `m.rtc.notification`event (MSC4075).
1515
/// Keep the notification event id as it is needed to decline calls (MSC4310).
1616
case rtcNotifyEventID
17-
/// The local timestamp in millis at which the incoming call should stop ringing.
18-
case expirationTimestampMillis
17+
/// The Date at which the incoming call should stop ringing.
18+
case expirationDate
1919
}
2020

2121
let ElementCallServiceNotificationDiscardDelta = 15.0

NSE/Sources/NotificationHandler.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ class NotificationHandler {
210210
}
211211
}
212212

213+
let expirationDate = Date(timeIntervalSince1970: TimeInterval(expirationTimestamp / 1000))
213214
let payload = [ElementCallServiceNotificationKey.roomID.rawValue: roomID,
214215
ElementCallServiceNotificationKey.roomDisplayName.rawValue: roomDisplayName,
215-
ElementCallServiceNotificationKey.expirationTimestampMillis.rawValue: expirationTimestamp,
216+
ElementCallServiceNotificationKey.expirationDate.rawValue: expirationDate,
216217
ElementCallServiceNotificationKey.rtcNotifyEventID.rawValue: rtcNotifyEventID] as [String: Any]
217218

218219
do {

UnitTests/Sources/ElementCallServiceTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,15 +117,15 @@ private class PKPushPayloadMock: PKPushPayload {
117117
dict[ElementCallServiceNotificationKey.roomID.rawValue] = "!room:example.com"
118118
dict[ElementCallServiceNotificationKey.roomDisplayName.rawValue] = "welcome"
119119
dict[ElementCallServiceNotificationKey.rtcNotifyEventID.rawValue] = "$000"
120-
dict[ElementCallServiceNotificationKey.expirationTimestampMillis.rawValue] = 10
120+
dict[ElementCallServiceNotificationKey.expirationDate.rawValue] = Date(timeIntervalSince1970: 10)
121121
}
122122

123123
override var dictionaryPayload: [AnyHashable: Any] {
124124
dict
125125
}
126126

127127
func addSeconds(_ from: Date, lifetime: Int) -> Self {
128-
dict[ElementCallServiceNotificationKey.expirationTimestampMillis.rawValue] = UInt64(from.timeIntervalSince1970 * 1000) + UInt64(lifetime)
128+
dict[ElementCallServiceNotificationKey.expirationDate.rawValue] = from.addingTimeInterval(TimeInterval(lifetime))
129129
return self
130130
}
131131
}

0 commit comments

Comments
 (0)