Skip to content

Commit ff114d9

Browse files
jullianmgithub-actions[bot]
authored andcommitted
fix: revisit conditions to display channel creation option - WPB-18788 (#3376)
1 parent f0f4986 commit ff114d9

File tree

5 files changed

+82
-2
lines changed

5 files changed

+82
-2
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

wire-ios/Wire-iOS Tests/StartUIViewControllerSnapshotTests.swift

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,66 @@ final class StartUIViewControllerSnapshotTests: CoreDataSnapshotTestCase {
123123
.verify(matching: navigationController.view)
124124
}
125125
}
126+
127+
func testStartUIViewControllerShowNewChannelOptionForPersonalUser() {
128+
// Given, channels are supported and user is a personal user
129+
BackendInfo.apiVersion = .v8
130+
BackendInfo.isMLSEnabled = true
131+
132+
nonTeamTest {
133+
let navigationController = setupNavigationController()
134+
snapshotHelper
135+
.withUserInterfaceStyle(.dark)
136+
.verify(matching: navigationController.view)
137+
}
138+
}
139+
140+
func testStartUIViewControllerShowNewChannelOptionForTeamUser() {
141+
// Given, channels are supported
142+
BackendInfo.apiVersion = .v8
143+
BackendInfo.isMLSEnabled = true
144+
// channels are enabled
145+
userSession.channelsFeature = Feature.Channels(
146+
status: .enabled,
147+
config: .init(
148+
allowedToCreateChannels: .teamMembers,
149+
allowedToOpenChannels: .admins
150+
)
151+
)
152+
// user is in a team and is allowed to create a channel
153+
let mockUserType = MockUserType()
154+
mockUserType.hasTeam = true
155+
mockUserType.teamRole = .member
156+
userSession.selfUser = mockUserType
157+
158+
let navigationController = setupNavigationController()
159+
snapshotHelper
160+
.withUserInterfaceStyle(.dark)
161+
.verify(matching: navigationController.view)
162+
}
163+
164+
func testStartUIViewControllerHideNewChannelOptionForTeamUser() {
165+
// Given, channels are supported
166+
BackendInfo.apiVersion = .v8
167+
BackendInfo.isMLSEnabled = true
168+
169+
// user is in a team
170+
let mockUserType = MockUserType()
171+
mockUserType.hasTeam = true
172+
userSession.selfUser = mockUserType
173+
174+
// but channels are disabled
175+
userSession.channelsFeature = Feature.Channels(
176+
status: .disabled,
177+
config: .init(
178+
allowedToCreateChannels: .teamMembers,
179+
allowedToOpenChannels: .admins
180+
)
181+
)
182+
183+
let navigationController = setupNavigationController()
184+
snapshotHelper
185+
.withUserInterfaceStyle(.dark)
186+
.verify(matching: navigationController.view)
187+
}
126188
}

wire-ios/Wire-iOS/Sources/UserInterface/StartUI/StartUI/StartUIViewController.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ final class StartUIViewController: UIViewController {
4444
let groupSelector = SearchGroupSelector()
4545

4646
lazy var conversationTypePicker: UIViewController = {
47-
let availableConversationTypes: Set<WireMultiParticipantConversationType> = if areChannelsSupported {
47+
let canCreateChannels = userSession.channelsFeature.canCreateChannels(
48+
role: userSession.selfUser.teamRole
49+
)
50+
51+
let isTeamUser = userSession.selfUser.hasTeam
52+
53+
let availableConversationTypes: Set<WireMultiParticipantConversationType> = if areChannelsSupported,
54+
canCreateChannels ||
55+
!isTeamUser {
4856
[.channel, .group]
4957
} else {
5058
[.group]
@@ -62,7 +70,7 @@ final class StartUIViewController: UIViewController {
6270
case .channel:
6371
Task { @MainActor [weak self] in
6472
guard let self else { return }
65-
if userSession.channelsFeature.canCreateChannels(role: userSession.selfUser.teamRole) {
73+
if canCreateChannels {
6674
navigateToChannelCreation()
6775
} else {
6876
presentCreateTeamBanner()
@@ -331,6 +339,7 @@ final class StartUIViewController: UIViewController {
331339
guard backendInfoApiVersion >= .v8 else {
332340
return false
333341
}
342+
334343
return true
335344
}
336345

0 commit comments

Comments
 (0)