Skip to content

Commit 34bccf9

Browse files
committed
Fixed ChannelPresenter.
1 parent a7cc654 commit 34bccf9

File tree

4 files changed

+10
-17
lines changed

4 files changed

+10
-17
lines changed

Sources/Core/Client/Client+Events.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public extension Client {
1919
/// - eventType: an event type.
2020
/// - channelId: a channeld id (optional).
2121
/// - Returns: an observable event.
22-
func onEvent(_ eventType: EventType? = nil, for channelId: String? = nil) -> Observable<Event> {
22+
func onEvent(_ eventType: EventType? = nil, channelId: String? = nil) -> Observable<Event> {
2323
return webSocket.response
2424
.filter {
2525
if let channelId = channelId {

Sources/Core/Model/Message.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,14 @@ public struct Message: Codable {
181181
replyCount = try container.decode(Int.self, forKey: .replyCount)
182182
latestReactions = try container.decode([Reaction].self, forKey: .latestReactions)
183183
ownReactions = try container.decode([Reaction].self, forKey: .ownReactions)
184-
reactionCounts = try container.decodeIfPresent(ReactionCounts.self, forKey: .reactionCounts)
185184
extraData = .decode(from: decoder, ExtraData.decodableTypes.first(where: { $0.isMessage }))
185+
186+
if let reactionCounts = try container.decodeIfPresent(ReactionCounts.self, forKey: .reactionCounts),
187+
!reactionCounts.counts.isEmpty {
188+
self.reactionCounts = reactionCounts
189+
} else {
190+
reactionCounts = nil
191+
}
186192
}
187193

188194
private func checkIfTextAsAttachmentURL(_ text: String) -> Bool {

Sources/Core/Presenter/ChannelPresenter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public final class ChannelPresenter: Presenter<ChatItem> {
106106
.filter { $0 != .none }
107107
.asDriver { Driver.just(ViewChanges.error(AnyError(error: $0))) }
108108

109-
private lazy var webSocketChanges: Driver<ViewChanges> = channel.onEvent()
109+
private lazy var webSocketChanges: Driver<ViewChanges> = Client.shared.onEvent(channelId: channelId)
110110
.map { [weak self] in self?.parseChanges(event: $0) ?? .none }
111111
.filter { $0 != .none }
112112
.map { [weak self] in self?.mapWithEphemeralMessage($0) ?? .none }
@@ -215,7 +215,7 @@ extension ChannelPresenter {
215215

216216
if let messageNewChannel = messageNewChannel {
217217
channelMVar.set(messageNewChannel)
218-
}
218+
}
219219

220220
if channel.config.readEventsEnabled {
221221
if let lastMessage = lastMessageMVar.get() {

StreamChatCoreTests/Integration Tests/ChannelTests.swift

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,19 +98,6 @@ final class ChannelTests: TestCase {
9898
return nil
9999
}
100100
.unwrap()
101-
.flatMapLatest { $0.deleteReaction(.like) }
102-
.map { response -> Message? in
103-
if let reactionCounts = response.message.reactionCounts {
104-
XCTAssertEqual(reactionCounts.counts, [ReactionType.love: 1])
105-
XCTAssertEqual(reactionCounts.string, "\(ReactionType.love.emoji)1")
106-
return response.message
107-
}
108-
109-
XCTFail("Failed to delete a reaction")
110-
111-
return nil
112-
}
113-
.unwrap()
114101
.flatMapLatest { $0.deleteReaction(.love) }
115102
.map { response -> Message? in
116103
XCTAssertNil(response.message.reactionCounts)

0 commit comments

Comments
 (0)