Files
Swiftgram/submodules/TelegramCore/Sources/SecretChats/SecretChatIncomingEncryptedOperation.swift
Isaac ac019b15c5 Refactor Api types 90-99 to use struct-wrapped constructors
Types refactored (file-grouped parallel approach):
- encrypted* (Chat, ChatDiscarded, ChatEmpty, ChatRequested, ChatWaiting,
  File, Message, MessageService)
- chatInviteExported
- exported* (ChatlistInvite, ContactToken, MessageLink, StoryLink)
- factCheck

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-16 02:19:54 +08:00

27 lines
1.6 KiB
Swift

import Foundation
import Postbox
import TelegramApi
private func keyFingerprintFromBytes(_ bytes: Buffer) -> Int64 {
if let memory = bytes.data, bytes.size >= 4 {
var fingerprint: Int64 = 0
memcpy(&fingerprint, memory, 8)
return fingerprint
}
return 0
}
extension SecretChatIncomingEncryptedOperation {
convenience init(message: Api.EncryptedMessage) {
switch message {
case let .encryptedMessage(encryptedMessageData):
let (randomId, chatId, date, bytes, file) = (encryptedMessageData.randomId, encryptedMessageData.chatId, encryptedMessageData.date, encryptedMessageData.bytes, encryptedMessageData.file)
self.init(peerId: PeerId(namespace: Namespaces.Peer.SecretChat, id: PeerId.Id._internalFromInt64Value(Int64(chatId))), globallyUniqueId: randomId, timestamp: date, type: .message, keyFingerprint: keyFingerprintFromBytes(bytes), contents: MemoryBuffer(bytes), mediaFileReference: SecretChatFileReference(file))
case let .encryptedMessageService(encryptedMessageServiceData):
let (randomId, chatId, date, bytes) = (encryptedMessageServiceData.randomId, encryptedMessageServiceData.chatId, encryptedMessageServiceData.date, encryptedMessageServiceData.bytes)
self.init(peerId: PeerId(namespace: Namespaces.Peer.SecretChat, id: PeerId.Id._internalFromInt64Value(Int64(chatId))), globallyUniqueId: randomId, timestamp: date, type: .service, keyFingerprint: keyFingerprintFromBytes(bytes), contents: MemoryBuffer(bytes), mediaFileReference: nil)
}
}
}