mirror of
https://github.com/vector-im/element-ios.git
synced 2024-09-28 23:32:41 +00:00
Create OnBoardingManager
in order to manage onboarding steps, like create DM room with riot bot.
This commit is contained in:
parent
1b0c481d59
commit
075f9a5468
3 changed files with 95 additions and 0 deletions
|
@ -61,6 +61,7 @@
|
|||
B169331620F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */; };
|
||||
B169331720F3CBE000746532 /* RecentCellData.m in Sources */ = {isa = PBXBuildFile; fileRef = B16932F920F3C51900746532 /* RecentCellData.m */; };
|
||||
B17982FF2119FED2001FD722 /* GDPRConsentViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */; };
|
||||
B1798302211B13B3001FD722 /* OnBoardingManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = B1798301211B13B3001FD722 /* OnBoardingManager.swift */; };
|
||||
B1B5571820EE6C4D00210D55 /* CountryPickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */; };
|
||||
B1B5571920EE6C4D00210D55 /* LanguagePickerViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */; };
|
||||
B1B5571A20EE6C4D00210D55 /* SettingsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B1B5567E20EE6C4C00210D55 /* SettingsViewController.m */; };
|
||||
|
@ -494,6 +495,7 @@
|
|||
B169331220F3CAFC00746532 /* PublicRoomsDirectoryDataSource.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PublicRoomsDirectoryDataSource.m; sourceTree = "<group>"; };
|
||||
B169331320F3CAFC00746532 /* PublicRoomsDirectoryDataSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PublicRoomsDirectoryDataSource.h; sourceTree = "<group>"; };
|
||||
B17982FE2119FED2001FD722 /* GDPRConsentViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GDPRConsentViewController.swift; sourceTree = "<group>"; };
|
||||
B1798301211B13B3001FD722 /* OnBoardingManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnBoardingManager.swift; sourceTree = "<group>"; };
|
||||
B1B5567920EE6C4C00210D55 /* CountryPickerViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CountryPickerViewController.h; sourceTree = "<group>"; };
|
||||
B1B5567A20EE6C4C00210D55 /* CountryPickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CountryPickerViewController.m; sourceTree = "<group>"; };
|
||||
B1B5567C20EE6C4C00210D55 /* LanguagePickerViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LanguagePickerViewController.m; sourceTree = "<group>"; };
|
||||
|
@ -1284,6 +1286,14 @@
|
|||
path = GDPR;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B1798300211B137B001FD722 /* OnBoarding */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B1798301211B13B3001FD722 /* OnBoardingManager.swift */,
|
||||
);
|
||||
path = OnBoarding;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
B1B5567620EE6C4C00210D55 /* Modules */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -2316,6 +2326,7 @@
|
|||
B1B5597C20EFC3DF00210D55 /* Managers */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
B1798300211B137B001FD722 /* OnBoarding */,
|
||||
B1B5598B20EFC5E400210D55 /* Analytics */,
|
||||
B1B5598920EFC41100210D55 /* BugReport */,
|
||||
B1B5598A20EFC42100210D55 /* Settings */,
|
||||
|
@ -3081,6 +3092,7 @@
|
|||
B1B5579920EF575B00210D55 /* AuthInputsView.m in Sources */,
|
||||
B1B5597520EFB02A00210D55 /* InviteRecentTableViewCell.m in Sources */,
|
||||
B1B5571E20EE6C4D00210D55 /* ContactDetailsViewController.m in Sources */,
|
||||
B1798302211B13B3001FD722 /* OnBoardingManager.swift in Sources */,
|
||||
B1B5573520EE6C4D00210D55 /* GroupDetailsViewController.m in Sources */,
|
||||
B1B5575220EE6C4D00210D55 /* RoomKeyRequestViewController.m in Sources */,
|
||||
F083BD1E1E7009ED00A9B29C /* AppDelegate.m in Sources */,
|
||||
|
|
82
Riot/Managers/OnBoarding/OnBoardingManager.swift
Normal file
82
Riot/Managers/OnBoarding/OnBoardingManager.swift
Normal file
|
@ -0,0 +1,82 @@
|
|||
/*
|
||||
Copyright 2018 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
|
||||
|
||||
/// `OnBoardingManager` is used to manage onboarding steps, like create DM room with riot bot.
|
||||
final public class OnBoardingManager: NSObject {
|
||||
|
||||
// MARK: - Constants
|
||||
|
||||
private enum Constants {
|
||||
static let riotBotMatrixId = "@riot-bot:matrix.org"
|
||||
static let createRiotBotDMRequestMaxNumberOfTries: UInt = UInt.max
|
||||
}
|
||||
|
||||
// MARK: - Properties
|
||||
|
||||
private var session: MXSession
|
||||
|
||||
// MARK: - Setup & Teardown
|
||||
|
||||
@objc init(session: MXSession) {
|
||||
self.session = session
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Public
|
||||
|
||||
@objc func createRiotBotDirectMessageIfNeeded(sucess: (() -> Void)?, failure: ((Error) -> Void)?) {
|
||||
|
||||
// Check user has join no rooms so is a new comer
|
||||
guard self.isUSerJoinedARoom() == false else {
|
||||
return
|
||||
}
|
||||
|
||||
// Create DM room with Riot-bot
|
||||
|
||||
let httpOperation = self.session.createRoom(name: nil, visibility: .private, alias: nil, topic: nil, invite: [Constants.riotBotMatrixId], invite3PID: nil, isDirect: true, preset: .trustedPrivateChat) { (response) in
|
||||
|
||||
switch response {
|
||||
case .success(_):
|
||||
sucess?()
|
||||
case .failure(let error):
|
||||
NSLog("[OnBoardingManager] Create chat with riot-bot failed with error \(error)");
|
||||
failure?(error)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Make multipe tries, until we get a response
|
||||
httpOperation.maxNumberOfTries = Constants.createRiotBotDMRequestMaxNumberOfTries
|
||||
}
|
||||
|
||||
// MARK: - Private
|
||||
|
||||
private func isUSerJoinedARoom() -> Bool {
|
||||
var isUSerJoinedARoom = false
|
||||
|
||||
for roomSummary in self.session.roomsSummaries() {
|
||||
if case .join = roomSummary.membership {
|
||||
isUSerJoinedARoom = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return isUSerJoinedARoom
|
||||
}
|
||||
}
|
|
@ -2,4 +2,5 @@
|
|||
// Use this file to import your target's public headers that you would like to expose to Swift.
|
||||
//
|
||||
|
||||
@import MatrixSDK;
|
||||
#import "WebViewViewController.h"
|
||||
|
|
Loading…
Reference in a new issue