[ServiceId] Update InteractionFinder
This commit is contained in:
parent
05b5391dc9
commit
94e7d2fba1
@ -3,6 +3,7 @@
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
//
|
||||
|
||||
import LibSignalClient
|
||||
import SignalCoreKit
|
||||
import SignalMessaging
|
||||
import SignalUI
|
||||
@ -51,7 +52,7 @@ class StoryGroupReplyLoader: Dependencies {
|
||||
self.storyMessage = storyMessage
|
||||
self.tableView = tableView
|
||||
self.messageBatchFetcher = StoryGroupReplyBatchFetcher(
|
||||
storyAuthor: UntypedServiceId(storyMessage.authorUuid),
|
||||
storyAuthor: Aci(fromUUID: storyMessage.authorUuid),
|
||||
storyTimestamp: storyMessage.timestamp
|
||||
)
|
||||
self.messageLoader = MessageLoader(
|
||||
@ -324,12 +325,12 @@ extension StoryGroupReplyLoader: DatabaseChangeDelegate {
|
||||
// MARK: - Batch Fetcher
|
||||
|
||||
private class StoryGroupReplyBatchFetcher: MessageLoaderBatchFetcher {
|
||||
private let storyAuthor: UntypedServiceId
|
||||
private let storyAuthor: Aci
|
||||
private let storyTimestamp: UInt64
|
||||
|
||||
private(set) var uniqueIdsAndRowIds = [(uniqueId: String, rowId: Int64)]()
|
||||
|
||||
init(storyAuthor: UntypedServiceId, storyTimestamp: UInt64) {
|
||||
init(storyAuthor: Aci, storyTimestamp: UInt64) {
|
||||
self.storyAuthor = storyAuthor
|
||||
self.storyTimestamp = storyTimestamp
|
||||
}
|
||||
|
||||
@ -981,7 +981,7 @@ class MessageManagerRequest: NSObject {
|
||||
private static func isDuplicate(_ decryptedEnvelope: DecryptedIncomingEnvelope, tx: SDSAnyReadTransaction) -> Bool {
|
||||
return InteractionFinder.existsIncomingMessage(
|
||||
timestamp: decryptedEnvelope.timestamp,
|
||||
sourceServiceId: decryptedEnvelope.sourceAci.untypedServiceId,
|
||||
sourceAci: decryptedEnvelope.sourceAci,
|
||||
sourceDeviceId: decryptedEnvelope.sourceDeviceId,
|
||||
transaction: tx
|
||||
)
|
||||
|
||||
@ -270,7 +270,7 @@ public class StoryFinder: NSObject {
|
||||
let sql = """
|
||||
SELECT \(StoryMessage.columnName(.timestamp))
|
||||
FROM \(StoryMessage.databaseTableName)
|
||||
WHERE \(StoryMessage.columnName(.authorUuid)) != '\(StoryMessage.systemStoryAuthorUUID.uuidString)'
|
||||
WHERE \(StoryMessage.columnName(.authorUuid)) != '\(StoryMessage.systemStoryAuthor.serviceIdUppercaseString)'
|
||||
ORDER BY \(StoryMessage.columnName(.timestamp)) ASC
|
||||
LIMIT 1
|
||||
"""
|
||||
|
||||
@ -347,7 +347,7 @@ public final class StoryMessage: NSObject, SDSCodableModel, Decodable {
|
||||
|
||||
// The "Signal account" used for e.g. the onboarding story has a fixed UUID
|
||||
// we can use to prevent trying to actually reply, send a message, etc.
|
||||
public static let systemStoryAuthorUUID = UUID(uuidString: "00000000-0000-0000-0000-000000000001")!
|
||||
public static let systemStoryAuthor = Aci(fromUUID: UUID(uuidString: "00000000-0000-0000-0000-000000000001")!)
|
||||
|
||||
@discardableResult
|
||||
public static func createFromSystemAuthor(
|
||||
@ -378,7 +378,7 @@ public final class StoryMessage: NSObject, SDSCodableModel, Decodable {
|
||||
// sophisticated for future stories this is where we'd change it, maybe make this
|
||||
// a null timestamp and interpret that different when we read it back out.
|
||||
timestamp: timestamp,
|
||||
authorUuid: Self.systemStoryAuthorUUID,
|
||||
authorUuid: Self.systemStoryAuthor.temporary_rawUUID,
|
||||
groupId: nil,
|
||||
manifest: manifest,
|
||||
attachment: attachment,
|
||||
@ -949,7 +949,7 @@ extension OWSOutgoingMessageRecipientState: Codable {}
|
||||
extension SignalServiceAddress {
|
||||
|
||||
public var isSystemStoryAddress: Bool {
|
||||
return self.uuid == StoryMessage.systemStoryAuthorUUID
|
||||
return self.serviceId == StoryMessage.systemStoryAuthor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
import Foundation
|
||||
import GRDB
|
||||
import LibSignalClient
|
||||
import SignalCoreKit
|
||||
|
||||
public enum EditMessageQueryMode {
|
||||
@ -22,7 +23,7 @@ protocol InteractionFinderAdapter {
|
||||
|
||||
static func fetch(rowId: Int64, transaction: ReadTransaction) throws -> TSInteraction?
|
||||
|
||||
static func existsIncomingMessage(timestamp: UInt64, sourceServiceId: UntypedServiceId, sourceDeviceId: UInt32, transaction: ReadTransaction) -> Bool
|
||||
static func existsIncomingMessage(timestamp: UInt64, sourceAci: Aci, sourceDeviceId: UInt32, transaction: ReadTransaction) -> Bool
|
||||
|
||||
static func interactions(withTimestamp timestamp: UInt64, filter: @escaping (TSInteraction) -> Bool, transaction: ReadTransaction) throws -> [TSInteraction]
|
||||
|
||||
@ -43,7 +44,7 @@ protocol InteractionFinderAdapter {
|
||||
|
||||
static func enumerateGroupReplies(for storyMessage: StoryMessage, transaction: ReadTransaction, block: @escaping (TSMessage, UnsafeMutablePointer<ObjCBool>) -> Void)
|
||||
static func hasLocalUserReplied(storyTimestamp: UInt64, storyAuthorUuidString: String, transaction: ReadTransaction) -> Bool
|
||||
static func groupReplyUniqueIdsAndRowIds(storyAuthor: UntypedServiceId, storyTimestamp: UInt64, transaction: ReadTransaction) -> [(String, Int64)]
|
||||
static func groupReplyUniqueIdsAndRowIds(storyAuthor: Aci, storyTimestamp: UInt64, transaction: ReadTransaction) -> [(String, Int64)]
|
||||
|
||||
// MARK: - instance methods
|
||||
|
||||
@ -119,10 +120,10 @@ public class InteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
}
|
||||
}
|
||||
|
||||
public class func existsIncomingMessage(timestamp: UInt64, sourceServiceId: UntypedServiceId, sourceDeviceId: UInt32, transaction: SDSAnyReadTransaction) -> Bool {
|
||||
public class func existsIncomingMessage(timestamp: UInt64, sourceAci: Aci, sourceDeviceId: UInt32, transaction: SDSAnyReadTransaction) -> Bool {
|
||||
switch transaction.readTransaction {
|
||||
case .grdbRead(let grdbRead):
|
||||
return GRDBInteractionFinder.existsIncomingMessage(timestamp: timestamp, sourceServiceId: sourceServiceId, sourceDeviceId: sourceDeviceId, transaction: grdbRead)
|
||||
return GRDBInteractionFinder.existsIncomingMessage(timestamp: timestamp, sourceAci: sourceAci, sourceDeviceId: sourceDeviceId, transaction: grdbRead)
|
||||
}
|
||||
}
|
||||
|
||||
@ -249,7 +250,7 @@ public class InteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
}
|
||||
|
||||
public static func groupReplyUniqueIdsAndRowIds(
|
||||
storyAuthor: UntypedServiceId,
|
||||
storyAuthor: Aci,
|
||||
storyTimestamp: UInt64,
|
||||
transaction: SDSAnyReadTransaction
|
||||
) -> [(String, Int64)] {
|
||||
@ -691,7 +692,7 @@ public class GRDBInteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
)
|
||||
}
|
||||
|
||||
static func existsIncomingMessage(timestamp: UInt64, sourceServiceId: UntypedServiceId, sourceDeviceId: UInt32, transaction: GRDBReadTransaction) -> Bool {
|
||||
static func existsIncomingMessage(timestamp: UInt64, sourceAci: Aci, sourceDeviceId: UInt32, transaction: GRDBReadTransaction) -> Bool {
|
||||
let sql = """
|
||||
SELECT EXISTS(
|
||||
SELECT 1
|
||||
@ -706,8 +707,8 @@ public class GRDBInteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
"""
|
||||
let arguments: StatementArguments = [
|
||||
timestamp,
|
||||
sourceServiceId.uuidValue.uuidString,
|
||||
SignalServiceAddress(sourceServiceId).phoneNumber,
|
||||
sourceAci.serviceIdUppercaseString,
|
||||
SignalServiceAddress(sourceAci).phoneNumber,
|
||||
sourceDeviceId
|
||||
]
|
||||
do {
|
||||
@ -1002,11 +1003,11 @@ public class GRDBInteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
}
|
||||
|
||||
static func groupReplyUniqueIdsAndRowIds(
|
||||
storyAuthor: UntypedServiceId,
|
||||
storyAuthor: Aci,
|
||||
storyTimestamp: UInt64,
|
||||
transaction: GRDBReadTransaction
|
||||
) -> [(String, Int64)] {
|
||||
guard storyAuthor.uuidValue != StoryMessage.systemStoryAuthorUUID else {
|
||||
guard storyAuthor != StoryMessage.systemStoryAuthor else {
|
||||
// No replies on system stories.
|
||||
return []
|
||||
}
|
||||
@ -1022,7 +1023,7 @@ public class GRDBInteractionFinder: NSObject, InteractionFinderAdapter {
|
||||
return try Row.fetchAll(
|
||||
transaction.database,
|
||||
sql: sql,
|
||||
arguments: [storyTimestamp, storyAuthor.uuidValue.uuidString]
|
||||
arguments: [storyTimestamp, storyAuthor.serviceIdUppercaseString]
|
||||
).map { ($0[0], $0[1]) }
|
||||
} catch {
|
||||
owsFail("error: \(error)")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user