diff --git a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift index b3deb4d66..7e3bd71c9 100644 --- a/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift +++ b/Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift @@ -37,8 +37,11 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe @Published public var addUsersShown = false public var shouldShowLeaveConversationButton: Bool { - channel.ownCapabilities.contains(.deleteChannel) - || !channel.isDirectMessageChannel + if channel.isDirectMessageChannel { + return channel.ownCapabilities.contains(.deleteChannel) + } else { + return channel.ownCapabilities.contains(.leaveChannel) + } } public var canRenameChannel: Bool { diff --git a/Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift b/Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift index f1523e182..51c587ce2 100644 --- a/Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift +++ b/Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift @@ -25,7 +25,7 @@ extension ChannelAction { actions.append(viewInfo) - if !channel.isDirectMessageChannel, let userId = chatClient.currentUserId { + if !channel.isDirectMessageChannel, channel.ownCapabilities.contains(.leaveChannel), let userId = chatClient.currentUserId { let leaveGroup = leaveGroup( for: channel, chatClient: chatClient, diff --git a/StreamChatSwiftUI.xcodeproj/project.pbxproj b/StreamChatSwiftUI.xcodeproj/project.pbxproj index a8307d909..97e942798 100644 --- a/StreamChatSwiftUI.xcodeproj/project.pbxproj +++ b/StreamChatSwiftUI.xcodeproj/project.pbxproj @@ -3818,10 +3818,10 @@ }; 84E95A75284A486600699FD3 /* XCRemoteSwiftPackageReference "stream-chat-swift" */ = { isa = XCRemoteSwiftPackageReference; - repositoryURL = "https://github.com/GetStream/stream-chat-swift.git"; + repositoryURL = "https://github.com/bpollman/stream-chat-swift.git"; requirement = { - kind = upToNextMajorVersion; - minimumVersion = 4.65.0; + branch = "update-dm-mocks"; + kind = branch; }; }; E3A1C01A282BAC66002D1E26 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = { diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift index 0c59a4e4b..10aab329e 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift @@ -222,10 +222,21 @@ class ChatChannelInfoViewModel_Tests: StreamChatTestCase { XCTAssert(leaveButton == true) } + func test_chatChannelInfoVM_leaveButtonHiddenInGroup() { + // Given + let channel = mockGroup(with: 5, updateCapabilities: false) + let viewModel = ChatChannelInfoViewModel(channel: channel) + + // When + let leaveButton = viewModel.shouldShowLeaveConversationButton + + // Then + XCTAssert(leaveButton == false) + } + func test_chatChannelInfoVM_leaveButtonShownInDM() { // Given - let channel = ChatChannel.mock( - cid: .unique, + let channel = ChatChannel.mockDMChannel( name: "Test", ownCapabilities: [.deleteChannel] ) @@ -262,6 +273,7 @@ class ChatChannelInfoViewModel_Tests: StreamChatTestCase { if updateCapabilities { capabilities.insert(.updateChannel) capabilities.insert(.deleteChannel) + capabilities.insert(.leaveChannel) } let channel = ChatChannel.mock( cid: cid,