Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added indicator when a message was edited #447

Merged
merged 4 commits into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.49.0"),
.package(url: "https://github.com/GetStream/stream-chat-swift.git", from: "4.50.0"),
],
targets: [
.target(
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
2 changes: 1 addition & 1 deletion StreamChatSwiftUI-XCFramework.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Pod::Spec.new do |spec|

spec.framework = "Foundation", "UIKit", "SwiftUI"

spec.dependency "StreamChat-XCFramework", "~> 4.49.0"
spec.dependency "StreamChat-XCFramework", "~> 4.50.0"

spec.cocoapods_version = ">= 1.11.0"
end
2 changes: 1 addition & 1 deletion StreamChatSwiftUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Pod::Spec.new do |spec|

spec.framework = "Foundation", "UIKit", "SwiftUI"

spec.dependency "StreamChat", "~> 4.49.0"
spec.dependency "StreamChat", "~> 4.50.0"
end

2 changes: 1 addition & 1 deletion StreamChatSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3376,7 +3376,7 @@
repositoryURL = "https://github.com/GetStream/stream-chat-swift.git";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 4.49.0;
minimumVersion = 4.50.0;
};
};
E3A1C01A282BAC66002D1E26 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,25 @@
// 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))

Check failure on line 53 in StreamChatSwiftUITests/Tests/ChatChannel/MessageContainerView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageContainerEdited_snapshot, failed - Snapshot does not match reference.

Check failure on line 53 in StreamChatSwiftUITests/Tests/ChatChannel/MessageContainerView_Tests.swift

View workflow job for this annotation

GitHub Actions / Test SwiftUI (Debug)

test_messageContainerEdited_snapshot, failed - Snapshot does not match reference.
}

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.
Loading