mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-06-06 15:32:20 +00:00
core, ui: tolerate unknown MsgContentTag in chatContentTypes (#6805)
This commit is contained in:
@@ -458,7 +458,7 @@ func apiGetChat(chatId: ChatId, scope: GroupChatScope?, contentTag: MsgContentTa
|
||||
|
||||
func apiGetChatContentTypes(chatId: ChatId, scope: GroupChatScope? = nil) async throws -> [MsgContentTag] {
|
||||
let r: ChatResponse0 = try await chatSendCmd(.apiGetChatContentTypes(chatId: chatId, scope: scope))
|
||||
if case let .chatContentTypes(types) = r { return types }
|
||||
if case let .chatContentTypes(types) = r { return types.filter { if case .unknown = $0 { return false }; return true } }
|
||||
throw r.unexpected
|
||||
}
|
||||
|
||||
|
||||
@@ -4773,7 +4773,7 @@ extension MsgContent: Encodable {
|
||||
}
|
||||
}
|
||||
|
||||
public enum MsgContentTag: String, Decodable {
|
||||
public enum MsgContentTag: Codable, Hashable {
|
||||
case text
|
||||
case link
|
||||
case image
|
||||
@@ -4781,6 +4781,43 @@ public enum MsgContentTag: String, Decodable {
|
||||
case voice
|
||||
case file
|
||||
case report
|
||||
case chat
|
||||
case unknown(type: String)
|
||||
|
||||
public var rawValue: String {
|
||||
switch self {
|
||||
case .text: return "text"
|
||||
case .link: return "link"
|
||||
case .image: return "image"
|
||||
case .video: return "video"
|
||||
case .voice: return "voice"
|
||||
case .file: return "file"
|
||||
case .report: return "report"
|
||||
case .chat: return "chat"
|
||||
case let .unknown(type): return type
|
||||
}
|
||||
}
|
||||
|
||||
public init(from decoder: Decoder) throws {
|
||||
let s = try decoder.singleValueContainer().decode(String.self)
|
||||
switch s {
|
||||
case "text": self = .text
|
||||
case "link": self = .link
|
||||
case "image": self = .image
|
||||
case "video": self = .video
|
||||
case "voice": self = .voice
|
||||
case "file": self = .file
|
||||
case "report": self = .report
|
||||
case "chat": self = .chat
|
||||
case "liveText": self = .text
|
||||
default: self = .unknown(type: s)
|
||||
}
|
||||
}
|
||||
|
||||
public func encode(to encoder: Encoder) throws {
|
||||
var container = encoder.singleValueContainer()
|
||||
try container.encode(rawValue)
|
||||
}
|
||||
}
|
||||
|
||||
public enum MsgChatLink: Codable, Equatable, Hashable {
|
||||
|
||||
Reference in New Issue
Block a user