Skip to content

Commit

Permalink
[REMOVE THIS COMMIT] Implement edited feature
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Mar 8, 2024
1 parent bfbe384 commit eec945e
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### ✅ Added
- Link detection in the text views
- Indicator when a message was edited

# [4.49.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.49.0)
_February 28, 2024_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,11 @@ open class ChatChannelViewModel: ObservableObject, MessagesDataSource {
}

let delay = previousMessage.createdAt.timeIntervalSince(date)
let showMessageEditedLabel = utils.messageListConfig.isMessageEditedLabelEnabled
&& message.textUpdatedAt != nil

if delay > utils.messageListConfig.maxTimeIntervalBetweenMessagesInGroup {
if delay > utils.messageListConfig.maxTimeIntervalBetweenMessagesInGroup
|| showMessageEditedLabel {
temp[message.id]?.append(firstMessageKey)
var prevInfo = temp[previousMessage.id] ?? []
prevInfo.append(lastMessageKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class DefaultMessageIdBuilder: MessageIdBuilder {
if message.localState != nil {
statesId = message.uploadingStatesId
}
if message.textUpdatedAt != nil {
statesId = "edited"
}
return message.baseId + statesId + message.reactionScoresId
+ message.repliesCountId + "\(message.updatedAt)" + message.pinStateId
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public struct MessageListConfig {
handleTabBarVisibility: Bool = true,
messageListAlignment: MessageListAlignment = .standard,
uniqueReactionsEnabled: Bool = false,
localLinkDetectionEnabled: Bool = true
localLinkDetectionEnabled: Bool = true,
isMessageEditedLabelEnabled: Bool = true
) {
self.messageListType = messageListType
self.typingIndicatorPlacement = typingIndicatorPlacement
Expand All @@ -50,6 +51,7 @@ public struct MessageListConfig {
self.messageListAlignment = messageListAlignment
self.uniqueReactionsEnabled = uniqueReactionsEnabled
self.localLinkDetectionEnabled = localLinkDetectionEnabled
self.isMessageEditedLabelEnabled = isMessageEditedLabelEnabled
}

public let messageListType: MessageListType
Expand All @@ -72,6 +74,7 @@ public struct MessageListConfig {
public let messageListAlignment: MessageListAlignment
public let uniqueReactionsEnabled: Bool
public let localLinkDetectionEnabled: Bool
public let isMessageEditedLabelEnabled: Bool
}

/// Contains information about the message paddings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,19 @@ struct MessageDateView: View {

var message: ChatMessage

var text: String {
var text = dateFormatter.string(from: message.createdAt)
let showMessageEditedLabel = utils.messageListConfig.isMessageEditedLabelEnabled
&& message.textUpdatedAt != nil
&& !message.isDeleted
if showMessageEditedLabel {
text = text + "" + L10n.Message.Cell.edited
}
return text
}

var body: some View {
Text(dateFormatter.string(from: message.createdAt))
Text(text)
.font(fonts.footnote)
.foregroundColor(Color(colors.textLowEmphasis))
.animation(nil)
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 @@ -315,6 +315,8 @@ internal enum L10n {
internal static var title: String { L10n.tr("Localizable", "message.bounce.title") }
}
internal enum Cell {
/// Edited
internal static var edited: String { L10n.tr("Localizable", "message.cell.edited") }
/// Pinned by
internal static var pinnedBy: String { L10n.tr("Localizable", "message.cell.pinnedBy") }
/// unknown
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"message.gallery.photos" = "Photos";
"message.cell.pinnedBy" = "Pinned by";
"message.cell.unknownPin" = "unknown";
"message.cell.edited" = "Edited";
"message.reactions.currentUser" = "You";

"alert.actions.cancel" = "Cancel";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@ class MessageContainerView_Tests: StreamChatTestCase {
// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_messageContainerEdited_snapshot() {
// Given
streamChat = StreamChat(chatClient: chatClient)
let message = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "Message sent by current user",
author: .mock(id: Self.currentUserId, name: "Martin"),
isSentByCurrentUser: true,
textUpdatedAt: Date()
)

// When
let view = testMessageViewContainer(message: message)

// Then
assertSnapshot(matching: view, as: .image(perceptualPrecision: precision))
}

func test_messageContainerViewSentOtherUser_snapshot() {
// Given
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import XCTest

@available(iOS 15.0, *)
class MessageListScrollTime: StreamTestCase {

// FIXME
override func setUpWithError() throws {
mockServerEnabled = false
try super.setUpWithError()
}

func testMessageListScrollTime() {
WHEN("user opens the message list") {
backendRobot.generateChannels(count: 1, messagesCount: 100, withAttachments: true)
participantRobot.addReaction(type: .like)
// FIXME
// backendRobot.generateChannels(count: 1, messagesCount: 100, withAttachments: true)
// participantRobot.addReaction(type: .like)
userRobot.login().openChannel()
}
THEN("user scrolls the message list") {
Expand Down

0 comments on commit eec945e

Please sign in to comment.