Skip to content

Commit 91043a7

Browse files
committed
Fixes according to review
1 parent 8b2e684 commit 91043a7

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

Sources/Miscellaneous/ChatAdapter.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,21 @@ class ChatAdapter {
2626
}
2727
}
2828

29-
static func associate(chat: ChatImpl, with kotlinChat: PubNubChat.ChatImpl) {
30-
queue.sync {
29+
static func associate(chat: ChatImpl, with kotlinChat: PubNubChat.ChatImpl) {
30+
queue.sync {
31+
associations.removeAll {
32+
$0.isEmpty()
33+
}
34+
if let existing = associations.first(where: {
35+
!$0.isEmpty() && ($0.chat === chat || $0.kotlinChat === kotlinChat)
36+
}) {
37+
existing._chat = chat
38+
existing._kotlinChat = kotlinChat
39+
} else {
3140
associations.append(.init(chat: chat, kotlinChat: kotlinChat))
3241
}
3342
}
43+
}
3444

3545
static func clean() {
3646
queue.sync {
@@ -46,8 +56,8 @@ class ChatAdapter {
4656
// swiftlint:disable:next force_unwrapping
4757
var kotlinChat: PubNubChat.ChatImpl { _kotlinChat! }
4858

49-
private weak var _chat: ChatImpl?
50-
private weak var _kotlinChat: PubNubChat.ChatImpl?
59+
weak var _chat: ChatImpl?
60+
weak var _kotlinChat: PubNubChat.ChatImpl?
5161

5262
init(chat: ChatImpl, kotlinChat: PubNubChat.ChatImpl) {
5363
_chat = chat

0 commit comments

Comments
 (0)