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.
37 lines
1.3 KiB
Swift
37 lines
1.3 KiB
Swift
|
|
public extension Message {
|
|
|
|
enum Destination {
|
|
case contact(publicKey: String)
|
|
case closedGroup(groupPublicKey: String)
|
|
case legacyOpenGroup(channel: UInt64, server: String)
|
|
case openGroup(
|
|
roomToken: String,
|
|
server: String,
|
|
whisperTo: String? = nil,
|
|
whisperMods: Bool = false,
|
|
fileIds: [Int64]? = nil // TODO: Handle 'fileIds'
|
|
)
|
|
|
|
static func from(_ thread: TSThread) -> Message.Destination {
|
|
if let thread = thread as? TSContactThread {
|
|
return .contact(publicKey: thread.contactSessionID())
|
|
}
|
|
|
|
if let thread = thread as? TSGroupThread, thread.isClosedGroup {
|
|
let groupID = thread.groupModel.groupId
|
|
let groupPublicKey = LKGroupUtilities.getDecodedGroupID(groupID)
|
|
return .closedGroup(groupPublicKey: groupPublicKey)
|
|
}
|
|
|
|
if let thread = thread as? TSGroupThread, thread.isOpenGroup {
|
|
let openGroup: OpenGroupV2 = Storage.shared.getV2OpenGroup(for: thread.uniqueId!)!
|
|
|
|
return .openGroup(roomToken: openGroup.room, server: openGroup.server)
|
|
}
|
|
|
|
preconditionFailure("TODO: Handle legacy closed groups.")
|
|
}
|
|
}
|
|
}
|