Skip to content

Commit

Permalink
Add "Invite people" to the space menu in the left panel and update me…
Browse files Browse the repository at this point in the history
…nu order #5810

- done
  • Loading branch information
gileluard authored and stefanceriu committed Mar 28, 2022
1 parent dc99e33 commit 767eec4
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 1 deletion.
45 changes: 45 additions & 0 deletions Riot/Modules/SideMenu/SideMenuCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
}
Expand Down Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum SpaceMenuListItemAction {
case addSpace
case settings
case leaveSpace
case invite
}

/// Style of the `SpaceMenuListViewCell`
Expand Down
3 changes: 3 additions & 0 deletions Riot/Modules/Spaces/SpaceMenu/SpaceMenuPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class SpaceMenuPresenter: NSObject {
case addRoom
case addSpace
case settings
case invite
}

// MARK: - Properties
Expand Down Expand Up @@ -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)")
}
Expand Down
3 changes: 2 additions & 1 deletion Riot/Modules/Spaces/SpaceMenu/SpaceMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]

Expand Down
1 change: 1 addition & 0 deletions changelog.d/5810.change
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add "Invite people" to the space menu in the left panel and update menu order

0 comments on commit 767eec4

Please sign in to comment.