mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-23 17:07:31 +09:00
Dactyloidae iOS initial commit
This commit is contained in:
parent
daa6179d22
commit
7154a0497e
2123 changed files with 197052 additions and 0 deletions
66
mobile/ios/Account/FxADevice.swift
Normal file
66
mobile/ios/Account/FxADevice.swift
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import Foundation
|
||||
import Shared
|
||||
import SwiftyJSON
|
||||
|
||||
public struct FxADevicePushParams {
|
||||
let callback: String
|
||||
let publicKey: String
|
||||
let authKey: String
|
||||
}
|
||||
|
||||
public class FxADevice: RemoteDevice {
|
||||
let pushParams: FxADevicePushParams?
|
||||
|
||||
fileprivate init(name: String, id: String?, type: String?, isCurrentDevice: Bool = false, push: FxADevicePushParams?, lastAccessTime: Timestamp?) {
|
||||
self.pushParams = push
|
||||
super.init(id: id, name: name, type: type, isCurrentDevice: isCurrentDevice, lastAccessTime: lastAccessTime)
|
||||
}
|
||||
|
||||
static func forRegister(_ name: String, type: String, push: FxADevicePushParams?) -> FxADevice {
|
||||
return FxADevice(name: name, id: nil, type: type, push: push, lastAccessTime: nil)
|
||||
}
|
||||
|
||||
static func forUpdate(_ name: String, id: String, push: FxADevicePushParams?) -> FxADevice {
|
||||
return FxADevice(name: name, id: id, type: nil, push: push, lastAccessTime: nil)
|
||||
}
|
||||
|
||||
func toJSON() -> JSON {
|
||||
var parameters = [String: String]()
|
||||
parameters["name"] = name
|
||||
parameters["id"] = id
|
||||
parameters["type"] = type
|
||||
if let push = self.pushParams {
|
||||
parameters["pushCallback"] = push.callback
|
||||
parameters["pushPublicKey"] = push.publicKey
|
||||
parameters["pushAuthKey"] = push.authKey
|
||||
}
|
||||
return JSON(parameters as NSDictionary)
|
||||
}
|
||||
|
||||
static func fromJSON(_ json: JSON) -> FxADevice? {
|
||||
guard json.error == nil,
|
||||
let id = json["id"].string,
|
||||
let name = json["name"].string else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let isCurrentDevice = json["isCurrentDevice"].bool ?? false
|
||||
let lastAccessTime = json["lastAccessTime"].uInt64
|
||||
let type = json["type"].string
|
||||
|
||||
let push: FxADevicePushParams?
|
||||
if let pushCallback = json["pushCallback"].stringValue(),
|
||||
let publicKey = json["pushPublicKey"].stringValue(), publicKey != "",
|
||||
let authKey = json["pushAuthKey"].stringValue(), authKey != "" {
|
||||
push = FxADevicePushParams(callback: pushCallback, publicKey: publicKey, authKey: authKey)
|
||||
} else {
|
||||
push = nil
|
||||
}
|
||||
|
||||
return FxADevice(name: name, id: id, type: type, isCurrentDevice: isCurrentDevice, push: push, lastAccessTime: lastAccessTime)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue