mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
9859cf95a4
Fixed an issue where fileIds weren't correctly getting sent along with open group messages Fixed an issue where the screens could miss updates if the device was locked with the app in the foreground and then later unlocked after receiving notifications Added an optimisation to prevent attempting to send a message after it has been deleted Added logic to report fake calls if the code goes down an invalid code path when handling a call (to prevent Apple blocking the app) Delayed the core which clears notifications to increase the time the app has to handle interactions (just in case it was a race condition)
69 lines
2.6 KiB
Swift
69 lines
2.6 KiB
Swift
// Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
|
|
|
|
import Foundation
|
|
import GRDB
|
|
import SessionUtilitiesKit
|
|
|
|
public extension Message {
|
|
enum Destination: Codable {
|
|
case contact(publicKey: String)
|
|
case closedGroup(groupPublicKey: String)
|
|
case openGroup(
|
|
roomToken: String,
|
|
server: String,
|
|
whisperTo: String? = nil,
|
|
whisperMods: Bool = false,
|
|
fileIds: [String]? = nil
|
|
)
|
|
case openGroupInbox(server: String, openGroupPublicKey: String, blindedPublicKey: String)
|
|
|
|
static func from(
|
|
_ db: Database,
|
|
thread: SessionThread,
|
|
fileIds: [String]? = nil
|
|
) throws -> Message.Destination {
|
|
switch thread.variant {
|
|
case .contact:
|
|
if SessionId.Prefix(from: thread.id) == .blinded {
|
|
guard let lookup: BlindedIdLookup = try? BlindedIdLookup.fetchOne(db, id: thread.id) else {
|
|
preconditionFailure("Attempting to send message to blinded id without the Open Group information")
|
|
}
|
|
|
|
return .openGroupInbox(
|
|
server: lookup.openGroupServer,
|
|
openGroupPublicKey: lookup.openGroupPublicKey,
|
|
blindedPublicKey: thread.id
|
|
)
|
|
}
|
|
|
|
return .contact(publicKey: thread.id)
|
|
|
|
case .closedGroup:
|
|
return .closedGroup(groupPublicKey: thread.id)
|
|
|
|
case .openGroup:
|
|
guard let openGroup: OpenGroup = try thread.openGroup.fetchOne(db) else {
|
|
throw StorageError.objectNotFound
|
|
}
|
|
|
|
return .openGroup(roomToken: openGroup.roomToken, server: openGroup.server, fileIds: fileIds)
|
|
}
|
|
}
|
|
|
|
func with(fileIds: [String]) -> Message.Destination {
|
|
// Only Open Group messages support receiving the 'fileIds'
|
|
switch self {
|
|
case .openGroup(let roomToken, let server, let whisperTo, let whisperMods, _):
|
|
return .openGroup(
|
|
roomToken: roomToken,
|
|
server: server,
|
|
whisperTo: whisperTo,
|
|
whisperMods: whisperMods,
|
|
fileIds: fileIds
|
|
)
|
|
|
|
default: return self
|
|
}
|
|
}
|
|
}
|
|
}
|