Skip to content

Commit 5690d2e

Browse files
authored
Fix showing unmute user message action just after muting the user (#847)
1 parent 6f8686f commit 5690d2e

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
44
# Upcoming
55

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

910
# [4.79.1](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.79.1)

Sources/StreamChatSwiftUI/ChatChannel/Reactions/MessageActions/DefaultMessageActions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public extension MessageAction {
182182
if channel.config.mutesEnabled {
183183
let author = message.author
184184
let currentUser = chatClient.currentUserController().currentUser
185-
let isMuted = currentUser?.mutedUsers.contains(message.author) ?? false
185+
let isMuted = currentUser?.mutedUsers.contains(where: { $0.id == author.id }) ?? false
186186
if isMuted {
187187
let unmuteAction = unmuteAction(
188188
for: message,

StreamChatSwiftUITests/Infrastructure/Shared/StreamChatModel.xcdatamodeld/StreamChatModel.xcdatamodel/contents

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2-
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23605" systemVersion="24A348" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
2+
<model type="com.apple.IDECoreDataModeler.DataModel" documentVersion="1.0" lastSavedToolsVersion="23507" systemVersion="24B83" minimumToolsVersion="Automatic" sourceLanguage="Swift" userDefinedModelVersionIdentifier="">
33
<entity name="AttachmentDTO" representedClassName="AttachmentDTO" syncable="YES">
44
<attribute name="data" attributeType="Binary"/>
55
<attribute name="id" attributeType="String"/>
@@ -44,6 +44,8 @@
4444
<attribute name="defaultSortingAt" attributeType="Date" usesScalarValueType="NO" spotlightIndexingEnabled="YES"/>
4545
<attribute name="deletedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
4646
<attribute name="extraData" attributeType="Binary"/>
47+
<attribute name="hasUnreadSorting" attributeType="Integer 16" defaultValueString="0" usesScalarValueType="YES"/>
48+
<attribute name="id" optional="YES" attributeType="String"/>
4749
<attribute name="imageURL" optional="YES" attributeType="URI"/>
4850
<attribute name="isBlocked" optional="YES" attributeType="Boolean" usesScalarValueType="YES"/>
4951
<attribute name="isDisabled" attributeType="Boolean" defaultValueString="NO" usesScalarValueType="YES"/>
@@ -469,6 +471,7 @@
469471
<attribute name="lastActivityAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
470472
<attribute name="name" optional="YES" attributeType="String"/>
471473
<attribute name="teams" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer"/>
474+
<attribute name="teamsRole" optional="YES" attributeType="Transformable" valueTransformerName="NSSecureUnarchiveFromDataTransformer"/>
472475
<attribute name="userCreatedAt" attributeType="Date" usesScalarValueType="NO"/>
473476
<attribute name="userDeactivatedAt" optional="YES" attributeType="Date" usesScalarValueType="NO"/>
474477
<attribute name="userRoleRaw" attributeType="String"/>

StreamChatSwiftUITests/Tests/ChatChannel/MessageActions_Tests.swift

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,46 @@ class MessageActions_Tests: StreamChatTestCase {
375375
// Then
376376
XCTAssertTrue(messageActions.contains(where: { $0.title == "Edit Message" }))
377377
}
378+
379+
func test_messageActions_currentUser_unmuteUser() throws {
380+
// Given
381+
// Note: internally creates current user controller
382+
let mutedUserId = UserId.unique
383+
try chatClient.databaseContainer.writeSynchronously { session in
384+
try session.saveCurrentUser(
385+
payload: .dummy(
386+
userId: .unique,
387+
role: .admin,
388+
mutedUsers: [
389+
.dummy(userId: mutedUserId)
390+
]
391+
)
392+
)
393+
}
394+
395+
let channel = ChatChannel.mockDMChannel(config: .mock(mutesEnabled: true))
396+
let message = ChatMessage.mock(
397+
id: .unique,
398+
cid: channel.cid,
399+
text: "Test",
400+
author: .mock(id: mutedUserId),
401+
isSentByCurrentUser: false
402+
)
403+
let factory = DefaultViewFactory.shared
404+
405+
// When
406+
let messageActions = MessageAction.defaultActions(
407+
factory: factory,
408+
for: message,
409+
channel: channel,
410+
chatClient: chatClient,
411+
onFinish: { _ in },
412+
onError: { _ in }
413+
)
414+
415+
// Then
416+
XCTAssertTrue(messageActions.contains(where: { $0.title == "Unmute User" }))
417+
}
378418

379419
// MARK: - Private
380420

0 commit comments

Comments
 (0)