Skip to content

Commit

Permalink
Only show Leave Group options if user has "leave-channel" permission (#…
Browse files Browse the repository at this point in the history
…633)

* Channel Actions - Only show Leave Group if user has "leave-channel" permission

* Channel Actions - Update tests for leave button

* Update Package to point to PR branch with Mock update

* Fix unit tests

* Update CHANGELOG.md

* Fix tests

---------

Co-authored-by: Ben Pollman <[email protected]>
  • Loading branch information
nuno-vieira and bpollman authored Oct 31, 2024
1 parent 57726e1 commit 5fea4bc
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions StreamChatSwiftUI.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down

0 comments on commit 5fea4bc

Please sign in to comment.