Remove use of ExpressibleByXLiteral from MessageBackup IDs
This commit is contained in:
parent
5aac1ec836
commit
4e993f2f8f
@ -8,19 +8,25 @@ import LibSignalClient
|
||||
|
||||
extension MessageBackup {
|
||||
|
||||
public struct ChatId: ExpressibleByIntegerLiteral, Hashable {
|
||||
public struct ChatId: Hashable, MessageBackupLoggableId {
|
||||
let value: UInt64
|
||||
|
||||
public typealias IntegerLiteralType = UInt64
|
||||
|
||||
internal let value: UInt64
|
||||
|
||||
public init(integerLiteral value: UInt64) {
|
||||
public init(value: UInt64) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
fileprivate init(_ value: UInt64) {
|
||||
self.value = value
|
||||
fileprivate init(chat: BackupProto.Chat) {
|
||||
self.init(value: chat.id)
|
||||
}
|
||||
|
||||
fileprivate init(chatItem: BackupProto.ChatItem) {
|
||||
self.init(value: chatItem.chatId)
|
||||
}
|
||||
|
||||
// MARK: MessageBackupLoggableId
|
||||
|
||||
public var typeLogString: String { "BackupProto.Chat" }
|
||||
public var idLogString: String { "\(value)" }
|
||||
}
|
||||
|
||||
/// Chats only exist for group (v2) and contact threads, not story threads.
|
||||
@ -40,22 +46,33 @@ extension MessageBackup {
|
||||
}
|
||||
|
||||
public var uniqueId: MessageBackup.ThreadUniqueId {
|
||||
return .init(self.thread.uniqueId)
|
||||
return .init(chatThread: self)
|
||||
}
|
||||
}
|
||||
|
||||
public struct ThreadUniqueId: ExpressibleByStringLiteral, Hashable {
|
||||
public typealias StringLiteralType = String
|
||||
public struct ThreadUniqueId: Hashable, MessageBackupLoggableId {
|
||||
let value: String
|
||||
|
||||
internal let value: String
|
||||
|
||||
public init(stringLiteral value: String) {
|
||||
public init(value: String) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
public init(_ value: String) {
|
||||
self.value = value
|
||||
fileprivate init(thread: TSThread) {
|
||||
self.init(value: thread.uniqueId)
|
||||
}
|
||||
|
||||
fileprivate init(interaction: TSInteraction) {
|
||||
self.init(value: interaction.uniqueThreadId)
|
||||
}
|
||||
|
||||
fileprivate init(chatThread: ChatThread) {
|
||||
self.init(thread: chatThread.thread)
|
||||
}
|
||||
|
||||
// MARK: MessageBackupLoggableId
|
||||
|
||||
public var typeLogString: String { "TSThread" }
|
||||
public var idLogString: String { value }
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,7 +88,7 @@ extension MessageBackup {
|
||||
|
||||
public let recipientContext: RecipientArchivingContext
|
||||
|
||||
private var currentChatId: ChatId = 1
|
||||
private var currentChatId = ChatId(value: 1)
|
||||
private let map = SharedMap<ThreadUniqueId, ChatId>()
|
||||
|
||||
internal init(recipientContext: RecipientArchivingContext) {
|
||||
@ -80,7 +97,7 @@ extension MessageBackup {
|
||||
|
||||
internal func assignChatId(to threadUniqueId: ThreadUniqueId) -> ChatId {
|
||||
defer {
|
||||
currentChatId = ChatId(currentChatId.value + 1)
|
||||
currentChatId = ChatId(value: currentChatId.value + 1)
|
||||
}
|
||||
map[threadUniqueId] = currentChatId
|
||||
return currentChatId
|
||||
@ -142,39 +159,27 @@ extension MessageBackup {
|
||||
extension BackupProto.Chat {
|
||||
|
||||
public var chatId: MessageBackup.ChatId {
|
||||
return .init(id)
|
||||
return MessageBackup.ChatId(chat: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.ChatItem {
|
||||
|
||||
public var typedChatId: MessageBackup.ChatId {
|
||||
return .init(chatId)
|
||||
return MessageBackup.ChatId(chatItem: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TSThread {
|
||||
|
||||
public var uniqueThreadIdentifier: MessageBackup.ThreadUniqueId {
|
||||
return .init(self.uniqueId)
|
||||
return MessageBackup.ThreadUniqueId(thread: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension TSInteraction {
|
||||
|
||||
public var uniqueThreadIdentifier: MessageBackup.ThreadUniqueId {
|
||||
return .init(self.uniqueThreadId)
|
||||
return MessageBackup.ThreadUniqueId(interaction: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension MessageBackup.ThreadUniqueId: MessageBackupLoggableId {
|
||||
public var typeLogString: String { "TSThread" }
|
||||
|
||||
public var idLogString: String { value }
|
||||
}
|
||||
|
||||
extension MessageBackup.ChatId: MessageBackupLoggableId {
|
||||
public var typeLogString: String { "BackupProto.Chat" }
|
||||
|
||||
public var idLogString: String { "\(value)" }
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ public protocol MessageBackupLocalRecipientArchiver: MessageBackupProtoArchiver
|
||||
|
||||
public class MessageBackupLocalRecipientArchiverImpl: MessageBackupLocalRecipientArchiver {
|
||||
|
||||
private static let localRecipientId = RecipientId(integerLiteral: 1)
|
||||
private static let localRecipientId = RecipientId(value: 1)
|
||||
|
||||
public func archiveLocalRecipient(stream: MessageBackupProtoOutputStream) -> MessageBackup.ArchiveLocalRecipientResult {
|
||||
let error = Self.writeFrameToStream(
|
||||
|
||||
@ -8,18 +8,35 @@ import LibSignalClient
|
||||
|
||||
extension MessageBackup {
|
||||
|
||||
public struct RecipientId: ExpressibleByIntegerLiteral, Hashable {
|
||||
public struct RecipientId: Hashable {
|
||||
let value: UInt64
|
||||
|
||||
public typealias IntegerLiteralType = UInt64
|
||||
|
||||
internal let value: UInt64
|
||||
|
||||
public init(integerLiteral value: UInt64) {
|
||||
public init(value: UInt64) {
|
||||
self.value = value
|
||||
}
|
||||
|
||||
fileprivate init(_ value: UInt64) {
|
||||
self.value = value
|
||||
fileprivate init(recipient: BackupProto.Recipient) {
|
||||
self.init(value: recipient.id)
|
||||
}
|
||||
|
||||
fileprivate init(chat: BackupProto.Chat) {
|
||||
self.init(value: chat.recipientId)
|
||||
}
|
||||
|
||||
fileprivate init(chatItem: BackupProto.ChatItem) {
|
||||
self.init(value: chatItem.authorId)
|
||||
}
|
||||
|
||||
fileprivate init(reaction: BackupProto.Reaction) {
|
||||
self.init(value: reaction.authorId)
|
||||
}
|
||||
|
||||
fileprivate init(quote: BackupProto.Quote) {
|
||||
self.init(value: quote.authorId)
|
||||
}
|
||||
|
||||
fileprivate init(sendStatus: BackupProto.SendStatus) {
|
||||
self.init(value: sendStatus.recipientId)
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,7 +76,7 @@ extension MessageBackup {
|
||||
self.localRecipientId = localRecipientId
|
||||
|
||||
// Start after the local recipient id.
|
||||
currentRecipientId = RecipientId(localRecipientId.value + 1)
|
||||
currentRecipientId = RecipientId(value: localRecipientId.value + 1)
|
||||
|
||||
// Also insert the local identifiers, just in case we try and look
|
||||
// up the local recipient by .contact enum case.
|
||||
@ -74,7 +91,7 @@ extension MessageBackup {
|
||||
|
||||
internal func assignRecipientId(to address: Address) -> RecipientId {
|
||||
defer {
|
||||
currentRecipientId = RecipientId(currentRecipientId.value + 1)
|
||||
currentRecipientId = RecipientId(value: currentRecipientId.value + 1)
|
||||
}
|
||||
switch address {
|
||||
case .group(let groupId):
|
||||
@ -168,40 +185,40 @@ extension MessageBackup.RecipientArchivingContext.Address: MessageBackupLoggable
|
||||
extension BackupProto.Recipient {
|
||||
|
||||
public var recipientId: MessageBackup.RecipientId {
|
||||
return .init(id)
|
||||
return MessageBackup.RecipientId(recipient: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.Chat {
|
||||
|
||||
public var typedRecipientId: MessageBackup.RecipientId {
|
||||
return .init(recipientId)
|
||||
return MessageBackup.RecipientId(chat: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.ChatItem {
|
||||
|
||||
public var authorRecipientId: MessageBackup.RecipientId {
|
||||
return .init(authorId)
|
||||
return MessageBackup.RecipientId(chatItem: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.Reaction {
|
||||
|
||||
public var authorRecipientId: MessageBackup.RecipientId {
|
||||
return .init(authorId)
|
||||
return MessageBackup.RecipientId(reaction: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.Quote {
|
||||
|
||||
public var authorRecipientId: MessageBackup.RecipientId {
|
||||
return .init(authorId)
|
||||
return MessageBackup.RecipientId(quote: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension BackupProto.SendStatus {
|
||||
public var destinationRecipientId: MessageBackup.RecipientId {
|
||||
return .init(recipientId)
|
||||
return MessageBackup.RecipientId(sendStatus: self)
|
||||
}
|
||||
}
|
||||
|
||||
@ -318,7 +318,7 @@ public class MessageBackupManagerImpl: MessageBackupManager {
|
||||
MessageBackup.CallId(
|
||||
callId: backupProtoCall.callId,
|
||||
conversationRecipientId: MessageBackup.RecipientId(
|
||||
integerLiteral: backupProtoCall.conversationRecipientId
|
||||
value: backupProtoCall.conversationRecipientId
|
||||
)
|
||||
))
|
||||
])
|
||||
|
||||
Loading…
Reference in New Issue
Block a user