diff --git a/Riot/Modules/SideMenu/SideMenuCoordinator.swift b/Riot/Modules/SideMenu/SideMenuCoordinator.swift index 7e3857d5f6..174f3d0ff8 100644 --- a/Riot/Modules/SideMenu/SideMenuCoordinator.swift +++ b/Riot/Modules/SideMenu/SideMenuCoordinator.swift @@ -320,6 +320,36 @@ final class SideMenuCoordinator: NSObject, SideMenuCoordinatorType { self.spaceSettingsCoordinator = coordinator } + func showSpaceInvite(spaceId: String, session: MXSession) { + guard let space = session.spaceService.getSpace(withId: spaceId), let spaceRoom = space.room else { + MXLog.error("[SideMenuCoordinator] showSpaceInvite: failed to find space with id \(spaceId)") + return + } + + spaceRoom.state { [weak self] roomState in + guard let self = self else { return } + + guard let powerLevels = roomState?.powerLevels, let userId = session.myUserId else { + MXLog.error("[SpaceMembersCoordinator] spaceMemberListCoordinatorShowInvite: failed to find powerLevels for room") + return + } + let userPowerLevel = powerLevels.powerLevelOfUser(withUserID: userId) + + guard userPowerLevel >= powerLevels.invite else { + let alert = UIAlertController(title: VectorL10n.spacesInvitePeople, message: VectorL10n.spaceInviteNotEnoughPermission, preferredStyle: .alert) + alert.addAction(UIAlertAction(title: VectorL10n.ok, style: .default, handler: nil)) + self.sideMenuViewController.present(alert, animated: true) + return + } + + let coordinator = ContactsPickerCoordinator(session: session, room: spaceRoom, initialSearchText: nil, actualParticipants: nil, invitedParticipants: nil, userParticipant: nil) + coordinator.delegate = self + coordinator.start() + self.add(childCoordinator: coordinator) + self.sideMenuViewController.present(coordinator.toPresentable(), animated: true) + } + } + private func resetExploringSpaceIfNeeded() { if sideMenuNavigationViewController.presentedViewController == nil { Analytics.shared.exploringSpace = nil @@ -437,6 +467,8 @@ extension SideMenuCoordinator: SpaceMenuPresenterDelegate { } else { AppDelegate.theDelegate().showAlert(withTitle: VectorL10n.settingsTitle, message: VectorL10n.spacesComingSoonDetail(AppInfo.current.displayName)) } + case .invite: + self.showSpaceInvite(spaceId: spaceId, session: session) } } } @@ -511,6 +543,19 @@ extension SideMenuCoordinator: CreateRoomCoordinatorDelegate { } } +// MARK: - ContactsPickerCoordinatorDelegate +extension SideMenuCoordinator: ContactsPickerCoordinatorDelegate { + func contactsPickerCoordinatorDidStartLoading(_ coordinator: ContactsPickerCoordinatorProtocol) { + } + + func contactsPickerCoordinatorDidEndLoading(_ coordinator: ContactsPickerCoordinatorProtocol) { + } + + func contactsPickerCoordinatorDidClose(_ coordinator: ContactsPickerCoordinatorProtocol) { + remove(childCoordinator: coordinator) + } +} + // MARK: - UIAdaptivePresentationControllerDelegate extension SideMenuCoordinator: UIAdaptivePresentationControllerDelegate { diff --git a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift index f9964201d7..8954f504dc 100644 --- a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift +++ b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuListItemViewData.swift @@ -25,6 +25,7 @@ enum SpaceMenuListItemAction { case addSpace case settings case leaveSpace + case invite } /// Style of the `SpaceMenuListViewCell` diff --git a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift index b900dda798..2cc8d9dbdb 100644 --- a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift +++ b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift @@ -27,6 +27,7 @@ class SpaceMenuPresenter: NSObject { case addRoom case addSpace case settings + case invite } // MARK: - Properties @@ -117,6 +118,8 @@ extension SpaceMenuPresenter: SpaceMenuModelViewModelCoordinatorDelegate { self.delegate?.spaceMenuPresenter(self, didCompleteWith: .addSpace, forSpaceWithId: self.spaceId, with: self.session) case .settings: self.delegate?.spaceMenuPresenter(self, didCompleteWith: .settings, forSpaceWithId: self.spaceId, with: self.session) + case .invite: + self.delegate?.spaceMenuPresenter(self, didCompleteWith: .invite, forSpaceWithId: self.spaceId, with: self.session) default: MXLog.error("[SpaceMenuPresenter] spaceListViewModel didSelectItem: invalid action \(action)") } diff --git a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift index 71c0f91340..642f0e33ac 100644 --- a/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift +++ b/Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift @@ -25,11 +25,12 @@ class SpaceMenuViewModel: SpaceMenuViewModelType { weak var viewDelegate: SpaceMenuViewModelViewDelegate? private let spaceMenuItems: [SpaceMenuListItemViewData] = [ + SpaceMenuListItemViewData(action: .invite, style: .normal, title: VectorL10n.spacesInvitePeople, icon: Asset.Images.spaceInviteUser.image, value: nil), SpaceMenuListItemViewData(action: .exploreSpaceMembers, style: .normal, title: VectorL10n.roomDetailsPeople, icon: Asset.Images.spaceMenuMembers.image, value: nil), + SpaceMenuListItemViewData(action: .settings, style: .normal, title: VectorL10n.sideMenuActionSettings, icon: Asset.Images.sideMenuActionIconSettings.image, value: nil), SpaceMenuListItemViewData(action: .exploreSpaceRooms, style: .normal, title: VectorL10n.spacesExploreRooms, icon: Asset.Images.spaceMenuRooms.image, value: nil), SpaceMenuListItemViewData(action: .addRoom, style: .normal, title: VectorL10n.spacesAddRoom, icon: Asset.Images.spaceMenuPlusIcon.image, value: nil), SpaceMenuListItemViewData(action: .addSpace, style: .normal, title: VectorL10n.spacesAddSpace, icon: Asset.Images.spaceMenuPlusIcon.image, value: nil, isBeta: true), - SpaceMenuListItemViewData(action: .settings, style: .normal, title: VectorL10n.sideMenuActionSettings, icon: Asset.Images.sideMenuActionIconSettings.image, value: nil), SpaceMenuListItemViewData(action: .leaveSpace, style: .destructive, title: VectorL10n.leave, icon: Asset.Images.spaceMenuLeave.image, value: nil) ] diff --git a/changelog.d/5810.change b/changelog.d/5810.change new file mode 100644 index 0000000000..63585a270e --- /dev/null +++ b/changelog.d/5810.change @@ -0,0 +1 @@ +Add "Invite people" to the space menu in the left panel and update menu order \ No newline at end of file