Skip to content

Fix showing unmute user message action just after muting the user #847

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

Merged
merged 6 commits into from
Jun 17, 2025
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 @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
# Upcoming

### 🐞 Fixed
- Fix showing unmute user message action just after muting the user [#847](https://github.com/GetStream/stream-chat-swiftui/pull/847)
- Fix rare concurrency crash in `ChannelAvatarsMerger.createMergedAvatar(from:)` [#858](https://github.com/GetStream/stream-chat-swiftui/pull/858)

# [4.79.1](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.79.1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public extension MessageAction {
if channel.config.mutesEnabled {
let author = message.author
let currentUser = chatClient.currentUserController().currentUser
let isMuted = currentUser?.mutedUsers.contains(message.author) ?? false
let isMuted = currentUser?.mutedUsers.contains(where: { $0.id == author.id }) ?? false
if isMuted {
let unmuteAction = unmuteAction(
for: message,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24A348" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B83" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
<entity name="AttachmentDTO" representedClassName="AttachmentDTO" syncable="YES">
<attribute name="data" attributeType="Binary"/>
<attribute name="id" attributeType="String"/>
Expand Down Expand Up @@ -44,6 +44,8 @@
<attribute name="defaultSortingAt" attributeType="Date" usesScalarValueType="NO" spotlightIndexingEnabled="YES"/>
<attribute name="deletedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="extraData" attributeType="Binary"/>
<attribute name="hasUnreadSorting" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
<attribute name="id" optional="YES" attributeType="String"/>
<attribute name="imageURL" optional="YES" attributeType="URI"/>
<attribute name="isBlocked" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
<attribute name="isDisabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
Expand Down Expand Up @@ -469,6 +471,7 @@
<attribute name="lastActivityAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="name" optional="YES" attributeType="String"/>
<attribute name="teams" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer"/>
<attribute name="teamsRole" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer"/>
Copy link
Member

Choose a reason for hiding this comment

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

Why has this file changed? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because we have a copy of the CoreData model (historical reasons as what I understand) and it was updated to set teamsRole when creating UserDTO. This unit-test is special because current user controller is accessed from the message actions and it requires data in the database.

<attribute name="userCreatedAt" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="userDeactivatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
<attribute name="userRoleRaw" attributeType="String"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,46 @@ class MessageActions_Tests: StreamChatTestCase {
// Then
XCTAssertTrue(messageActions.contains(where: { $0.title == "Edit Message" }))
}

func test_messageActions_currentUser_unmuteUser() throws {
// Given
// Note: internally creates current user controller
let mutedUserId = UserId.unique
try chatClient.databaseContainer.writeSynchronously { session in
try session.saveCurrentUser(
payload: .dummy(
userId: .unique,
role: .admin,
mutedUsers: [
.dummy(userId: mutedUserId)
]
)
)
}

let channel = ChatChannel.mockDMChannel(config: .mock(mutesEnabled: true))
let message = ChatMessage.mock(
id: .unique,
cid: channel.cid,
text: "Test",
author: .mock(id: mutedUserId),
isSentByCurrentUser: false
)
let factory = DefaultViewFactory.shared

// When
let messageActions = MessageAction.defaultActions(
factory: factory,
for: message,
channel: channel,
chatClient: chatClient,
onFinish: { _ in },
onError: { _ in }
)

// Then
XCTAssertTrue(messageActions.contains(where: { $0.title == "Unmute User" }))
}

// MARK: - Private

Expand Down
Loading