diff --git a/CHANGELOG.md b/CHANGELOG.md index f5f00b728..bc07d6004 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Add support for Channel Search in the Channel List [#628](https://github.com/GetStream/stream-chat-swiftui/pull/628) ### 🐞 Fixed - Fix crash when opening message overlay in iPad with a TabBar [#627](https://github.com/GetStream/stream-chat-swiftui/pull/627) +- Only show Leave Group option if the user has leave-channel permission [#633](https://github.com/GetStream/stream-chat-swiftui/pull/633) # [4.65.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.65.0) _October 18, 2024_ 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..f4be98d11 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 = develop; + 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..f11ea200e 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift @@ -222,11 +222,23 @@ 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 cidDM = ChannelId(type: .messaging, id: "!members" + .newUniqueId) let channel = ChatChannel.mock( - cid: .unique, - name: "Test", + cid: cidDM, ownCapabilities: [.deleteChannel] ) let viewModel = ChatChannelInfoViewModel(channel: channel) @@ -262,6 +274,7 @@ class ChatChannelInfoViewModel_Tests: StreamChatTestCase { if updateCapabilities { capabilities.insert(.updateChannel) capabilities.insert(.deleteChannel) + capabilities.insert(.leaveChannel) } let channel = ChatChannel.mock( cid: cid, diff --git a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift index ea3661a9c..cd581ac97 100644 --- a/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift +++ b/StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift @@ -103,7 +103,7 @@ class ChatChannelInfoView_Tests: StreamChatTestCase { let group = ChatChannel.mock( cid: .unique, name: "Test Group", - ownCapabilities: [.deleteChannel, .updateChannel], + ownCapabilities: [.leaveChannel, .updateChannel], lastActiveMembers: members, memberCount: members.count ) @@ -151,7 +151,7 @@ class ChatChannelInfoView_Tests: StreamChatTestCase { let group = ChatChannel.mock( cid: .unique, name: "Test Group", - ownCapabilities: [.deleteChannel, .updateChannel], + ownCapabilities: [.updateChannel, .leaveChannel], lastActiveMembers: members, memberCount: members.count )