Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
martinmitrevski committed Dec 6, 2023
1 parent abe5099 commit 2db505b
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 32 deletions.
14 changes: 7 additions & 7 deletions Sources/StreamChatSwiftUI/ChatChannel/ChatChannelViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
private func applicationWillEnterForeground() {
guard let first = messages.first else { return }
if canMarkRead {
maybeSendReadEvent(for: first)
sendReadEventIfNeeded(for: first)
}
}

Expand All @@ -224,7 +224,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}

public func jumpToMessage(messageId: String) -> Bool {
if messageId == "unknown" {
if messageId == .unknownMessageId {
if firstUnreadMessageId == nil, let lastReadMessageId {
channelDataSource.loadPageAroundMessageId(lastReadMessageId) { [weak self] error in
if error != nil {
Expand Down Expand Up @@ -313,7 +313,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
if index == 0 {
let isActive = UIApplication.shared.applicationState == .active
if isActive && canMarkRead {
maybeSendReadEvent(for: message)
sendReadEventIfNeeded(for: message)
}
}
}
Expand Down Expand Up @@ -390,14 +390,14 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}
}

maybeRefreshMessageList()
refreshMessageListIfNeeded()

if !showScrollToLatestButton && scrolledId == nil && !loadingNextMessages {
updateScrolledIdToNewestMessage()
}

if lastMessageRead != nil && firstUnreadMessageId == nil {
self.firstUnreadMessageId = channelDataSource.firstUnreadMessageId
firstUnreadMessageId = channelDataSource.firstUnreadMessageId
}
}

Expand Down Expand Up @@ -497,7 +497,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
)
}

private func maybeSendReadEvent(for message: ChatMessage) {
private func sendReadEventIfNeeded(for message: ChatMessage) {
if message.id != lastMessageRead {
lastMessageRead = message.id
throttler.throttle { [weak self] in
Expand All @@ -509,7 +509,7 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}
}

private func maybeRefreshMessageList() {
private func refreshMessageListIfNeeded() {
let count = messages.count
if count > lastRefreshThreshold {
lastRefreshThreshold = lastRefreshThreshold + refreshThreshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct JumpToUnreadButton: View {
@Injected(\.colors) var colors

var unreadCount: Int
var onTap: () -> ()
var onClose: () -> ()
var onTap: () -> Void
var onClose: () -> Void

var body: some View {
HStack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,9 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
ForEach(messages, id: \.messageId) { message in
var index: Int? = messageListDateUtils.indexForMessageDate(message: message, in: messages)
let messageDate: Date? = messageListDateUtils.showMessageDate(for: index, in: messages)
let showUnreadSeparator = messageListConfig.showNewMessagesSeparator && (message.messageId == firstUnreadMessageId || message.id == firstUnreadMessageId)
let messageIsFirstUnread = message.messageId == firstUnreadMessageId ||
message.id == firstUnreadMessageId
let showUnreadSeparator = messageListConfig.showNewMessagesSeparator && messageIsFirstUnread
let showsLastInGroupInfo = showsLastInGroupInfo(for: message, channel: channel)
factory.makeMessageContainerView(
channel: channel,
Expand Down Expand Up @@ -289,16 +291,16 @@ public struct MessageListView<Factory: ViewFactory>: View, KeyboardReadable {
}
})
.overlay(
(channel.unreadCount.messages > 0 && !unreadMessagesBannerShown) ?
factory.makeJumpToUnreadButton(
channel: channel,
onJumpToMessage: {
_ = onJumpToMessage?(firstUnreadMessageId ?? "unknown")
},
onClose: {
firstUnreadMessageId = nil
}
) : nil
(channel.unreadCount.messages > 0 && !unreadMessagesBannerShown) ?
factory.makeJumpToUnreadButton(
channel: channel,
onJumpToMessage: {
_ = onJumpToMessage?(firstUnreadMessageId ?? .unknownMessageId)
},
onClose: {
firstUnreadMessageId = nil
}
) : nil
)
.modifier(factory.makeMessageListContainerModifier())
.modifier(HideKeyboardOnTapGesture(shouldAdd: keyboardShown))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,22 +456,21 @@ extension MessageAction {
let channelController = chatClient.channelController(for: channel.cid)
let action = {
channelController.markUnread(from: message.id) { result in
switch result {
case .success(_):
if case let .failure(error) = result {
onError(error)
} else {
onFinish(
MessageActionInfo(
message: message,
identifier: "markUnread"
identifier: MessageActionId.markUnread
)
)
case .failure(let error):
onError(error)
}
}
}
let unreadAction = MessageAction(
id: "markUnread",
title: "Mark Unread",
id: MessageActionId.markUnread,
title: L10n.Message.Actions.markUnread,
iconName: "message.badge",
action: action,
confirmationPopup: nil,
Expand Down Expand Up @@ -665,4 +664,5 @@ public enum MessageActionId {
public static let pin = "pin_message_action"
public static let unpin = "unpin_message_action"
public static let resend = "resend_message_action"
public static let markUnread = "mark_unread_action"
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class MessageActionsResolver: MessageActionsResolving {
viewModel.editedMessage = info.message
viewModel.quotedMessage = nil
}
} else if info.identifier == "markUnread" {
} else if info.identifier == MessageActionId.markUnread {
viewModel.firstUnreadMessageId = info.message.messageId
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/StreamChatSwiftUI/DefaultViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -879,8 +879,8 @@ extension ViewFactory {

public func makeJumpToUnreadButton(
channel: ChatChannel,
onJumpToMessage: @escaping () -> (),
onClose: @escaping () -> ()
onJumpToMessage: @escaping () -> Void,
onClose: @escaping () -> Void
) -> some View {
VStack {
JumpToUnreadButton(
Expand Down
2 changes: 2 additions & 0 deletions Sources/StreamChatSwiftUI/Generated/L10n.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,8 @@ internal enum L10n {
internal static var flag: String { L10n.tr("Localizable", "message.actions.flag") }
/// Reply
internal static var inlineReply: String { L10n.tr("Localizable", "message.actions.inline-reply") }
/// Mark Unread
internal static var markUnread: String { L10n.tr("Localizable", "message.actions.mark-unread") }
/// Pin to conversation
internal static var pin: String { L10n.tr("Localizable", "message.actions.pin") }
/// Resend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"message.actions.user-mute" = "Mute User";
"message.actions.resend" = "Resend";
"message.actions.flag" = "Flag Message";
"message.actions.mark-unread" = "Mark Unread";
"message.actions.flag.confirmation-title" = "Flag Message";
"message.actions.flag.confirmation-message" = "Do you want to send a copy of this message to a moderator for further investigation?";

Expand Down
2 changes: 2 additions & 0 deletions Sources/StreamChatSwiftUI/Utils/StringExtensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,6 @@ extension String {

return false
}

static let unknownMessageId = "unknown"
}
4 changes: 2 additions & 2 deletions Sources/StreamChatSwiftUI/ViewFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ public protocol ViewFactory: AnyObject {
/// - Returns: view shown in the jump to unread slot.
func makeJumpToUnreadButton(
channel: ChatChannel,
onJumpToMessage: @escaping () -> (),
onClose: @escaping () -> ()
onJumpToMessage: @escaping () -> Void,
onClose: @escaping () -> Void
) -> JumpToUnreadButtonType
}

0 comments on commit 2db505b

Please sign in to comment.