Skip to content
Closed
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
26 changes: 13 additions & 13 deletions Sources/StreamChat/Database/DatabaseContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
context.setChatClientConfig(chatClientConfig)
return context
}()

/// An immediately reacting NSManagedObjectContext for the chat state layer.
///
/// Chat state layer requires that the context is refreshed when a write happens. Otherwise database observers are too slow to react.
Expand Down Expand Up @@ -200,7 +200,7 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
log.debug("Context has no changes. Skipping save.", subsystems: .database)
}

log.debug("Database session succesfully saved.", subsystems: .database)
log.debug("Database session successfully saved.", subsystems: .database)
completion(nil)
} catch {
log.error("Failed to save data to DB. Error: \(error)", subsystems: .database)
Expand All @@ -210,7 +210,7 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
}
}
}

func write(_ actions: @escaping @Sendable (DatabaseSession) throws -> Void) async throws {
try await withCheckedThrowingContinuation { (continuation: CheckedContinuation<Void, Error>) in
write(actions) { error in
Expand All @@ -222,7 +222,7 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
}
}
}

func write<T>(converting actions: @escaping @Sendable (DatabaseSession) throws -> T, completion: @escaping @Sendable (Result<T, Error>) -> Void) where T: Sendable {
nonisolated(unsafe) var result: T?
write { session in
Expand All @@ -238,7 +238,7 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
}
}
}

private func read<T>(
from context: NSManagedObjectContext,
_ actions: @escaping @Sendable (DatabaseSession) throws -> T,
Expand All @@ -257,19 +257,19 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
}
}
}

func read<T>(_ actions: @escaping @Sendable (DatabaseSession) throws -> T, completion: @escaping @Sendable (Result<T, Error>) -> Void) {
read(from: backgroundReadOnlyContext, actions, completion: completion)
}

func read<T>(_ actions: @escaping @Sendable (DatabaseSession) throws -> T) async throws -> T where T: Sendable {
try await withCheckedThrowingContinuation { continuation in
read(from: stateLayerContext, actions) { result in
continuation.resume(with: result)
}
}
}

func readAndWait<T>(_ actions: @Sendable (DatabaseSession) throws -> T) throws -> T where T: Sendable {
let context = backgroundReadOnlyContext
nonisolated(unsafe) var result: T?
Expand Down Expand Up @@ -324,14 +324,14 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
if let writableContext = self?.writableContext, let allContext = self?.allContext {
writableContext.invalidateCurrentUserCache()
writableContext.reset()

for context in allContext where context != writableContext {
context.performAndWait {
context.invalidateCurrentUserCache()
context.reset()
}
}

if FileManager.default.fileExists(atPath: URL.streamAttachmentDownloadsDirectory.path) {
do {
try FileManager.default.removeItem(at: .streamAttachmentDownloadsDirectory)
Expand Down Expand Up @@ -429,12 +429,12 @@ class DatabaseContainer: NSPersistentContainer, @unchecked Sendable {
let dtoClasses = managedObjectModel.entities
.compactMap(\.name)
.compactMap { NSClassFromString($0) }

// Reset relationships
for dtoClass in dtoClasses {
dtoClass.resetEphemeralRelationshipValues?(in: writableContext)
}

// Reset properties without relationships
let allRequests: [NSBatchUpdateRequest] = dtoClasses
.compactMap { $0.resetEphemeralValuesBatchRequests?() }
Expand Down Expand Up @@ -477,7 +477,7 @@ extension NSManagedObjectContext {
"deleted": deletedObjects.count
]
}

func observeChanges(in otherContext: NSManagedObjectContext) -> NSObjectProtocol {
assert(!automaticallyMergesChangesFromParent, "Duplicate change handling")
return NotificationCenter.default
Expand Down
4 changes: 2 additions & 2 deletions StreamChatUITestsAppUITests/Tests/Attachments_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ final class Attachments_Tests: StreamTestCase {
userRobot.assertVideo(isPresent: true)
}
}

func test_participantUploadsFile() throws {
linkToScenario(withId: 33)

Expand All @@ -70,7 +70,7 @@ final class Attachments_Tests: StreamTestCase {
.login()
.openChannel()
}
WHEN("user sends an image beeing offline") {
WHEN("user sends an image being offline") {
userRobot
.setConnectivity(to: .off)
.uploadImage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
backendRobot.delayNewMessages(by: 10)
userRobot.sendMessage(message, waitForAppearance: false)
}
WHEN("user retuns to the channel list before the message is sent") {
WHEN("user returns to the channel list before the message is sent") {
userRobot.tapOnBackButton()
}
THEN("last message delivery status in the channel preview shows clocks on the left") {
Expand All @@ -45,7 +45,7 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
AND("user sends new message") {
userRobot.sendMessage(message)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.tapOnBackButton()
}
THEN("last message delivery status in the channel preview shows single checkmark on the right") {
Expand All @@ -69,7 +69,7 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
.sendMessage(failedMessage, waitForAppearance: false)
.assertMessageFailedToBeSent()
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.tapOnBackButton()
}
THEN("error indicator is shown for the failed message") {
Expand All @@ -87,10 +87,10 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("user retuns to the channel list") {
AND("user returns to the channel list") {
userRobot.tapOnBackButton()
}
WHEN("participant reads the user's message") {
Expand All @@ -116,7 +116,7 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
AND("user sends a new message") {
userRobot.sendMessage(message)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.tapOnBackButton()
}
THEN("delivery status is hidden") {
Expand All @@ -137,7 +137,7 @@ final class MessageDeliveryStatus_ChannelList_Tests: StreamTestCase {
WHEN("participant sends a new message") {
participantRobot.sendMessage(message)
}
AND("user retuns to the channel list") {
AND("user returns to the channel list") {
userRobot.tapOnBackButton()
}
THEN("delivery status is hidden") {
Expand Down Expand Up @@ -165,7 +165,7 @@ extension MessageDeliveryStatus_ChannelList_Tests {
AND("user replies to the message in thread") {
userRobot.sendMessageInThread(threadReply)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.moveToChannelListFromThreadReplies()
}
THEN("delivery status is hidden") {
Expand Down Expand Up @@ -193,7 +193,7 @@ extension MessageDeliveryStatus_ChannelList_Tests {
AND("user replies to message in thread") {
userRobot.sendMessageInThread(failedThreadReply, waitForAppearance: false)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.moveToChannelListFromThreadReplies()
}
THEN("delivery status shows error indicator") {
Expand Down Expand Up @@ -221,7 +221,7 @@ extension MessageDeliveryStatus_ChannelList_Tests {
AND("participant reads the user's thread reply") {
participantRobot.readMessage()
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.moveToChannelListFromThreadReplies()
}
THEN("user spots double checkmark next to the message") {
Expand Down Expand Up @@ -249,7 +249,7 @@ extension MessageDeliveryStatus_ChannelList_Tests {
AND("user replies to message in thread") {
userRobot.sendMessageInThread(threadReply)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.moveToChannelListFromThreadReplies()
}
THEN("delivery status is hidden") {
Expand All @@ -274,7 +274,7 @@ extension MessageDeliveryStatus_ChannelList_Tests {
AND("participant replies to message in thread") {
participantRobot.sendMessageInThread(threadReply)
}
WHEN("user retuns to the channel list") {
WHEN("user returns to the channel list") {
userRobot.moveToChannelListFromThreadReplies()
}
THEN("delivery status is hidden") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ final class MessageDeliveryStatus_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
WHEN("participant reads the user's message") {
Expand All @@ -102,7 +102,7 @@ final class MessageDeliveryStatus_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("message is read by more than 1 participant") {
Expand Down Expand Up @@ -130,7 +130,7 @@ final class MessageDeliveryStatus_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("is read by participant") {
Expand All @@ -156,7 +156,7 @@ final class MessageDeliveryStatus_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("delivery status shows single checkmark") {
Expand All @@ -181,7 +181,7 @@ final class MessageDeliveryStatus_Tests: StreamTestCase {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("delivery status shows single checkmark") {
Expand Down Expand Up @@ -211,7 +211,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends a new message") {
AND("user successfully sends a new message") {
userRobot.sendMessage(message)
}
WHEN("user previews thread for message: \(message)") {
Expand Down Expand Up @@ -347,7 +347,7 @@ extension MessageDeliveryStatus_Tests {

func test_noDoubleCheckmarkShownInThreadReply_whenNewParticipantAdded() throws {
linkToScenario(withId: 154)

GIVEN("user opens the channel") {
userRobot
.login()
Expand Down Expand Up @@ -462,7 +462,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("succesfully sends a new message") {
AND("successfully sends a new message") {
userRobot.sendMessage(message)
}
WHEN("user sends message with invalid command") {
Expand Down Expand Up @@ -554,7 +554,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
WHEN("participant reads the user's message") {
Expand All @@ -576,7 +576,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("message is read by more than 1 participant") {
Expand All @@ -601,7 +601,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("is read by participant") {
Expand All @@ -628,7 +628,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("delivery status is hidden") {
Expand All @@ -654,7 +654,7 @@ extension MessageDeliveryStatus_Tests {
.login()
.openChannel()
}
AND("user succesfully sends new message") {
AND("user successfully sends new message") {
userRobot.sendMessage(message)
}
AND("delivery status is hidden") {
Expand Down
Loading