2022-04-21 08:42:35 +02:00
|
|
|
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
2020-11-07 23:00:10 +01:00
|
|
|
|
2022-04-21 08:42:35 +02:00
|
|
|
import Foundation
|
|
|
|
import GRDB
|
|
|
|
import SessionUtilitiesKit
|
2020-11-07 23:00:10 +01:00
|
|
|
|
2022-04-21 08:42:35 +02:00
|
|
|
public extension Message {
|
|
|
|
enum Destination: Codable {
|
2020-11-07 23:00:10 +01:00
|
|
|
case contact(publicKey: String)
|
|
|
|
case closedGroup(groupPublicKey: String)
|
|
|
|
case openGroup(channel: UInt64, server: String)
|
2021-03-24 03:28:30 +01:00
|
|
|
case openGroupV2(room: String, server: String)
|
2020-11-25 06:15:16 +01:00
|
|
|
|
2022-04-21 08:42:35 +02:00
|
|
|
static func from(_ db: Database, thread: SessionThread) throws -> Message.Destination {
|
|
|
|
switch thread.variant {
|
|
|
|
case .contact: return .contact(publicKey: thread.id)
|
|
|
|
case .closedGroup: return .closedGroup(groupPublicKey: thread.id)
|
|
|
|
case .openGroup:
|
|
|
|
guard let openGroup: OpenGroup = try thread.openGroup.fetchOne(db) else {
|
2022-05-30 05:04:26 +02:00
|
|
|
throw StorageError.objectNotFound
|
2022-04-21 08:42:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return .openGroupV2(room: openGroup.room, server: openGroup.server)
|
2020-11-25 06:15:16 +01:00
|
|
|
}
|
|
|
|
}
|
2020-11-07 23:00:10 +01:00
|
|
|
}
|
|
|
|
}
|