Skip to content

Commit 0541496

Browse files
authored
Fix/pin unpin not working for messages with attachments (#842)
1 parent 88bd595 commit 0541496

File tree

6 files changed

+24
-5
lines changed

6 files changed

+24
-5
lines changed

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
296296
// This is needed for the LinkDetectionTextView to work properly.
297297
// TODO: This should be refactored on v5 so the TextView does not depend directly on the view model.
298298
.environment(\.messageViewModel, messageViewModel)
299+
.onChange(of: message, perform: { message in messageViewModel.message = message })
300+
.onChange(of: channel) { channel in messageViewModel.channel = channel }
299301
}
300302

301303
private var maximumHorizontalSwipeDisplacement: CGFloat {

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListHelperViews.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public struct MessageReadIndicatorView: View {
112112

113113
public var body: some View {
114114
HStack(spacing: 2) {
115-
if showReadCount && !readUsers.isEmpty {
115+
if showReadCount && shouldShowReads {
116116
Text("\(readUsers.count)")
117117
.font(fonts.footnoteBold)
118118
.foregroundColor(colors.tintColor)
@@ -122,7 +122,7 @@ public struct MessageReadIndicatorView: View {
122122
uiImage: image
123123
)
124124
.customizable()
125-
.foregroundColor(!readUsers.isEmpty ? colors.tintColor : Color(colors.textLowEmphasis))
125+
.foregroundColor(shouldShowReads ? colors.tintColor : Color(colors.textLowEmphasis))
126126
.frame(height: 16)
127127
.opacity(localState == .sendingFailed || localState == .syncingFailed ? 0.0 : 1)
128128
.accessibilityLabel(
@@ -137,12 +137,16 @@ public struct MessageReadIndicatorView: View {
137137
}
138138

139139
private var image: UIImage {
140-
!readUsers.isEmpty ? images.readByAll : (isMessageSending ? images.messageReceiptSending : images.messageSent)
140+
shouldShowReads ? images.readByAll : (isMessageSending ? images.messageReceiptSending : images.messageSent)
141141
}
142142

143143
private var isMessageSending: Bool {
144144
localState == .sending || localState == .pendingSend || localState == .syncing
145145
}
146+
147+
private var shouldShowReads: Bool {
148+
!readUsers.isEmpty && !isMessageSending
149+
}
146150
}
147151

148152
/// Message spacer view, used for adding space depending on who sent the message..

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ open class MessageViewModel: ObservableObject {
1111
@Injected(\.chatClient) private var chatClient
1212

1313
@Published public internal(set) var message: ChatMessage
14-
public private(set) var channel: ChatChannel?
14+
@Published public internal(set) var channel: ChatChannel?
1515
private var cancellables = Set<AnyCancellable>()
1616

1717
public init(

Sources/StreamChatSwiftUI/DefaultViewFactory.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ extension ViewFactory {
10121012
currentUserId: chatClient.currentUserId,
10131013
message: message
10141014
)
1015-
let showReadCount = channel.memberCount > 2
1015+
let showReadCount = channel.memberCount > 2 && !message.isLastActionFailed
10161016
return MessageReadIndicatorView(
10171017
readUsers: readUsers,
10181018
showReadCount: showReadCount,

StreamChatSwiftUITests/Tests/ChatChannel/MessageReadIndicatorView_Tests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ class MessageReadIndicatorView_Tests: StreamChatTestCase {
8585
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
8686
}
8787

88+
func test_messageReadIndicatorView_snapshotSyncing_whenShowReadCount() {
89+
// Given
90+
let view = MessageReadIndicatorView(
91+
readUsers: [.mock(id: .unique)],
92+
showReadCount: true,
93+
localState: .syncing
94+
)
95+
.frame(width: 50, height: 16)
96+
97+
// Then
98+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
99+
}
100+
88101
func test_messageReadIndicatorView_snapshotMessageFailed() {
89102
// Given
90103
let view = MessageReadIndicatorView(

0 commit comments

Comments
 (0)