mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.6 KiB
Swift
44 lines
1.6 KiB
Swift
6 years ago
|
|
||
5 years ago
|
@objc(SNOpenGroup)
|
||
|
public final class OpenGroup : NSObject, NSCoding {
|
||
6 years ago
|
@objc public let id: String
|
||
|
@objc public let idAsData: Data
|
||
6 years ago
|
@objc public let channel: UInt64
|
||
6 years ago
|
@objc public let server: String
|
||
|
@objc public let displayName: String
|
||
|
@objc public let isDeletable: Bool
|
||
6 years ago
|
|
||
6 years ago
|
@objc public init?(channel: UInt64, server: String, displayName: String, isDeletable: Bool) {
|
||
|
let id = "\(server).\(channel)"
|
||
|
self.id = id
|
||
|
guard let idAsData = id.data(using: .utf8) else { return nil }
|
||
|
self.idAsData = idAsData
|
||
6 years ago
|
self.channel = channel
|
||
6 years ago
|
self.server = server.lowercased()
|
||
6 years ago
|
self.displayName = displayName
|
||
|
self.isDeletable = isDeletable
|
||
|
}
|
||
|
|
||
6 years ago
|
// MARK: Coding
|
||
|
@objc public init?(coder: NSCoder) {
|
||
|
channel = UInt64(coder.decodeInt64(forKey: "channel"))
|
||
|
server = coder.decodeObject(forKey: "server") as! String
|
||
6 years ago
|
let id = "\(server).\(channel)"
|
||
|
self.id = id
|
||
|
guard let idAsData = id.data(using: .utf8) else { return nil }
|
||
|
self.idAsData = idAsData
|
||
6 years ago
|
displayName = coder.decodeObject(forKey: "displayName") as! String
|
||
|
isDeletable = coder.decodeBool(forKey: "isDeletable")
|
||
|
super.init()
|
||
|
}
|
||
|
|
||
|
@objc public func encode(with coder: NSCoder) {
|
||
|
coder.encode(Int64(channel), forKey: "channel")
|
||
|
coder.encode(server, forKey: "server")
|
||
|
coder.encode(displayName, forKey: "displayName")
|
||
|
coder.encode(isDeletable, forKey: "isDeletable")
|
||
|
}
|
||
|
|
||
5 years ago
|
override public var description: String { "\(displayName) (\(server))" }
|
||
6 years ago
|
}
|