Skip to content

Commit

Permalink
Merge pull request #6791 from vector-im/aleksandrs/6786_inactive_sess…
Browse files Browse the repository at this point in the history
…ions_screen

Device manager: Inactive sessions screen
  • Loading branch information
Aleksandrs Proskurins committed Oct 5, 2022
2 parents bf9bb82 + 87cc0dd commit 6eef04a
Show file tree
Hide file tree
Showing 34 changed files with 875 additions and 130 deletions.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -2388,10 +2388,14 @@ To enable access, tap Settings> Location and select Always";
"user_session_push_notifications" = "Push notifications";
"user_session_push_notifications_message" = "When turned on, this session will receive push notifications.";

"user_other_session_security_recommendation_title" = "Security recommendation";

// First item is client name and second item is session display name
"user_session_name" = "%@: %@";

"user_session_item_details" = "%@ · Last activity %@";
"user_inactive_session_item" = "Inactive for 90+ days";
"user_inactive_session_item_with_date" = "Inactive for 90+ days (%@)";

"device_name_desktop" = "%@ Desktop";
"device_name_web" = "%@ Web";
Expand Down
2 changes: 2 additions & 0 deletions Riot/Generated/Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ internal class Asset: NSObject {
internal static let deviceTypeMobile = ImageAsset(name: "device_type_mobile")
internal static let deviceTypeUnknown = ImageAsset(name: "device_type_unknown")
internal static let deviceTypeWeb = ImageAsset(name: "device_type_web")
internal static let userOtherSessionsInactive = ImageAsset(name: "user_other_sessions_inactive")
internal static let userSessionListItemInactiveSession = ImageAsset(name: "user_session_list_item_inactive_session")
internal static let userSessionUnverified = ImageAsset(name: "user_session_unverified")
internal static let userSessionVerified = ImageAsset(name: "user_session_verified")
internal static let userSessionsInactive = ImageAsset(name: "user_sessions_inactive")
Expand Down
12 changes: 12 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8483,6 +8483,18 @@ public class VectorL10n: NSObject {
public static var userIdTitle: String {
return VectorL10n.tr("Vector", "user_id_title")
}
/// Inactive for 90+ days
public static var userInactiveSessionItem: String {
return VectorL10n.tr("Vector", "user_inactive_session_item")
}
/// Inactive for 90+ days (%@)
public static func userInactiveSessionItemWithDate(_ p1: String) -> String {
return VectorL10n.tr("Vector", "user_inactive_session_item_with_date", p1)
}
/// Security recommendation
public static var userOtherSessionSecurityRecommendationTitle: String {
return VectorL10n.tr("Vector", "user_other_session_security_recommendation_title")
}
/// Name
public static var userSessionDetailsApplicationName: String {
return VectorL10n.tr("Vector", "user_session_details_application_name")
Expand Down
1 change: 1 addition & 0 deletions RiotSwiftUI/Modules/Common/Mock/MockAppScreens.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Foundation
/// The static list of mocked screens in RiotSwiftUI
enum MockAppScreens {
static let appScreens: [MockScreenState.Type] = [
MockUserOtherSessionsScreenState.self,
MockUserSessionsOverviewScreenState.self,
MockUserSessionDetailsScreenState.self,
MockUserSessionOverviewScreenState.self,
Expand Down
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import Foundation
import SwiftUI

/// View data for DeviceAvatarView
struct DeviceAvatarViewData {
struct DeviceAvatarViewData: Hashable {
let deviceType: DeviceType
let isVerified: Bool?
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
switch result {
case let .openSessionOverview(sessionInfo: sessionInfo):
self.openSessionOverview(sessionInfo: sessionInfo)
case let .openOtherSessions(sessionsInfo: sessionsInfo, filter: filter):
self.openOtherSessions(sessionsInfo: sessionsInfo,
filterBy: filter,
title: VectorL10n.userOtherSessionSecurityRecommendationTitle)
}
}
return coordinator
Expand All @@ -66,7 +70,7 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
}

private func createUserSessionDetailsCoordinator(sessionInfo: UserSessionInfo) -> UserSessionDetailsCoordinator {
let parameters = UserSessionDetailsCoordinatorParameters(session: sessionInfo)
let parameters = UserSessionDetailsCoordinatorParameters(sessionInfo: sessionInfo)
return UserSessionDetailsCoordinator(parameters: parameters)
}

Expand All @@ -83,10 +87,34 @@ final class UserSessionsFlowCoordinator: Coordinator, Presentable {
}

private func createUserSessionOverviewCoordinator(sessionInfo: UserSessionInfo) -> UserSessionOverviewCoordinator {
let parameters = UserSessionOverviewCoordinatorParameters(session: self.parameters.session, sessionInfo: sessionInfo)
let parameters = UserSessionOverviewCoordinatorParameters(session: parameters.session,
sessionInfo: sessionInfo)
return UserSessionOverviewCoordinator(parameters: parameters)
}

private func openOtherSessions(sessionsInfo: [UserSessionInfo], filterBy filter: OtherUserSessionsFilter, title: String) {
let coordinator = createOtherSessionsCoordinator(sessionsInfo: sessionsInfo,
filterBy: filter,
title: title)
coordinator.completion = { [weak self] result in
guard let self = self else { return }
switch result {
case let .openSessionDetails(sessionInfo: session):
self.openSessionDetails(sessionInfo: session)
}
}
pushScreen(with: coordinator)
}

private func createOtherSessionsCoordinator(sessionsInfo: [UserSessionInfo],
filterBy filter: OtherUserSessionsFilter,
title: String) -> UserOtherSessionsCoordinator {
let parameters = UserOtherSessionsCoordinatorParameters(sessionsInfo: sessionsInfo,
filter: filter,
title: title)
return UserOtherSessionsCoordinator(parameters: parameters)
}

// MARK: - Public

func start() {
Expand Down
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
}
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)]
}
}
Loading

0 comments on commit 6eef04a

Please sign in to comment.