2022-09-27 07:17:22 +00:00
|
|
|
//
|
2022-09-05 08:41:35 +00:00
|
|
|
// 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
|
|
|
|
|
|
|
|
/// Represents a user session information
|
|
|
|
struct UserSessionInfo: Identifiable {
|
|
|
|
/// The session identifier
|
2022-09-27 13:51:13 +00:00
|
|
|
let id: String
|
2022-09-05 08:41:35 +00:00
|
|
|
|
|
|
|
/// The session display name
|
2022-09-27 13:51:13 +00:00
|
|
|
let name: String?
|
2022-09-05 08:41:35 +00:00
|
|
|
|
|
|
|
/// The device type used by the session
|
|
|
|
let deviceType: DeviceType
|
|
|
|
|
2022-10-11 15:11:52 +00:00
|
|
|
/// The current state of verification for the session.
|
|
|
|
let verificationState: VerificationState
|
2022-09-05 08:41:35 +00:00
|
|
|
|
|
|
|
/// The IP address where this device was last seen.
|
|
|
|
let lastSeenIP: String?
|
|
|
|
|
|
|
|
/// Last time the session was active
|
|
|
|
let lastSeenTimestamp: TimeInterval?
|
2022-09-29 12:07:10 +00:00
|
|
|
|
|
|
|
// MARK: - Application Properties
|
|
|
|
|
|
|
|
/// Application name used by the session
|
|
|
|
let applicationName: String?
|
|
|
|
|
|
|
|
/// Application version used by the session
|
|
|
|
let applicationVersion: String?
|
|
|
|
|
|
|
|
/// Application URL used by the session. Only applicable for web sessions.
|
|
|
|
let applicationURL: String?
|
|
|
|
|
|
|
|
// MARK: - Device Properties
|
|
|
|
|
|
|
|
/// Device model
|
|
|
|
let deviceModel: String?
|
|
|
|
|
|
|
|
/// Device OS
|
|
|
|
let deviceOS: String?
|
|
|
|
|
|
|
|
/// Last seen IP location
|
|
|
|
let lastSeenIPLocation: String?
|
|
|
|
|
2022-10-04 07:49:26 +00:00
|
|
|
/// Client name
|
|
|
|
let clientName: String?
|
|
|
|
|
|
|
|
/// Client version
|
|
|
|
let clientVersion: String?
|
2022-09-29 12:07:10 +00:00
|
|
|
|
2022-09-05 08:41:35 +00:00
|
|
|
/// True to indicate that session has been used under `inactiveSessionDurationTreshold` value
|
2022-09-27 13:51:13 +00:00
|
|
|
let isActive: Bool
|
2022-09-29 12:07:10 +00:00
|
|
|
|
2022-09-27 12:36:44 +00:00
|
|
|
/// True to indicate that this is current user session
|
2022-09-27 13:51:13 +00:00
|
|
|
let isCurrent: Bool
|
2022-10-11 15:11:52 +00:00
|
|
|
|
|
|
|
/// Represents a verification state.
|
|
|
|
enum VerificationState {
|
|
|
|
/// The state is unknown (likely because the current session
|
|
|
|
/// hasn't been set up for cross-signing yet).
|
|
|
|
case unknown
|
|
|
|
/// The session has not yet been verified.
|
|
|
|
case unverified
|
|
|
|
/// The session has been verified.
|
|
|
|
case verified
|
|
|
|
}
|
2022-09-05 08:41:35 +00:00
|
|
|
}
|
2022-09-27 11:51:15 +00:00
|
|
|
|
2022-10-11 12:11:15 +00:00
|
|
|
// MARK: - Equatable
|
|
|
|
|
2022-09-27 11:51:15 +00:00
|
|
|
extension UserSessionInfo: Equatable {
|
|
|
|
static func == (lhs: UserSessionInfo, rhs: UserSessionInfo) -> Bool {
|
2022-09-29 12:07:10 +00:00
|
|
|
lhs.id == rhs.id
|
2022-09-27 11:51:15 +00:00
|
|
|
}
|
|
|
|
}
|
2022-10-11 12:11:15 +00:00
|
|
|
|
|
|
|
// MARK: - Mocks
|
|
|
|
|
|
|
|
extension UserSessionInfo {
|
2022-10-12 11:08:08 +00:00
|
|
|
static func mockPhone(verificationState: VerificationState = .verified,
|
|
|
|
hasTimestamp: Bool = true,
|
|
|
|
isCurrent: Bool = false) -> UserSessionInfo {
|
2022-10-11 12:11:15 +00:00
|
|
|
UserSessionInfo(id: "1",
|
|
|
|
name: "Element Mobile: iOS",
|
|
|
|
deviceType: .mobile,
|
2022-10-12 11:08:08 +00:00
|
|
|
verificationState: verificationState,
|
2022-10-11 15:11:52 +00:00
|
|
|
lastSeenIP: "1.0.0.1",
|
2022-10-12 11:08:08 +00:00
|
|
|
lastSeenTimestamp: hasTimestamp ? Date().timeIntervalSince1970 : nil,
|
2022-10-11 15:11:52 +00:00
|
|
|
applicationName: "Element iOS",
|
|
|
|
applicationVersion: "1.9.8",
|
|
|
|
applicationURL: nil,
|
|
|
|
deviceModel: nil,
|
|
|
|
deviceOS: "iOS 16.0.2",
|
|
|
|
lastSeenIPLocation: nil,
|
|
|
|
clientName: nil,
|
|
|
|
clientVersion: nil,
|
2022-10-12 11:08:08 +00:00
|
|
|
isActive: true,
|
|
|
|
isCurrent: isCurrent)
|
2022-10-11 12:11:15 +00:00
|
|
|
}
|
|
|
|
}
|