From 73ce77b24688ca291bab3a0051a142c51ac9edd1 Mon Sep 17 00:00:00 2001 From: Jaesung Lee Date: Sat, 18 Mar 2023 03:16:39 +0900 Subject: [PATCH] [FIX] Allowed nullable `MessageList/menuContent` --- .../ChatUI/ChatInChannel/MessageList.swift | 39 +++++++++++++++---- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/Sources/ChatUI/ChatInChannel/MessageList.swift b/Sources/ChatUI/ChatInChannel/MessageList.swift index 54aabbf..1439a10 100644 --- a/Sources/ChatUI/ChatInChannel/MessageList.swift +++ b/Sources/ChatUI/ChatInChannel/MessageList.swift @@ -254,7 +254,7 @@ public struct MessageList RowContent, - @ViewBuilder menuContent: @escaping (_ message: MessageType) -> MenuContent + menuContent: ((_ message: MessageType) -> MenuContent)? = nil ) { var sendingMessages: [MessageType] = [] var failedMessages: [MessageType] = [] @@ -312,14 +312,37 @@ public struct MessageList RowContent ) where MenuContent == EmptyView { - self.init( - messageData, - showsDate: showsDate, - reactionItems: reactionItems, - rowContent: rowContent - ) { _ in - EmptyView() + var sendingMessages: [MessageType] = [] + var failedMessages: [MessageType] = [] + var sentMessages: [MessageType] = [] + var deliveredMessages: [MessageType] = [] + var seenMessages: [MessageType] = [] + + messageData.forEach { + switch $0.readReceipt { + case .sending: + sendingMessages.append($0) + case .failed: + failedMessages.append($0) + case .sent: + sentMessages.append($0) + case .delivered: + deliveredMessages.append($0) + case .seen, .played: + seenMessages.append($0) + } } + + self.sendingMessages = sendingMessages + self.failedMessages = failedMessages + self.sentMessages = sentMessages + self.deliveredMessages = deliveredMessages + self.seenMessages = seenMessages + + self.showsDate = showsDate + self.rowContent = rowContent + self.reactionItems = reactionItems + self.messageMenuContent = nil } var sendingMessageList: some View {