Skip to content

Commit 5ab6f90

Browse files
authored
Last Owner should edit admins, and not leave when is last (#4372)
1 parent be525e6 commit 5ab6f90

File tree

67 files changed

+691
-363
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+691
-363
lines changed

ElementX.xcodeproj/project.pbxproj

Lines changed: 25 additions & 38 deletions
Large diffs are not rendered by default.

ElementX/Resources/Localizations/en.lproj/Localizable.strings

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@
242242
"common_poll_undisclosed_text" = "Results will show after the poll has ended";
243243
"common_preparing" = "Preparing…";
244244
"common_privacy_policy" = "Privacy policy";
245+
"common_private_room" = "Private room";
246+
"common_private_space" = "Private space";
247+
"common_public_room" = "Public room";
248+
"common_public_space" = "Public space";
245249
"common_reaction" = "Reaction";
246250
"common_reactions" = "Reactions";
247251
"common_reason" = "Reason";
@@ -556,6 +560,7 @@
556560
"screen_room_pinned_banner_view_all_button_title" = "View All";
557561
"screen_room_single_knock_request_title" = "%1$@ wants to join this room";
558562
"screen_room_single_knock_request_view_button_title" = "View";
563+
"screen_room_change_role_administrators_or_owners_title" = "Edit Admins or Owners";
559564
"screen_room_details_pinned_events_row_title" = "Pinned messages";
560565
"screen_room_details_profile_row_title" = "Profile";
561566
"screen_room_details_requests_to_join_title" = "Requests to join";
@@ -714,7 +719,6 @@
714719
"screen_create_room_action_create_room" = "New room";
715720
"screen_create_room_error_creating_room" = "An error occurred when creating the room";
716721
"screen_create_room_private_option_description" = "Only people invited can access this room. All messages are end-to-end encrypted.";
717-
"screen_create_room_private_option_title" = "Private room";
718722
"screen_create_room_public_option_description" = "Anyone can find this room.\nYou can change this anytime in room settings.";
719723
"screen_create_room_topic_label" = "Topic (optional)";
720724
"screen_deactivate_account_confirmation_dialog_content" = "Please confirm that you want to deactivate your account. This action cannot be undone.";
@@ -952,7 +956,6 @@
952956
"screen_room_details_already_invited" = "Already invited";
953957
"screen_room_details_badge_encrypted" = "Encrypted";
954958
"screen_room_details_badge_not_encrypted" = "Not encrypted";
955-
"screen_room_details_badge_public" = "Public room";
956959
"screen_room_details_edit_room_title" = "Edit Room";
957960
"screen_room_details_edition_error" = "There was an unknown error and the information couldn't be changed.";
958961
"screen_room_details_edition_error_title" = "Unable to update room";
@@ -1295,6 +1298,7 @@
12951298
"screen_create_account_title" = "Create account";
12961299
"screen_create_poll_cancel_confirmation_content_ios" = "Your changes won’t be saved";
12971300
"screen_create_room_add_people_title" = "Invite people";
1301+
"screen_create_room_private_option_title" = "Private room";
12981302
"screen_create_room_public_option_title" = "Public room";
12991303
"screen_create_room_room_name_label" = "Room name";
13001304
"screen_create_room_title" = "Create a room";
@@ -1324,6 +1328,7 @@
13241328
"screen_room_change_role_section_moderators" = "Moderators";
13251329
"screen_room_change_role_section_users" = "Members";
13261330
"screen_room_change_role_unsaved_changes_title" = "Save changes?";
1331+
"screen_room_details_badge_public" = "Public room";
13271332
"screen_room_details_invite_people_title" = "Invite people";
13281333
"screen_room_details_leave_conversation_title" = "Leave conversation";
13291334
"screen_room_details_leave_room_title" = "Leave room";

ElementX/Resources/Localizations/en.lproj/Localizable.stringsdict

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
<key>NSStringFormatValueTypeKey</key>
7878
<string>d</string>
7979
<key>one</key>
80-
<string>%1$d member</string>
80+
<string>%1$d Member</string>
8181
<key>other</key>
82-
<string>%1$d members</string>
82+
<string>%1$d Members</string>
8383
</dict>
8484
</dict>
8585
<key>common_poll_votes_count</key>

ElementX/Resources/Localizations/it.lproj/Localizable.stringsdict

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@
7777
<key>NSStringFormatValueTypeKey</key>
7878
<string>d</string>
7979
<key>one</key>
80-
<string>%1$d membro</string>
80+
<string>%1$d Membro</string>
8181
<key>other</key>
82-
<string>%1$d membri</string>
82+
<string>%1$d Membri</string>
8383
</dict>
8484
</dict>
8585
<key>common_poll_votes_count</key>

ElementX/Sources/Application/Navigation/AppRoutes.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ enum AppRoute: Hashable {
4848
case chatBackupSettings
4949
/// An external share request e.g. from the ShareExtension
5050
case share(ShareExtensionPayload)
51+
/// The change roles screen of a room with the transfer ownership setting
52+
case transferOwnership(roomID: String)
5153

5254
/// Whether or not the route should be handled by the authentication flow.
5355
var isAuthenticationRoute: Bool {

ElementX/Sources/FlowCoordinators/ChatsFlowCoordinator.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
202202
}
203203
case .accountProvisioningLink:
204204
break // We always ignore this flow when logged in.
205+
case .transferOwnership(let roomID):
206+
if stateMachine.state.roomListSelectedRoomID == roomID {
207+
roomFlowCoordinator?.handleAppRoute(appRoute, animated: animated)
208+
} else {
209+
stateMachine.processEvent(.selectRoom(roomID: roomID, via: [], entryPoint: .transferOwnership))
210+
}
205211
}
206212
}
207213

@@ -232,6 +238,7 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
232238
case .roomDetails: .roomDetails(roomID: roomID)
233239
case .eventID(let eventID): .event(eventID: eventID, roomID: roomID, via: via) // ignored.
234240
case .share(let payload): .share(payload)
241+
case .transferOwnership: .transferOwnership(roomID: roomID)
235242
}
236243
roomFlowCoordinator.handleAppRoute(route, animated: animated)
237244
} else {
@@ -449,6 +456,8 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
449456
actionsSubject.send(.logout)
450457
case .presentDeclineAndBlock(let userID, let roomID):
451458
stateMachine.processEvent(.presentDeclineAndBlockScreen(userID: userID, roomID: roomID))
459+
case .transferOwnership(let roomIdentifier):
460+
handleAppRoute(.transferOwnership(roomID: roomIdentifier), animated: true)
452461
}
453462
}
454463
.store(in: &cancellables)
@@ -555,6 +564,8 @@ class ChatsFlowCoordinator: FlowCoordinatorProtocol {
555564
coordinator.handleAppRoute(.roomDetails(roomID: roomID), animated: animated)
556565
case .share(let payload):
557566
coordinator.handleAppRoute(.share(payload), animated: animated)
567+
case .transferOwnership:
568+
coordinator.handleAppRoute(.transferOwnership(roomID: roomID), animated: animated)
558569
}
559570

560571
Task {

ElementX/Sources/FlowCoordinators/EncryptionSettingsFlowCoordinator.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class EncryptionSettingsFlowCoordinator: FlowCoordinatorProtocol {
8282
case .roomList, .room, .roomAlias, .childRoom, .childRoomAlias,
8383
.roomDetails, .roomMemberDetails, .userProfile,
8484
.event, .eventOnRoomAlias, .childEvent, .childEventOnRoomAlias,
85-
.call, .genericCallLink, .settings, .share:
85+
.call, .genericCallLink, .settings, .share, .transferOwnership:
8686
// These routes aren't in this flow so clear the entire stack.
8787
clearRoute(animated: animated)
8888
case .chatBackupSettings:

ElementX/Sources/FlowCoordinators/RoomFlowCoordinator.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ enum RoomFlowCoordinatorEntryPoint: Hashable {
3737
case roomDetails
3838
/// An external media share request
3939
case share(ShareExtensionPayload)
40+
/// The flow to change the the owner of the room
41+
case transferOwnership
4042

4143
var isEventID: Bool {
4244
guard case .eventID = self else { return false }
@@ -196,7 +198,42 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
196198
break // These are converted to a room ID route one level above.
197199
case .accountProvisioningLink, .roomList, .userProfile, .call, .genericCallLink, .settings, .chatBackupSettings:
198200
break // These routes can't be handled.
201+
case .transferOwnership(let roomID):
202+
guard self.roomID == roomID else { fatalError("Navigation route doesn't belong to this room flow.") }
203+
204+
Task {
205+
if roomProxy == nil {
206+
guard case let .joined(roomProxy) = await userSession.clientProxy.roomForIdentifier(roomID) else {
207+
return
208+
}
209+
210+
await storeAndSubscribeToRoomProxy(roomProxy)
211+
}
212+
213+
presentTransferOwnershipScreen()
214+
}
215+
}
216+
}
217+
218+
private func presentTransferOwnershipScreen() {
219+
let parameters = RoomChangeRolesScreenCoordinatorParameters(mode: .owner,
220+
roomProxy: roomProxy,
221+
mediaProvider: userSession.mediaProvider,
222+
userIndicatorController: userIndicatorController,
223+
analytics: analytics)
224+
let stackCoordinator = NavigationStackCoordinator()
225+
let coordinator = RoomChangeRolesScreenCoordinator(parameters: parameters)
226+
coordinator.actionsPublisher.sink { [weak self] action in
227+
guard let self else { return }
228+
switch action {
229+
case .complete:
230+
navigationStackCoordinator.setSheetCoordinator(nil)
231+
}
199232
}
233+
.store(in: &cancellables)
234+
235+
stackCoordinator.setRootCoordinator(coordinator)
236+
navigationStackCoordinator.setSheetCoordinator(stackCoordinator, animated: true)
200237
}
201238

202239
private func presentCallScreen(roomID: String) async {
@@ -798,6 +835,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
798835
stateMachine.tryEvent(.presentRoomMemberDetails(userID: userID))
799836
case .presentReportRoomScreen:
800837
stateMachine.tryEvent(.presentReportRoomScreen)
838+
case .transferOwnership:
839+
presentTransferOwnershipScreen()
801840
}
802841
}
803842
.store(in: &cancellables)
@@ -1555,6 +1594,8 @@ class RoomFlowCoordinator: FlowCoordinatorProtocol {
15551594
coordinator.handleAppRoute(.roomDetails(roomID: roomID), animated: true)
15561595
case .share(let payload):
15571596
coordinator.handleAppRoute(.share(payload), animated: true)
1597+
case .transferOwnership:
1598+
coordinator.handleAppRoute(.transferOwnership(roomID: roomID), animated: true)
15581599
}
15591600
}
15601601

ElementX/Sources/FlowCoordinators/RoomRolesAndPermissionsFlowCoordinator.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,13 @@ class RoomRolesAndPermissionsFlowCoordinator: FlowCoordinatorProtocol {
107107

108108
stateMachine.addRoutes(event: .changeRoles, transitions: [.rolesAndPermissionsScreen => .changingRoles]) { [weak self] context in
109109
guard let role = context.userInfo as? RoomRolesAndPermissionsScreenRole else { fatalError("Expected a role") }
110-
self?.presentChangeRolesScreen(role: role)
110+
let mode: RoomRole = switch role {
111+
case .administrators:
112+
.administrator
113+
case .moderators:
114+
.moderator
115+
}
116+
self?.presentChangeRolesScreen(mode: mode)
111117
}
112118
stateMachine.addRoutes(event: .finishedChangingRoles, transitions: [.changingRoles => .rolesAndPermissionsScreen])
113119

@@ -150,12 +156,7 @@ class RoomRolesAndPermissionsFlowCoordinator: FlowCoordinatorProtocol {
150156
}
151157
}
152158

153-
private func presentChangeRolesScreen(role: RoomRolesAndPermissionsScreenRole) {
154-
let mode = switch role {
155-
case .administrators: RoomMemberDetails.Role.administrator
156-
case .moderators: RoomMemberDetails.Role.moderator
157-
}
158-
159+
private func presentChangeRolesScreen(mode: RoomRole) {
159160
let parameters = RoomChangeRolesScreenCoordinatorParameters(mode: mode,
160161
roomProxy: roomProxy,
161162
mediaProvider: mediaProvider,

ElementX/Sources/Generated/Strings.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,14 @@ internal enum L10n {
542542
internal static var commonPreparing: String { return L10n.tr("Localizable", "common_preparing") }
543543
/// Privacy policy
544544
internal static var commonPrivacyPolicy: String { return L10n.tr("Localizable", "common_privacy_policy") }
545+
/// Private room
546+
internal static var commonPrivateRoom: String { return L10n.tr("Localizable", "common_private_room") }
547+
/// Private space
548+
internal static var commonPrivateSpace: String { return L10n.tr("Localizable", "common_private_space") }
549+
/// Public room
550+
internal static var commonPublicRoom: String { return L10n.tr("Localizable", "common_public_room") }
551+
/// Public space
552+
internal static var commonPublicSpace: String { return L10n.tr("Localizable", "common_public_space") }
545553
/// Reaction
546554
internal static var commonReaction: String { return L10n.tr("Localizable", "common_reaction") }
547555
/// Reactions
@@ -2150,6 +2158,8 @@ internal enum L10n {
21502158
internal static var screenRoomChangePermissionsRoomTopic: String { return L10n.tr("Localizable", "screen_room_change_permissions_room_topic") }
21512159
/// Send messages
21522160
internal static var screenRoomChangePermissionsSendMessages: String { return L10n.tr("Localizable", "screen_room_change_permissions_send_messages") }
2161+
/// Edit Admins or Owners
2162+
internal static var screenRoomChangeRoleAdministratorsOrOwnersTitle: String { return L10n.tr("Localizable", "screen_room_change_role_administrators_or_owners_title") }
21532163
/// Edit Admins
21542164
internal static var screenRoomChangeRoleAdministratorsTitle: String { return L10n.tr("Localizable", "screen_room_change_role_administrators_title") }
21552165
/// You will not be able to undo this action. You are promoting the user to have the same power level as you.

0 commit comments

Comments
 (0)