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 3 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
4 changes: 1 addition & 3 deletions .github/workflows/smoke-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ env:
jobs:
build-test-app-and-frameworks:
name: Build Test App and Frameworks
runs-on: macos-14
runs-on: macos-15
if: ${{ github.event_name != 'push' }}
steps:
- uses: actions/[email protected]
Expand All @@ -35,8 +35,6 @@ jobs:
- name: Build
run: bundle exec fastlane build_test_app_and_frameworks
timeout-minutes: 60
env:
XCODE_VERSION: "15.0.1" # Should match the minimum version in dependent jobs
- uses: actions/upload-artifact@v4
if: success()
with:
Expand Down
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)
- Refresh quoted message preview when the quoted message is deleted [#3553](https://github.com/GetStream/stream-chat-swift/pull/3553)
### ⚡ 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
90 changes: 90 additions & 0 deletions StreamChatUITestsAppUITests/Tests/QuotedReply_Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

import XCTest
@testable import StreamChatUI

final class QuotedReply_Tests: StreamTestCase {

Expand Down Expand Up @@ -217,6 +218,29 @@ final class QuotedReply_Tests: StreamTestCase {
userRobot.assertDeletedMessage()
}
}

func test_originalQuoteIsDeletedByParticipant_deletedMessageIsShown() {
linkToScenario(withId: 6643)

GIVEN("user opens the channel") {
userRobot.login().openChannel()
}
AND("participant sends a message") {
participantRobot.sendMessage("1")
}
AND("user adds a quoted reply") {
userRobot.quoteMessage(replyText)
}
WHEN("participant deletes an original message") {
participantRobot.deleteMessage()
}
THEN("deleted message is shown") {
userRobot.assertDeletedMessage(at: 1)
}
AND("deleted message is shown in quoted reply bubble") {
userRobot.assertQuotedMessage(L10n.Message.deletedMessagePlaceholder)
}
}

func test_quotedReplyIsDeletedByUser_deletedMessageIsShown() {
linkToScenario(withId: 109)
Expand All @@ -235,6 +259,27 @@ final class QuotedReply_Tests: StreamTestCase {
userRobot.assertDeletedMessage()
}
}

func test_originalQuoteIsDeletedByUser_deletedMessageIsShown() {
linkToScenario(withId: 6644)

GIVEN("user opens the channel") {
backendRobot.generateChannels(count: 1, messagesCount: 1)
userRobot.login().openChannel()
}
AND("user adds a quoted reply") {
userRobot.quoteMessage(replyText)
}
WHEN("user deletes an original message") {
userRobot.deleteMessage(messageCellIndex: 1)
}
THEN("deleted message is shown") {
userRobot.assertDeletedMessage(at: 1)
}
AND("deleted message is shown in quoted reply bubble") {
userRobot.assertQuotedMessage(L10n.Message.deletedMessagePlaceholder)
}
}

func test_unreadCount_whenUserSendsInvalidCommand_and_jumpingOnQuotedMessage() {
linkToScenario(withId: 1676)
Expand Down Expand Up @@ -537,6 +582,30 @@ final class QuotedReply_Tests: StreamTestCase {
userRobot.openThread().assertDeletedMessage()
}
}

func test_originalQuoteIsDeletedByParticipant_deletedMessageIsShown_InThread() {
linkToScenario(withId: 6645)

GIVEN("user opens the channel") {
backendRobot.generateChannels(count: 1, messageText: parentText, messagesCount: 1)
userRobot.login().openChannel()
}
AND("participant sends a message") {
participantRobot.replyToMessageInThread("1")
}
AND("user adds a quoted reply") {
userRobot.openThread().quoteMessage(replyText)
}
WHEN("participant deletes an original message") {
participantRobot.deleteMessage()
}
THEN("deleted message is shown") {
userRobot.assertDeletedMessage(at: 1)
}
AND("deleted message is shown in quoted reply bubble") {
userRobot.assertQuotedMessage(L10n.Message.deletedMessagePlaceholder)
}
}

func test_quotedReplyIsDeletedByUser_deletedMessageIsShown_InThread() {
linkToScenario(withId: 1965)
Expand All @@ -555,6 +624,27 @@ final class QuotedReply_Tests: StreamTestCase {
userRobot.assertDeletedMessage()
}
}

func test_originalQuoteIsDeletedByUser_deletedMessageIsShown_InThread() {
linkToScenario(withId: 6646)

GIVEN("user opens the channel") {
backendRobot.generateChannels(count: 1, messagesCount: 1)
userRobot.login().openChannel()
}
AND("user adds a quoted reply") {
userRobot.openThread().quoteMessage(replyText)
}
WHEN("user deletes an original message") {
userRobot.deleteMessage(messageCellIndex: 1)
}
THEN("deleted message is shown") {
userRobot.assertDeletedMessage(at: 1)
}
AND("deleted message is shown in quoted reply bubble") {
userRobot.assertQuotedMessage(L10n.Message.deletedMessagePlaceholder)
}
}

func test_rootMessageShouldOnlyBeVisibleInTheLastPageInThread() {
linkToScenario(withId: 1997)
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