Skip to content

Commit b326fe6

Browse files
Added handling for bounced messages (#405)
1 parent 7df1f28 commit b326fe6

File tree

7 files changed

+62
-3
lines changed

7 files changed

+62
-3
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
- Jump to a message that is not on the first page
88
- Jump to a message in a thread
99
- Bi-directional scrolling of the message list
10+
- Handling of bounced messages
1011

1112
### 🐞 Fixed
1213
- Some links not being rendered correctly

Sources/StreamChatSwiftUI/ChatChannel/MessageList/MessageContainerView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
6060

6161
public var body: some View {
6262
HStack(alignment: .bottom) {
63-
if message.type == .system || message.type == .error {
63+
if message.type == .system || (message.type == .error && message.isBounced == false) {
6464
factory.makeSystemMessageView(message: message)
6565
} else {
6666
if message.isRightAligned {
@@ -105,7 +105,7 @@ public struct MessageContainerView<Factory: ViewFactory>: View {
105105
)
106106
: nil
107107

108-
message.localState == .sendingFailed ? SendFailureIndicator() : nil
108+
(message.localState == .sendingFailed || message.isBounced) ? SendFailureIndicator() : nil
109109
}
110110
)
111111
.background(

Sources/StreamChatSwiftUI/ChatChannel/Reactions/MessageActions/DefaultMessageActions.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ extension MessageAction {
4242
onError: onError
4343
)
4444
return messageActions
45+
} else if message.isBounced {
46+
let title = MessageAction(
47+
title: L10n.Message.Bounce.title,
48+
iconName: "exclamationmark.octagon.fill",
49+
action: {},
50+
confirmationPopup: nil,
51+
isDestructive: false
52+
)
53+
messageActions = messageNotSentActions(
54+
for: message,
55+
channel: channel,
56+
chatClient: chatClient,
57+
onFinish: onFinish,
58+
onError: onError
59+
)
60+
messageActions.insert(title, at: 0)
61+
return messageActions
4562
}
4663

4764
if channel.config.quotesEnabled {

Sources/StreamChatSwiftUI/ChatChannel/Reactions/ReactionsOverlayView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public struct ReactionsOverlayView<Factory: ViewFactory>: View {
132132
x: messageOriginX(proxy: reader)
133133
)
134134
.overlay(
135-
channel.config.reactionsEnabled ?
135+
(channel.config.reactionsEnabled && !messageDisplayInfo.message.isBounced) ?
136136
factory.makeReactionsContentView(
137137
message: viewModel.message,
138138
contentRect: messageDisplayInfo.frame,

Sources/StreamChatSwiftUI/Generated/L10n.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,10 @@ internal enum L10n {
300300
internal static var confirmationTitle: String { L10n.tr("Localizable", "message.actions.flag.confirmation-title") }
301301
}
302302
}
303+
internal enum Bounce {
304+
/// Message was bounced
305+
internal static var title: String { L10n.tr("Localizable", "message.bounce.title") }
306+
}
303307
internal enum Cell {
304308
/// Pinned by
305309
internal static var pinnedBy: String { L10n.tr("Localizable", "message.cell.pinnedBy") }

Sources/StreamChatSwiftUI/Resources/en.lproj/Localizable.strings

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
"message.search.title" = "Search";
107107
"message.search.cancel" = "Cancel";
108108

109+
"message.bounce.title" = "Message was bounced";
110+
109111
"current-selection" = "%d of %d";
110112

111113
"attachment.max-size-exceeded" = "Attachment size exceed the limit.";

StreamChatSwiftUITests/Tests/ChatChannel/MessageActions_Tests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,39 @@ class MessageActions_Tests: StreamChatTestCase {
174174
XCTAssert(messageActions[0].title == "Edit Message")
175175
XCTAssert(messageActions[1].title == "Delete Message")
176176
}
177+
178+
func test_messageActions_bouncedMessage() {
179+
// Given
180+
let channel = ChatChannel.mockDMChannel()
181+
let moderationDetails = MessageModerationDetails(
182+
originalText: "Some text",
183+
action: .bounce
184+
)
185+
let message = ChatMessage.mock(
186+
id: .unique,
187+
cid: channel.cid,
188+
text: "Test",
189+
author: .mock(id: chatClient.currentUserId!),
190+
isBounced: true,
191+
moderationsDetails: moderationDetails
192+
)
193+
let factory = DefaultViewFactory.shared
194+
195+
// When
196+
let messageActions = MessageAction.defaultActions(
197+
factory: factory,
198+
for: message,
199+
channel: channel,
200+
chatClient: chatClient,
201+
onFinish: { _ in },
202+
onError: { _ in }
203+
)
204+
205+
// Then
206+
XCTAssert(messageActions.count == 4)
207+
XCTAssert(messageActions[0].title == "Message was bounced")
208+
XCTAssert(messageActions[1].title == "Resend")
209+
XCTAssert(messageActions[2].title == "Edit Message")
210+
XCTAssert(messageActions[3].title == "Delete Message")
211+
}
177212
}

0 commit comments

Comments
 (0)