Skip to content

Commit b75eb97

Browse files
authored
Fix rendering link attachment preview with other attachment types (#659)
* Fix rendering link attachment preview with other attachment types * Update CHANGELOG.md * Only evaluate the hasOnlyLinks if there is at least one link attachment
1 parent 9e831cc commit b75eb97

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Make `VoiceRecordingButton` public [#658](https://github.com/GetStream/stream-chat-swiftui/pull/658)
88
### 🐞 Fixed
99
- Fix message long press taking too much time to show actions [#648](https://github.com/GetStream/stream-chat-swiftui/pull/648)
10+
- Fix rendering link attachment preview with other attachment types [#659](https://github.com/GetStream/stream-chat-swiftui/pull/659)
1011
### 🔄 Changed
1112
- Message composer now uses `.uploadFile` capability when showing attachment picker icon [#646](https://github.com/GetStream/stream-chat-swiftui/pull/646)
1213
- `ChannelInfoView` now uses `.updateChannelMembers` capability to show "Add Users" button [#651](https://github.com/GetStream/stream-chat-swiftui/pull/651)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ public struct MessageView<Factory: ViewFactory>: View {
4444
} else if let poll = message.poll {
4545
factory.makePollView(message: message, poll: poll, isFirst: isFirst)
4646
} else if !message.attachmentCounts.isEmpty {
47-
if messageTypeResolver.hasLinkAttachment(message: message) {
47+
let hasOnlyLinks = { message.attachmentCounts.keys.allSatisfy { $0 == .linkPreview } }
48+
if messageTypeResolver.hasLinkAttachment(message: message) && hasOnlyLinks() {
4849
factory.makeLinkAttachmentView(
4950
for: message,
5051
isFirst: isFirst,

StreamChatSwiftUITests/Tests/ChatChannel/MessageView_Tests.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,33 @@ class MessageView_Tests: StreamChatTestCase {
388388
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
389389
}
390390

391+
func test_linkAttachmentView_shouldNotRenderLinkPreviewWithOtherAttachments() {
392+
// Given
393+
let messageWithLinkAndImages = ChatMessage.mock(
394+
id: .unique,
395+
cid: .unique,
396+
text: "https://getstream.io",
397+
author: .mock(id: .unique),
398+
attachments: [
399+
ChatChannelTestHelpers.imageAttachments[0],
400+
ChatChannelTestHelpers.videoAttachments[0]
401+
]
402+
)
403+
404+
// When
405+
let view = MessageView(
406+
factory: DefaultViewFactory.shared,
407+
message: messageWithLinkAndImages,
408+
contentWidth: defaultScreenSize.width,
409+
isFirst: true,
410+
scrolledId: .constant(nil)
411+
)
412+
.applyDefaultSize()
413+
414+
// Then
415+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
416+
}
417+
391418
func test_deletedMessageView_snapshot() {
392419
// Given
393420
let message = ChatMessage.mock(
Loading

0 commit comments

Comments
 (0)