session-ios/SessionMessagingKit/Messages/Control Messages/MessageRequestResponse.swift
Morgan Pretty 32304ae5dd Cleared out some of the legacy serialisation logic, further UI binding
Refactored the SignalApp class to Swift
Fixed a horizontal alignment issue in the ConversationTitleView
Fixed an issue where expiration timer update messages weren't migrated or rendering correctly
Fixed an issue where expiring messages weren't migrated correctly
Fixed an issue where closed groups which had been left were causing migration failures (due to data incorrectly being assumed to be required)
Shifted the Legacy Attachment types into the 'SMKLegacy' namespace
Moved all of the NSCoding logic for the TSMessage
2022-05-03 17:14:56 +10:00

73 lines
2.1 KiB
Swift

// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import GRDB
import SessionUtilitiesKit
public final class MessageRequestResponse: ControlMessage {
private enum CodingKeys: String, CodingKey {
case isApproved
}
public var isApproved: Bool
// MARK: - Initialization
public init(isApproved: Bool) {
self.isApproved = isApproved
super.init()
}
// MARK: - Codable
required init(from decoder: Decoder) throws {
let container: KeyedDecodingContainer<CodingKeys> = try decoder.container(keyedBy: CodingKeys.self)
isApproved = try container.decode(Bool.self, forKey: .isApproved)
try super.init(from: decoder)
}
public override func encode(to encoder: Encoder) throws {
try super.encode(to: encoder)
var container: KeyedEncodingContainer<CodingKeys> = encoder.container(keyedBy: CodingKeys.self)
try container.encodeIfPresent(isApproved, forKey: .isApproved)
}
// MARK: - Proto Conversion
public override class func fromProto(_ proto: SNProtoContent, sender: String) -> MessageRequestResponse? {
guard let messageRequestResponseProto = proto.messageRequestResponse else { return nil }
let isApproved = messageRequestResponseProto.isApproved
return MessageRequestResponse(isApproved: isApproved)
}
public override func toProto(_ db: Database) -> SNProtoContent? {
let messageRequestResponseProto = SNProtoMessageRequestResponse.builder(isApproved: isApproved)
let contentProto = SNProtoContent.builder()
do {
contentProto.setMessageRequestResponse(try messageRequestResponseProto.build())
return try contentProto.build()
} catch {
SNLog("Couldn't construct unsend request proto from: \(self).")
return nil
}
}
// MARK: - Description
public var description: String {
"""
MessageRequestResponse(
isApproved: \(isApproved)
)
"""
}
}