-
Notifications
You must be signed in to change notification settings - Fork 489
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6791 from vector-im/aleksandrs/6786_inactive_sess…
…ions_screen Device manager: Inactive sessions screen
- Loading branch information
Showing
34 changed files
with
875 additions
and
130 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
.../Assets/Images.xcassets/DeviceManager/user_other_sessions_inactive.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "user_other_sessions_inactive.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...eManager/user_other_sessions_inactive.imageset/user_other_sessions_inactive.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions
12
...ges.xcassets/DeviceManager/user_session_list_item_inactive_session.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "user_session_list_item_inactive_session.svg", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...list_item_inactive_session.imageset/user_session_list_item_inactive_session.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
RiotSwiftUI/Modules/UserSessions/Common/InactiveUserSessionLastActivityFormatter.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// Copyright 2022 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 | ||
|
||
class InactiveUserSessionLastActivityFormatter { | ||
private static var dateFormatter: DateFormatter = { | ||
let dateFormatter = DateFormatter() | ||
dateFormatter.locale = Locale.current | ||
dateFormatter.dateStyle = .medium | ||
dateFormatter.doesRelativeDateFormatting = true | ||
return dateFormatter | ||
}() | ||
|
||
static func lastActivityDateString(from lastActivityTimestamp: TimeInterval) -> String { | ||
let date = Date(timeIntervalSince1970: lastActivityTimestamp) | ||
return InactiveUserSessionLastActivityFormatter.dateFormatter.string(from: date) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
...tUI/Modules/UserSessions/UserOtherSessions/Coordinator/UserOtherSessionsCoordinator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// | ||
// 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 CommonKit | ||
import SwiftUI | ||
|
||
struct UserOtherSessionsCoordinatorParameters { | ||
let sessionsInfo: [UserSessionInfo] | ||
let filter: OtherUserSessionsFilter | ||
let title: String | ||
} | ||
|
||
final class UserOtherSessionsCoordinator: Coordinator, Presentable { | ||
|
||
private let parameters: UserOtherSessionsCoordinatorParameters | ||
private let userOtherSessionsHostingController: UIViewController | ||
private var userOtherSessionsViewModel: UserOtherSessionsViewModelProtocol | ||
private var indicatorPresenter: UserIndicatorTypePresenterProtocol | ||
private var loadingIndicator: UserIndicator? | ||
|
||
// Must be used only internally | ||
var childCoordinators: [Coordinator] = [] | ||
var completion: ((UserOtherSessionsCoordinatorResult) -> Void)? | ||
|
||
init(parameters: UserOtherSessionsCoordinatorParameters) { | ||
self.parameters = parameters | ||
|
||
let viewModel = UserOtherSessionsViewModel(sessionsInfo: parameters.sessionsInfo, | ||
filter: parameters.filter, | ||
title: parameters.title) | ||
let view = UserOtherSessions(viewModel: viewModel.context) | ||
userOtherSessionsViewModel = viewModel | ||
userOtherSessionsHostingController = VectorHostingController(rootView: view) | ||
|
||
indicatorPresenter = UserIndicatorTypePresenter(presentingViewController: userOtherSessionsHostingController) | ||
} | ||
|
||
// MARK: - Public | ||
|
||
func start() { | ||
MXLog.debug("[UserOtherSessionsCoordinator] did start.") | ||
userOtherSessionsViewModel.completion = { [weak self] result in | ||
guard let self = self else { return } | ||
switch result { | ||
case let .showUserSessionOverview(sessionInfo: session): | ||
self.completion?(.openSessionDetails(sessionInfo: session)) | ||
} | ||
MXLog.debug("[UserOtherSessionsCoordinator] UserOtherSessionsViewModel did complete with result: \(result).") | ||
} | ||
} | ||
|
||
func toPresentable() -> UIViewController { | ||
userOtherSessionsHostingController | ||
} | ||
|
||
// MARK: - Private | ||
} |
121 changes: 121 additions & 0 deletions
121
RiotSwiftUI/Modules/UserSessions/UserOtherSessions/MockUserOtherSessionsScreenState.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
// | ||
// 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 SwiftUI | ||
|
||
/// Using an enum for the screen allows you define the different state cases with | ||
/// the relevant associated data for each case. | ||
enum MockUserOtherSessionsScreenState: MockScreenState, CaseIterable { | ||
// A case for each state you want to represent | ||
// with specific, minimal associated data that will allow you | ||
// mock that screen. | ||
|
||
case inactiveSessions | ||
|
||
/// The associated screen | ||
var screenType: Any.Type { | ||
UserOtherSessions.self | ||
} | ||
|
||
/// A list of screen state definitions | ||
static var allCases: [MockUserOtherSessionsScreenState] { | ||
// Each of the presence statuses | ||
[.inactiveSessions] | ||
} | ||
|
||
/// Generate the view struct for the screen state. | ||
var screenView: ([Any], AnyView) { | ||
|
||
let viewModel = UserOtherSessionsViewModel(sessionsInfo: inactiveSessions(), | ||
filter: .inactive, | ||
title: VectorL10n.userOtherSessionSecurityRecommendationTitle) | ||
|
||
// can simulate service and viewModel actions here if needs be. | ||
|
||
return ( | ||
[viewModel], | ||
AnyView(UserOtherSessions(viewModel: viewModel.context)) | ||
) | ||
} | ||
|
||
private func inactiveSessions() -> [UserSessionInfo] { | ||
[UserSessionInfo(id: "0", | ||
name: "iOS", | ||
deviceType: .mobile, | ||
isVerified: false, | ||
lastSeenIP: "10.0.0.10", | ||
lastSeenTimestamp: nil, | ||
applicationName: nil, | ||
applicationVersion: nil, | ||
applicationURL: nil, | ||
deviceModel: nil, | ||
deviceOS: nil, | ||
lastSeenIPLocation: nil, | ||
clientName: nil, | ||
clientVersion: nil, | ||
isActive: false, | ||
isCurrent: true), | ||
UserSessionInfo(id: "1", | ||
name: "macOS", | ||
deviceType: .desktop, | ||
isVerified: true, | ||
lastSeenIP: "1.0.0.1", | ||
lastSeenTimestamp: Date().timeIntervalSince1970 - 8000000, | ||
applicationName: nil, | ||
applicationVersion: nil, | ||
applicationURL: nil, | ||
deviceModel: nil, | ||
deviceOS: nil, | ||
lastSeenIPLocation: nil, | ||
clientName: nil, | ||
clientVersion: nil, | ||
isActive: false, | ||
isCurrent: false), | ||
UserSessionInfo(id: "2", | ||
name: "Firefox on Windows", | ||
deviceType: .web, | ||
isVerified: true, | ||
lastSeenIP: "2.0.0.2", | ||
lastSeenTimestamp: Date().timeIntervalSince1970 - 9000000, | ||
applicationName: nil, | ||
applicationVersion: nil, | ||
applicationURL: nil, | ||
deviceModel: nil, | ||
deviceOS: nil, | ||
lastSeenIPLocation: nil, | ||
clientName: nil, | ||
clientVersion: nil, | ||
isActive: false, | ||
isCurrent: false), | ||
UserSessionInfo(id: "3", | ||
name: "Android", | ||
deviceType: .mobile, | ||
isVerified: false, | ||
lastSeenIP: "3.0.0.3", | ||
lastSeenTimestamp: Date().timeIntervalSince1970 - 10000000, | ||
applicationName: nil, | ||
applicationVersion: nil, | ||
applicationURL: nil, | ||
deviceModel: nil, | ||
deviceOS: nil, | ||
lastSeenIPLocation: nil, | ||
clientName: nil, | ||
clientVersion: nil, | ||
isActive: false, | ||
isCurrent: false)] | ||
} | ||
} |
Oops, something went wrong.