10000 Fix/pin unpin not working for messages with attachments by nuno-vieira · Pull Request #842 · GetStream/stream-chat-swiftui · GitHub
[go: up one dir, main page]

Skip to content

Fix/pin unpin not working for messages with attachments #842

New issue

Have a question about this project? Sign up for a 8000 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

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
// This is needed for the LinkDetectionTextView to work properly.
// TODO: This should be refactored on v5 so the TextView does not depend directly on the view model.
.environment(\.messageViewModel, messageViewModel)
.onChange(of: message, perform: { message in messageViewModel.message = message })
.onChange(of: channel) { channel in messageViewModel.channel = channel }
}

private var maximumHorizontalSwipeDisplacement: CGFloat {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public struct MessageReadIndicatorView: View {

public var body: some View {
HStack(spacing: 2) {
if showReadCount && !readUsers.isEmpty {
if showReadCount && shouldShowReads {
Text("\(readUsers.count)")
.font(fonts.footnoteBold)
.foregroundColor(colors.tintColor)
Expand All @@ -122,7 +122,7 @@ public struct MessageReadIndicatorView: View {
uiImage: image
)
.customizable()
.foregroundColor(!readUsers.isEmpty ? colors.tintColor : Color(colors.textLowEmphasis))
.foregroundColor(shouldShowReads ? colors.tintColor : Color(colors.textLowEmphasis))
.frame(height: 16)
.opacity(localState == .sendingFailed || localState == .syncingFailed ? 0.0 : 1)
.accessibilityLabel(
Expand All @@ -137,12 +137,16 @@ public struct MessageReadIndicatorView: View {
}

private var image: UIImage {
!readUsers.isEmpty ? images.readByAll : (isMessageSending ? images.messageReceiptSending : images.messageSent)
shouldShowReads ? images.readByAll : (isMessageSending ? images.messageReceiptSending : images.messageSent)
}

private var isMessageSending: Bool {
localState == .sending || localState == .pendingSend || localState == .syncing
}

private var shouldShowReads: Bool {
!readUsers.isEmpty && !isMessageSending
}
}

/// Message spacer view, used for adding space depending on who sent the message..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open class MessageViewModel: ObservableObject {
@Injected(\.chatClient) private var chatClient

@Published public internal(set) var message: ChatMessage
public private(set) var channel: ChatChannel?
@Published public internal(set) var channel: ChatChannel?
private var cancellables = Set<AnyCancellable>()

public init(
Expand Down
2 changes: 1 addition & 1 deletion Sources/StreamChatSwiftUI/DefaultViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1012,7 +1012,7 @@ extension ViewFactory {
currentUserId: chatClient.currentUserId,
message: message
)
let showReadCount = channel.memberCount > 2
let showReadCount = channel.memberCount > 2 && !message.isLastActionFailed
return MessageReadIndicatorView(
readUsers: readUsers,
showReadCount: showReadCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class MessageReadIndicatorView_Tests: StreamChatTestCase {
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_messageReadIndicatorView_snapshotSyncing_whenShowReadCount() {
// Given
let view = MessageReadIndicatorView(
readUsers: [.mock(id: .unique)],
showReadCount: true,
localState: .syncing
)
.frame(width: 50, height: 16)

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_messageReadIndicatorView_snapshotMessageFailed() {
// Given
let view = MessageReadIndicatorView(
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
0