Skip to content

Commit

Permalink
[Spaces] M10.7 Explore rooms #4571
Browse files Browse the repository at this point in the history
- Update after review
  • Loading branch information
gileluard committed Sep 1, 2021
1 parent 36bfd3c commit 99caa08
Show file tree
Hide file tree
Showing 28 changed files with 420 additions and 354 deletions.
2 changes: 2 additions & 0 deletions Riot/Categories/MXRoomSummary+Riot.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef NS_ENUM(NSUInteger, RoomEncryptionTrustLevel) {
*/
@interface MXRoomSummary (Riot)

@property(nonatomic, readonly) BOOL isJoined;

/**
Set the room avatar in the dedicated MXKImageView.
The riot style implies to use in order :
Expand Down
5 changes: 5 additions & 0 deletions Riot/Categories/MXRoomSummary+Riot.m
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,9 @@ - (RoomEncryptionTrustLevel)roomEncryptionTrustLevel
return roomEncryptionTrustLevel;
}

- (BOOL)isJoined
{
return self.membership == MXMembershipJoin || self.membershipTransitionState == MXMembershipTransitionStateJoined;
}

@end
20 changes: 10 additions & 10 deletions Riot/Generated/Storyboards.swift
Original file line number Diff line number Diff line change
Expand Up @@ -234,16 +234,6 @@ internal enum StoryboardScene {

internal static let searchableDirectoryViewController = SceneType<Riot.ShowDirectoryViewController>(storyboard: ShowDirectoryViewController.self, identifier: "SearchableDirectoryViewController")
}
internal enum ShowSpaceChildRoomDetailViewController: StoryboardType {
internal static let storyboardName = "ShowSpaceChildRoomDetailViewController"

internal static let initialScene = InitialSceneType<Riot.ShowSpaceChildRoomDetailViewController>(storyboard: ShowSpaceChildRoomDetailViewController.self)
}
internal enum ShowSpaceExploreRoomViewController: StoryboardType {
internal static let storyboardName = "ShowSpaceExploreRoomViewController"

internal static let initialScene = InitialSceneType<Riot.ShowSpaceExploreRoomViewController>(storyboard: ShowSpaceExploreRoomViewController.self)
}
internal enum SideMenuViewController: StoryboardType {
internal static let storyboardName = "SideMenuViewController"

Expand All @@ -254,6 +244,16 @@ internal enum StoryboardScene {

internal static let initialScene = InitialSceneType<Riot.SimpleScreenTemplateViewController>(storyboard: SimpleScreenTemplateViewController.self)
}
internal enum SpaceChildRoomDetailViewController: StoryboardType {
internal static let storyboardName = "SpaceChildRoomDetailViewController"

internal static let initialScene = InitialSceneType<Riot.SpaceChildRoomDetailViewController>(storyboard: SpaceChildRoomDetailViewController.self)
}
internal enum SpaceExploreRoomViewController: StoryboardType {
internal static let storyboardName = "SpaceExploreRoomViewController"

internal static let initialScene = InitialSceneType<Riot.SpaceExploreRoomViewController>(storyboard: SpaceExploreRoomViewController.self)
}
internal enum SpaceFeatureUnaivableViewController: StoryboardType {
internal static let storyboardName = "SpaceFeatureUnaivableViewController"

Expand Down
53 changes: 43 additions & 10 deletions Riot/Modules/SideMenu/SideMenuCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class SideMenuCoordinatorParameters {
}
}

final class SideMenuCoordinator: SideMenuCoordinatorType {
final class SideMenuCoordinator: NSObject, SideMenuCoordinatorType {

// MARK: - Constants

Expand All @@ -61,7 +61,7 @@ final class SideMenuCoordinator: SideMenuCoordinatorType {

let spaceMenuPresenter = SpaceMenuPresenter()

private var exploreRoomCoordimator: ExploreRoomCoordinatorBridgePresenter?
private var exploreRoomCoordinator: ExploreRoomCoordinator?

// MARK: Public

Expand Down Expand Up @@ -205,6 +205,17 @@ final class SideMenuCoordinator: SideMenuCoordinatorType {
self.sideMenuNavigationViewController.present(safariViewController, animated: true, completion: nil)
}

private func showExploreRooms(spaceId: String, session: MXSession) {
let exploreRoomCoordinator = ExploreRoomCoordinator(session: session, spaceId: spaceId)
exploreRoomCoordinator.delegate = self
let presentable = exploreRoomCoordinator.toPresentable()
presentable.presentationController?.delegate = self
self.sideMenuViewController.present(presentable, animated: true, completion: nil)
exploreRoomCoordinator.start()

self.exploreRoomCoordinator = exploreRoomCoordinator
}

private func showInviteFriends(from sourceView: UIView?) {
let myUserId = self.parameters.userSessionsService.mainUserSession?.userId ?? ""

Expand All @@ -220,6 +231,14 @@ final class SideMenuCoordinator: SideMenuCoordinatorType {
self.spaceMenuPresenter.present(forSpaceWithId: spaceId, from: self.sideMenuViewController, sourceView: sourceView, session: session, animated: true)
}

func navigate(to item: SpaceExploreRoomListItemViewData, from sourceView: UIView?) {
if item.childInfo.roomType == .space {
self.exploreRoomCoordinator?.pushSpace(with: item)
} else if item.childInfo.roomType == .room {
self.exploreRoomCoordinator?.presentRoom(with: item, from: sourceView)
}
}

// MARK: UserSessions management

private func registerUserSessionsServiceNotifications() {
Expand Down Expand Up @@ -298,9 +317,7 @@ extension SideMenuCoordinator: SpaceMenuPresenterDelegate {
presenter.dismiss(animated: false) {
switch action {
case .exploreRooms:
self.exploreRoomCoordimator = ExploreRoomCoordinatorBridgePresenter(session: session, spaceId: spaceId)
self.exploreRoomCoordimator?.delegate = self
self.exploreRoomCoordimator?.present(from: self.sideMenuNavigationViewController, animated: true)
self.showExploreRooms(spaceId: spaceId, session: session)
case .exploreMembers:
// TODO present members list
break
Expand All @@ -309,10 +326,26 @@ extension SideMenuCoordinator: SpaceMenuPresenterDelegate {
}
}

// MARK: - ExploreRoomCoordinatorBridgePresenterDelegate
extension SideMenuCoordinator: ExploreRoomCoordinatorBridgePresenterDelegate {
func exploreRoomCoordinatorBridgePresenterDelegateDidComplete(_ coordinatorBridgePresenter: ExploreRoomCoordinatorBridgePresenter) {
self.exploreRoomCoordimator = nil
coordinatorBridgePresenter.dismiss(animated: true, completion: nil)
// MARK: - ExploreRoomCoordinatorDelegate
extension SideMenuCoordinator: ExploreRoomCoordinatorDelegate {
func exploreRoomCoordinatorDidComplete(_ coordinator: ExploreRoomCoordinatorType, withSelectedIem item: SpaceExploreRoomListItemViewData?, from sourceView: UIView?) {
guard let item = item else {
self.exploreRoomCoordinator?.toPresentable().dismiss(animated: true) {
self.exploreRoomCoordinator = nil
}
return
}
self.navigate(to: item, from: sourceView)
}
}

// MARK: - UIAdaptivePresentationControllerDelegate
extension SideMenuCoordinator: UIAdaptivePresentationControllerDelegate {

func exploreRoomCoordinatorDidComplete(_ presentationController: UIPresentationController) {
self.exploreRoomCoordinator?.toPresentable().dismiss(animated: true) {
self.exploreRoomCoordinator = nil
}
}

}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
// File created from ScreenTemplate
// $ createScreen.sh Spaces/SpaceRoomList/ExploreRoom ShowSpaceExploreRoom
/*
Copyright 2021 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation
import UIKit

final class SpaceExploreRoomCoordinator: SpaceExploreRoomCoordinatorType {

// MARK: - Properties

// MARK: Private

private var spaceExploreRoomViewModel: SpaceExploreRoomViewModelType
private let spaceExploreRoomViewController: SpaceExploreRoomViewController

// MARK: Public

// Must be used only internally
var childCoordinators: [Coordinator] = []

weak var delegate: SpaceExploreRoomCoordinatorDelegate?

// MARK: - Setup

init(parameters: SpaceExploreRoomCoordinatorParameters) {
let spaceExploreRoomViewModel = SpaceExploreRoomViewModel(parameters: parameters)
let spaceExploreRoomViewController = SpaceExploreRoomViewController.instantiate(with: spaceExploreRoomViewModel)
self.spaceExploreRoomViewModel = spaceExploreRoomViewModel
self.spaceExploreRoomViewController = spaceExploreRoomViewController
}

// MARK: - Public methods

func start() {
self.spaceExploreRoomViewModel.coordinatorDelegate = self
}

func toPresentable() -> UIViewController {
return self.spaceExploreRoomViewController
}
}

// MARK: - SpaceExploreRoomViewModelCoordinatorDelegate
extension SpaceExploreRoomCoordinator: SpaceExploreRoomViewModelCoordinatorDelegate {
func spaceExploreRoomViewModel(_ viewModel: SpaceExploreRoomViewModelType, didSelect item: SpaceExploreRoomListItemViewData, from sourceView: UIView?) {
self.delegate?.spaceExploreRoomCoordinator(self, didSelect: item, from: sourceView)
}

func spaceExploreRoomViewModelDidCancel(_ viewModel: SpaceExploreRoomViewModelType) {
self.delegate?.spaceExploreRoomCoordinatorDidCancel(self)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
//
// Copyright 2021 New Vector Ltd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

import Foundation

struct SpaceExploreRoomCoordinatorParameters {
let session: MXSession
let spaceId: String
let spaceName: String?
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// File created from ScreenTemplate
// $ createScreen.sh Spaces/SpaceRoomList/ExploreRoom ShowSpaceExploreRoom
/*
Copyright 2021 New Vector Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

import Foundation

protocol SpaceExploreRoomCoordinatorDelegate: AnyObject {
func spaceExploreRoomCoordinator(_ coordinator: SpaceExploreRoomCoordinatorType, didSelect item: SpaceExploreRoomListItemViewData, from sourceView: UIView?)
func spaceExploreRoomCoordinatorDidCancel(_ coordinator: SpaceExploreRoomCoordinatorType)
}

/// `SpaceExploreRoomCoordinatorType` is a protocol describing a Coordinator that handle key backup setup passphrase navigation flow.
protocol SpaceExploreRoomCoordinatorType: Coordinator, Presentable {
var delegate: SpaceExploreRoomCoordinatorDelegate? { get }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@

import Foundation

/// ShowSpaceExploreRoomViewController view actions exposed to view model
enum ShowSpaceExploreRoomViewAction {
/// SpaceExploreRoomViewController view actions exposed to view model
enum SpaceExploreRoomViewAction {
case loadData
case complete(_ selectedItem: SpaceExploreRoomListItemViewData, _ sourceView: UIView?)
case searchChanged(_ text: String?)
Expand Down
Loading

0 comments on commit 99caa08

Please sign in to comment.