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

Quoted message preview did not update when the quoted message was deleted #3553

Merged
merged 4 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Add `ImageAttachmentPayload.file` for setting `file_size` and `mime_type` for image attachments [#3548](https://github.com/GetStream/stream-chat-swift/pull/3548)
### 🐞 Fixed
- Remove the main thread requirement from the `DataStore` [#3541](https://github.com/GetStream/stream-chat-swift/pull/3541)
- Quoted message preview did not update when the quoted message was deleted [#3553](https://github.com/GetStream/stream-chat-swift/pull/3553)
laevandus marked this conversation as resolved.
Show resolved Hide resolved
### ⚡ Performance
- Improve performance of accessing database model properties [#3534](https://github.com/GetStream/stream-chat-swift/pull/3534)
- Improve performance of model conversions with large extra data [#3534](https://github.com/GetStream/stream-chat-swift/pull/3534)
Expand Down
8 changes: 8 additions & 0 deletions Sources/StreamChat/Database/DTOs/MessageDTO.swift
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class MessageDTO: NSManagedObject {
channel.cid = cid
}

// Refresh messages referencing the current message
if !quotedBy.isEmpty {
for message in quotedBy where !message.hasChanges && !message.isDeleted {
let messageId = message.id
message.id = messageId
}
}

prepareDefaultSortKeyIfNeeded()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ open class QuotedChatMessageView: _View, ThemeProvider, SwiftUIRepresentable {
? appearance.colorPalette.popoverBackground
: appearance.colorPalette.highlightedAccentBackground1

setText(message.text)
setText(message.textContent ?? "")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

textContent internally checks for the deleted state

setAvatar(imageUrl: message.author.imageURL)
setAvatarAlignment(avatarAlignment)

Expand All @@ -196,10 +196,11 @@ open class QuotedChatMessageView: _View, ThemeProvider, SwiftUIRepresentable {
open func setText(_ text: String) {
guard text != textView.text else { return }

let color = content?.message.isDeleted == true ? appearance.colorPalette.textLowEmphasis : appearance.colorPalette.text
let attributedText = NSMutableAttributedString(
string: text,
attributes: [
.foregroundColor: appearance.colorPalette.text,
.foregroundColor: color,
.font: appearance.fonts.subheadline
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,19 @@ final class QuotedChatMessageView_Tests: XCTestCase {

AssertSnapshot(view)
}

func test_withDeletedMessage() {
let message = ChatMessage.mock(
id: .unique,
cid: .unique,
text: "Hello Vader!",
author: .mock(id: .unique),
deletedAt: .unique,
isSentByCurrentUser: true
)
view.content = QuotedChatMessageView.Content(message: message, avatarAlignment: .leading)
AssertSnapshot(view)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to force the snapshot test to capture the grey text color. This works OK in the demo app, but snapshot test uses whatever textView.textColor is. I did not want to overcomplicate this so I left it as is. Seems to be related to order of things when view is rendered.

}

func test_withImageAttachmentAppearance() {
let attachment = ChatMessageImageAttachment.mock(
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
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading