mirror of
https://github.com/Novaloop-AG/element-x-ios.git
synced 2026-11-07 04:48:34 +00:00
Add a view to show the user's account from Element Classic. (#5361)
No presentation logic yet.
This commit is contained in:
@@ -7,13 +7,23 @@
|
||||
|
||||
import Foundation
|
||||
|
||||
struct ClassicAppAccount: Equatable {
|
||||
struct ClassicAppAccount: Equatable, CustomStringConvertible {
|
||||
let userID: String
|
||||
let displayName: String?
|
||||
let avatarURL: URL?
|
||||
|
||||
let serverName: String
|
||||
let homeserverURL: URL
|
||||
|
||||
let cryptoStoreURL: URL
|
||||
let cryptoStorePassphrase: Data
|
||||
let cryptoStorePassphrase: String
|
||||
|
||||
let accessToken: String // For avatar loading and key backup detection.
|
||||
|
||||
/// Custom `CustomStringConvertible` without the access token.
|
||||
var description: String {
|
||||
"ClassicAppAccount(userID: \(userID), homeserverURL: \(homeserverURL))"
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: NSCoding Types
|
||||
@@ -21,8 +31,10 @@ struct ClassicAppAccount: Equatable {
|
||||
final class ClassicAppMXAccount: NSObject, NSCoding {
|
||||
/// The obtained user ID.
|
||||
var userID: String
|
||||
/// The access token to create a MXRestClient.
|
||||
var accessToken: String
|
||||
/// The homeserver url (ex: "https://matrix.org").
|
||||
var homeserver: String?
|
||||
var homeserverURL: URL
|
||||
|
||||
/// Disable the account without logging out (NO by default).
|
||||
///
|
||||
@@ -37,6 +49,11 @@ final class ClassicAppMXAccount: NSObject, NSCoding {
|
||||
!isDisabled && !isSoftLogout
|
||||
}
|
||||
|
||||
/// Override the existing `CustomStringConvertible` conformance.
|
||||
override var description: String {
|
||||
"ClassicAppMXAccount(userID: \(userID), homeserverURL: \(homeserverURL), isDisabled: \(isDisabled), isSoftLogout: \(isSoftLogout))"
|
||||
}
|
||||
|
||||
// MARK: NSCoding
|
||||
|
||||
enum Keys {
|
||||
@@ -64,12 +81,15 @@ final class ClassicAppMXAccount: NSObject, NSCoding {
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
guard let userID = coder.decodeObject(forKey: Keys.userID) as? String,
|
||||
let homeserver = coder.decodeObject(forKey: Keys.homeserverURL) as? String else {
|
||||
let accessToken = coder.decodeObject(forKey: Keys.accessToken) as? String,
|
||||
let homeserver = coder.decodeObject(forKey: Keys.homeserverURL) as? String,
|
||||
let homeserverURL = URL(string: homeserver) else {
|
||||
return nil
|
||||
}
|
||||
|
||||
self.userID = userID
|
||||
self.homeserver = homeserver
|
||||
self.accessToken = accessToken
|
||||
self.homeserverURL = homeserverURL
|
||||
|
||||
isDisabled = coder.decodeBool(forKey: Keys.isDisabled)
|
||||
isSoftLogout = coder.decodeBool(forKey: Keys.isSoftLogout)
|
||||
@@ -89,7 +109,7 @@ final class ClassicAppMXUser: NSObject, NSCoding {
|
||||
/// The user display name.
|
||||
let displayName: String?
|
||||
/// The url of the user of the avatar.
|
||||
let avatarURL: String?
|
||||
let avatarURL: URL?
|
||||
|
||||
// MARK: NSCoding
|
||||
|
||||
@@ -110,7 +130,9 @@ final class ClassicAppMXUser: NSObject, NSCoding {
|
||||
|
||||
self.userID = userID
|
||||
displayName = aDecoder.decodeObject(forKey: Keys.displayName) as? String
|
||||
avatarURL = aDecoder.decodeObject(forKey: Keys.avatarURL) as? String
|
||||
|
||||
let avatarURLString = aDecoder.decodeObject(forKey: Keys.avatarURL) as? String
|
||||
avatarURL = avatarURLString.flatMap { URL(string: $0) }
|
||||
|
||||
super.init()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user