Skip to content

Commit f1289ce

Browse files
committed
Fix the ActiveLiveLocationsEndTimeTracker not triggering an UI Update
1 parent cd5dd03 commit f1289ce

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

Sources/StreamChat/Workers/Background/ActiveLiveLocationsEndTimeTracker.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,17 @@ class ActiveLiveLocationsEndTimeTracker: Worker {
7373
queue.asyncAfter(deadline: .now() + endAtTime, execute: workItem)
7474
}
7575

76+
/// It sets the location as inactive in the database and removes it from the active live locations.
77+
///
78+
/// The update of `updatedAt` is needed for the UI to be updated.
79+
/// The reason is because otherwise the `Equatable` of `SharedLocation` won't have any effect.
80+
/// Since the `endAt` is not changed, and the `isLiveSharingActive` property is a computed one.
81+
/// Which means, that when the `Equatable` is checked, it will return `true` and the UI won't update.
7682
private func setInactiveLocation(for messageId: String) {
7783
database.write { session in
7884
let message = session.message(id: messageId)
7985
message?.isActiveLiveLocation = false
86+
message?.location?.updatedAt = DBDate() // This is need for the UI to be updated.
8087
if let location = message?.location {
8188
message?.channel?.activeLiveLocations.remove(location)
8289
}

Tests/StreamChatTests/Workers/Background/ActiveLiveLocationsEndTimeTracker_Tests.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ final class ActiveLiveLocationsEndTimeTracker_Tests: XCTestCase {
127127
let messageId: MessageId = .unique
128128
let currentUserId: UserId = .unique
129129
let endAt = Date().addingTimeInterval(100)
130+
let updatedAt = Date.unique
130131

131132
// Create current user and channel
132133
try database.createCurrentUser(id: currentUserId)
@@ -144,7 +145,7 @@ final class ActiveLiveLocationsEndTimeTracker_Tests: XCTestCase {
144145
latitude: 10.0,
145146
longitude: 20.0,
146147
createdAt: Date(),
147-
updatedAt: Date(),
148+
updatedAt: updatedAt,
148149
endAt: endAt,
149150
createdByDeviceId: .unique
150151
)
@@ -162,6 +163,9 @@ final class ActiveLiveLocationsEndTimeTracker_Tests: XCTestCase {
162163

163164
// Verify work item is removed
164165
AssertAsync.willBeEqual(tracker.workItems.count, 0)
166+
let newUpdatedAt = try XCTUnwrap(database.viewContext.message(id: messageId)?.updatedAt)
167+
// The updateAt should be updated especially to trigger an UI Update.
168+
XCTAssertNotEqual(String(newUpdatedAt.timeIntervalSince1970), String(updatedAt.timeIntervalSince1970))
165169
}
166170

167171
func test_trackerDoesNotScheduleWorkItem_forMessageWithoutEndTime() throws {

0 commit comments

Comments
 (0)