Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CIS-1079] Fix CoreData misuse when creating Direct Messaging channels #1337

Merged
merged 1 commit into from
Aug 2, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Fix compilation for Xcode 13 beta 3 where SDK could not compile because of unvailability of `UIApplication.shared` [#1333](https://github.com/GetStream/stream-chat-swift/pull/1333)
- Fix member removed from a Channel is still present is MemberListController.members [#1323](https://github.com/GetStream/stream-chat-swift/issues/1323)
- Fix composer input field height for long text [#1335](https://github.com/GetStream/stream-chat-swift/issues/1335)
- Fix creating direct messaging channels creates CoreData misuse [#1337](https://github.com/GetStream/stream-chat-swift/issues/1337)

### 🔄 Changed
- `ContainerStackView` doesn't `assert` when trying to remove a subview, these operations are now no-op [#1328](https://github.com/GetStream/stream-chat-swift/issues/1328)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,17 @@ public class _ChatChannelController<ExtraData: ExtraDataTypes>: DataController,
_messagesObserver.computeValue = { [unowned self] in
guard let cid = self.cid else { return nil }
let sortAscending = self.listOrdering == .topToBottom ? false : true
let deletedMessageVisibility = self.client.databaseContainer.viewContext
.deletedMessagesVisibility ?? .visibleForCurrentUser
var deletedMessageVisibility: ChatClientConfig.DeletedMessageVisibility?
self.client.databaseContainer.viewContext.performAndWait {
deletedMessageVisibility = self.client.databaseContainer.viewContext.deletedMessagesVisibility
}

let observer = ListDatabaseObserver(
context: self.client.databaseContainer.viewContext,
fetchRequest: MessageDTO.messagesFetchRequest(
for: cid,
sortAscending: sortAscending,
deletedMessagesVisibility: deletedMessageVisibility
deletedMessagesVisibility: deletedMessageVisibility ?? .visibleForCurrentUser
),
itemCreator: { $0.asModel() as _ChatMessage<ExtraData> }
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,17 @@ class ChannelController_Tests: StressTestCase {
try client.databaseContainer.writeSynchronously {
try $0.saveChannel(payload: payload, query: nil)
}
env.channelUpdater?.update_channelCreatedCallback?(channelId)
env.channelUpdater?.update_completion?(.success(dummyPayload(with: .unique)))

// We call these callbacks on a queue other than main queue
// to simulate the actual scenario where callbacks will be called
// from NSURLSession-delegate (serial) queue
let _: Bool = try waitFor { completion in
DispatchQueue.global().async {
self.env.channelUpdater?.update_channelCreatedCallback?(self.channelId)
self.env.channelUpdater?.update_completion?(.success(self.dummyPayload(with: .unique)))
completion(true)
}
}

XCTAssertEqual(controller.channel?.cid, channelId)
XCTAssertEqual(controller.messages.count, payload.messages.count)
Expand Down