Skip to content

Commit 568942d

Browse files
authored
Merge pull request #799 from GetStream/fix/double-error-indicator-when-attachment-fails
Fix double error indicator when attachment fails + Fix message message sending state indicator
2 parents 05abfa9 + 5c2f9ac commit 568942d

11 files changed

+98
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Allow pasting images to the composer [#797](https://github.com/GetStream/stream-chat-swiftui/pull/797)
88
### 🐞 Fixed
99
- Fix allowing to send Polls when the current user does not have the capability [#798](https://github.com/GetStream/stream-chat-swiftui/pull/798)
10+
- Fix showing a double error indicator when sending attachments without any text [#799](https://github.com/GetStream/stream-chat-swiftui/pull/799)
11+
- Fix showing read indicator when message failed to be sent [#799](https://github.com/GetStream/stream-chat-swiftui/pull/799)
12+
- Fix not showing sending indicator when message is in sending state [#799](https://github.com/GetStream/stream-chat-swiftui/pull/799)
1013

1114
# [4.76.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.76.0)
1215
_March 31, 2025_

DemoAppSwiftUI/PinChannelHelpers.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ struct DemoAppChatChannelListItem: View {
5757
currentUserId: chatClient.currentUserId,
5858
message: channel.latestMessages.first
5959
),
60-
showReadCount: false
60+
showReadCount: false,
61+
localState: channel.latestMessages.first?.localState
6162
)
6263
}
6364
SubtitleText(text: injectedChannelInfo?.timestamp ?? channel.timestampText)

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
106106
)
107107
: nil
108108

109-
(message.localState == .sendingFailed || message.isBounced) ? SendFailureIndicator() : nil
109+
((message.localState == .sendingFailed || message.isBounced) && !message.text.isEmpty) ?
110+
SendFailureIndicator() : nil
110111
}
111112
)
112113
.background(

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageListHelperViews.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public struct MessageReadIndicatorView: View {
124124
.customizable()
125125
.foregroundColor(!readUsers.isEmpty ? colors.tintColor : Color(colors.textLowEmphasis))
126126
.frame(height: 16)
127+
.opacity(localState == .sendingFailed ? 0.0 : 1)
127128
.accessibilityLabel(
128129
Text(
129130
readUsers.isEmpty ? L10n.Message.ReadStatus.seenByNoOne : L10n.Message.ReadStatus.seenByOthers
@@ -136,7 +137,12 @@ public struct MessageReadIndicatorView: View {
136137
}
137138

138139
private var image: UIImage {
139-
!readUsers.isEmpty ? images.readByAll : (localState == .pendingSend ? images.messageReceiptSending : images.messageSent)
140+
!readUsers.isEmpty ? images.readByAll : (isMessageSending ? images.messageReceiptSending : images.messageSent)
141+
}
142+
143+
private var isMessageSending: Bool {
144+
localState == .sending
145+
|| localState == .pendingSend
140146
}
141147
}
142148

StreamChatSwiftUITests/Tests/ChatChannel/ChatChannelTestHelpers.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,27 @@ class ChatChannelTestHelpers {
7070
return imageAttachments
7171
}()
7272

73+
static func imageAttachment(state: LocalAttachmentState) -> AnyChatMessageAttachment {
74+
let attachmentFile = AttachmentFile(type: .png, size: 0, mimeType: "image/png")
75+
let uploadingState = AttachmentUploadingState(
76+
localFileURL: testURL,
77+
state: state,
78+
file: attachmentFile
79+
)
80+
return ChatMessageImageAttachment(
81+
id: .unique,
82+
type: .image,
83+
payload: ImageAttachmentPayload(
84+
title: "test",
85+
imageRemoteURL: testURL,
86+
extraData: [:]
87+
),
88+
downloadingState: nil,
89+
uploadingState: uploadingState
90+
)
91+
.asAnyAttachment
92+
}
93+
7394
static var giphyAttachments: [AnyChatMessageAttachment] = {
7495
let attachmentFile = AttachmentFile(type: .gif, size: 0, mimeType: "image/gif")
7596
let uploadingState = AttachmentUploadingState(

StreamChatSwiftUITests/Tests/ChatChannel/MessageContainerView_Tests.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,43 @@ class MessageContainerView_Tests: StreamChatTestCase {
261261
// Then
262262
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
263263
}
264-
264+
265+
func test_imageAttachments_failed_snapshot() {
266+
// Given
267+
let message = ChatMessage.mock(
268+
id: .unique,
269+
cid: .unique,
270+
text: "Test message",
271+
author: .mock(id: .unique),
272+
attachments: [ChatChannelTestHelpers.imageAttachment(state: .uploadingFailed)],
273+
localState: .sendingFailed
274+
)
275+
276+
// When
277+
let view = testMessageViewContainer(message: message)
278+
279+
// Then
280+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
281+
}
282+
283+
func test_imageAttachments_failedWhenMessageTextIsEmpty_snapshot() {
284+
// Given
285+
let message = ChatMessage.mock(
286+
id: .unique,
287+
cid: .unique,
288+
text: "",
289+
author: .mock(id: .unique),
290+
attachments: [ChatChannelTestHelpers.imageAttachment(state: .uploadingFailed)],
291+
localState: .sendingFailed
292+
)
293+
294+
// When
295+
let view = testMessageViewContainer(message: message)
296+
297+
// Then
298+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
299+
}
300+
265301
func test_translatedText_participant_snapshot() {
266302
// Given
267303
let message = ChatMessage.mock(

StreamChatSwiftUITests/Tests/ChatChannel/MessageReadIndicatorView_Tests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,30 @@ class MessageReadIndicatorView_Tests: StreamChatTestCase {
5858
// Then
5959
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
6060
}
61+
62+
func test_messageReadIndicatorView_snapshotSending() {
63+
// Given
64+
let view = MessageReadIndicatorView(
65+
readUsers: [],
66+
showReadCount: false,
67+
localState: .sending
68+
)
69+
.frame(width: 50, height: 16)
70+
71+
// Then
72+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
73+
}
74+
75+
func test_messageReadIndicatorView_snapshotMessageFailed() {
76+
// Given
77+
let view = MessageReadIndicatorView(
78+
readUsers: [],
79+
showReadCount: false,
80+
localState: .sendingFailed
81+
)
82+
.frame(width: 50, height: 16)
83+
84+
// Then
85+
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
86+
}
6187
}
Loading
Loading
Loading

0 commit comments

Comments
 (0)