Skip to content

Commit 5fea4bc

Browse files
Only show Leave Group options if user has "leave-channel" permission (#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]>
1 parent 57726e1 commit 5fea4bc

File tree

6 files changed

+27
-10
lines changed

6 files changed

+27
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
77
- Add support for Channel Search in the Channel List [#628](https://github.com/GetStream/stream-chat-swiftui/pull/628)
88
### 🐞 Fixed
99
- Fix crash when opening message overlay in iPad with a TabBar [#627](https://github.com/GetStream/stream-chat-swiftui/pull/627)
10+
- Only show Leave Group option if the user has leave-channel permission [#633](https://github.com/GetStream/stream-chat-swiftui/pull/633)
1011

1112
# [4.65.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.65.0)
1213
_October 18, 2024_

Sources/StreamChatSwiftUI/ChatChannel/ChannelInfo/ChatChannelInfoViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ public class ChatChannelInfoViewModel: ObservableObject, ChatChannelControllerDe
3737
@Published public var addUsersShown = false
3838

3939
public var shouldShowLeaveConversationButton: Bool {
40-
channel.ownCapabilities.contains(.deleteChannel)
41-
|| !channel.isDirectMessageChannel
40+
if channel.isDirectMessageChannel {
41+
return channel.ownCapabilities.contains(.deleteChannel)
42+
} else {
43+
return channel.ownCapabilities.contains(.leaveChannel)
44+
}
4245
}
4346

4447
public var canRenameChannel: Bool {

Sources/StreamChatSwiftUI/ChatChannelList/DefaultChannelActions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension ChannelAction {
2525

2626
actions.append(viewInfo)
2727

28-
if !channel.isDirectMessageChannel, let userId = chatClient.currentUserId {
28+
if !channel.isDirectMessageChannel, channel.ownCapabilities.contains(.leaveChannel), let userId = chatClient.currentUserId {
2929
let leaveGroup = leaveGroup(
3030
for: channel,
3131
chatClient: chatClient,

StreamChatSwiftUI.xcodeproj/project.pbxproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3818,10 +3818,10 @@
38183818
};
38193819
84E95A75284A486600699FD3 /* XCRemoteSwiftPackageReference "stream-chat-swift" */ = {
38203820
isa = XCRemoteSwiftPackageReference;
3821-
repositoryURL = "https://github.com/GetStream/stream-chat-swift.git";
3821+
repositoryURL = "https://github.com/bpollman/stream-chat-swift.git";
38223822
requirement = {
3823-
kind = upToNextMajorVersion;
3824-
minimumVersion = 4.65.0;
3823+
branch = develop;
3824+
kind = branch;
38253825
};
38263826
};
38273827
E3A1C01A282BAC66002D1E26 /* XCRemoteSwiftPackageReference "sentry-cocoa" */ = {

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoViewModel_Tests.swift

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,23 @@ class ChatChannelInfoViewModel_Tests: StreamChatTestCase {
222222
XCTAssert(leaveButton == true)
223223
}
224224

225+
func test_chatChannelInfoVM_leaveButtonHiddenInGroup() {
226+
// Given
227+
let channel = mockGroup(with: 5, updateCapabilities: false)
228+
let viewModel = ChatChannelInfoViewModel(channel: channel)
229+
230+
// When
231+
let leaveButton = viewModel.shouldShowLeaveConversationButton
232+
233+
// Then
234+
XCTAssert(leaveButton == false)
235+
}
236+
225237
func test_chatChannelInfoVM_leaveButtonShownInDM() {
226238
// Given
239+
let cidDM = ChannelId(type: .messaging, id: "!members" + .newUniqueId)
227240
let channel = ChatChannel.mock(
228-
cid: .unique,
229-
name: "Test",
241+
cid: cidDM,
230242
ownCapabilities: [.deleteChannel]
231243
)
232244
let viewModel = ChatChannelInfoViewModel(channel: channel)
@@ -262,6 +274,7 @@ class ChatChannelInfoViewModel_Tests: StreamChatTestCase {
262274
if updateCapabilities {
263275
capabilities.insert(.updateChannel)
264276
capabilities.insert(.deleteChannel)
277+
capabilities.insert(.leaveChannel)
265278
}
266279
let channel = ChatChannel.mock(
267280
cid: cid,

StreamChatSwiftUITests/Tests/ChatChannel/ChannelInfo/ChatChannelInfoView_Tests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
103103
let group = ChatChannel.mock(
104104
cid: .unique,
105105
name: "Test Group",
106-
ownCapabilities: [.deleteChannel, .updateChannel],
106+
ownCapabilities: [.leaveChannel, .updateChannel],
107107
lastActiveMembers: members,
108108
memberCount: members.count
109109
)
@@ -151,7 +151,7 @@ class ChatChannelInfoView_Tests: StreamChatTestCase {
151151
let group = ChatChannel.mock(
152152
cid: .unique,
153153
name: "Test Group",
154-
ownCapabilities: [.deleteChannel, .updateChannel],
154+
ownCapabilities: [.updateChannel, .leaveChannel],
155155
lastActiveMembers: members,
156156
memberCount: members.count
157157
)

0 commit comments

Comments
 (0)