Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Make `VoiceRecordingButton` public [#658](https://github.com/GetStream/stream-chat-swiftui/pull/658)
### 🐞 Fixed
- Fix message long press taking too much time to show actions [#648](https://github.com/GetStream/stream-chat-swiftui/pull/648)
- Fix rendering link attachment preview with other attachment types [#659](https://github.com/GetStream/stream-chat-swiftui/pull/659)
### 🔄 Changed
- Message composer now uses `.uploadFile` capability when showing attachment picker icon [#646](https://github.com/GetStream/stream-chat-swiftui/pull/646)
- `ChannelInfoView` now uses `.updateChannelMembers` capability to show "Add Users" button [#651](https://github.com/GetStream/stream-chat-swiftui/pull/651)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public struct MessageView<Factory: ViewFactory>: View {
} else if let poll = message.poll {
factory.makePollView(message: message, poll: poll, isFirst: isFirst)
} else if !message.attachmentCounts.isEmpty {
if messageTypeResolver.hasLinkAttachment(message: message) {
let hasOnlyLinks = message.attachmentCounts.keys.allSatisfy { $0 == .linkPreview }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As you stated in the PR description - probably good to move this in the resolver directly. It's a small breaking change in functionality, but it's actually a bug fix. We can deal with the inaccurate method name in a major release.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing is that we are doing this kinda logic with video attachment as well, where we only render the video attachment view if there is not image attachment as well:

messageTypeResolver.hasVideoAttachment(message: message)
                    && !messageTypeResolver.hasImageAttachment(message: message)

That is why opted for this approach as well 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Maybe we can just put the check directly after the &&, so it's executed only when hasLinkAttachment is true?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes makes sense 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done ✅

if messageTypeResolver.hasLinkAttachment(message: message) && hasOnlyLinks {
factory.makeLinkAttachmentView(
for: message,
isFirst: isFirst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,33 @@ class MessageView_Tests: StreamChatTestCase {
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_linkAttachmentView_shouldNotRenderLinkPreviewWithOtherAttachments() {
// Given
let messageWithLinkAndImages = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "https://getstream.io",
author: .mock(id: .unique),
attachments: [
ChatChannelTestHelpers.imageAttachments[0],
ChatChannelTestHelpers.videoAttachments[0]
]
)

// When
let view = MessageView(
factory: DefaultViewFactory.shared,
message: messageWithLinkAndImages,
contentWidth: defaultScreenSize.width,
isFirst: true,
scrolledId: .constant(nil)
)
.applyDefaultSize()

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

func test_deletedMessageView_snapshot() {
// Given
let message = ChatMessage.mock(
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