[WIP] Add all extensions

This commit is contained in:
Ali 2020-10-18 19:13:31 +04:00
parent ed7d110c94
commit 702d572f07
48 changed files with 480 additions and 54 deletions

View File

@ -997,6 +997,74 @@ ios_extension(
],
)
plist_fragment(
name = "NotificationContentInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIdentifier</key>
<string>{telegram_bundle_id}.NotificationContent</string>
<key>CFBundleName</key>
<string>Telegram</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>UNNotificationExtensionCategory</key>
<array>
<string>withReplyMedia</string>
<string>withMuteMedia</string>
</array>
<key>UNNotificationExtensionInitialContentSizeRatio</key>
<real>0.0001</real>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.usernotifications.content-extension</string>
<key>NSExtensionPrincipalClass</key>
<string>NotificationViewController</string>
</dict>
""".format(
telegram_bundle_id = telegram_bundle_id,
)
)
swift_library(
name = "NotificationContentExtensionLib",
module_name = "NotificationContentExtensionLib",
srcs = glob([
"NotificationContent/**/*.swift",
]),
deps = [
"//submodules/TelegramUI:TelegramUI"
],
)
ios_extension(
name = "NotificationContentExtension",
bundle_id = "{telegram_bundle_id}.NotificationContent".format(
telegram_bundle_id = telegram_bundle_id,
),
families = [
"iphone",
"ipad",
],
infoplists = [
":NotificationContentInfoPlist",
":VersionInfoPlist",
":AppNameInfoPlist",
],
minimum_os_version = "9.0",
provisioning_profile = "//build-input/data/provisioning-profiles:NotificationContent.mobileprovision",
deps = [":NotificationContentExtensionLib"],
frameworks = [
":TelegramUIFramework"
],
)
plist_fragment(
name = "WidgetInfoPlist",
extension = "plist",
@ -1054,13 +1122,86 @@ ios_extension(
frameworks = [],
)
plist_fragment(
name = "IntentsInfoPlist",
extension = "plist",
template =
"""
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleIdentifier</key>
<string>{telegram_bundle_id}.SiriIntents</string>
<key>CFBundleName</key>
<string>Telegram</string>
<key>CFBundlePackageType</key>
<string>XPC!</string>
<key>NSExtension</key>
<dict>
<key>NSExtensionAttributes</key>
<dict>
<key>IntentsRestrictedWhileLocked</key>
<array/>
<key>IntentsRestrictedWhileProtectedDataUnavailable</key>
<array/>
<key>IntentsSupported</key>
<array>
<string>INSendMessageIntent</string>
<string>INStartAudioCallIntent</string>
<string>INSearchForMessagesIntent</string>
<string>INSetMessageAttributeIntent</string>
<string>INSearchCallHistoryIntent</string>
</array>
</dict>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.intents-service</string>
<key>NSExtensionPrincipalClass</key>
<string>IntentHandler</string>
</dict>
""".format(
telegram_bundle_id = telegram_bundle_id,
)
)
swift_library(
name = "NotificationServiceExtensionLib",
module_name = "NotificationServiceExtensionLib",
name = "IntentsExtensionLib",
module_name = "IntentsExtensionLib",
srcs = glob([
"NotificationServiceNext/**/*.swift",
"SiriIntents/**/*.swift",
]),
deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/Postbox:Postbox",
"//submodules/TelegramApi:TelegramApi",
"//submodules/SyncCore:SyncCore",
"//submodules/TelegramCore:TelegramCore",
"//submodules/BuildConfig:BuildConfig",
"//submodules/OpenSSLEncryptionProvider:OpenSSLEncryptionProvider",
"//submodules/AppLockState:AppLockState",
],
)
ios_extension(
name = "IntentsExtension",
bundle_id = "{telegram_bundle_id}.SiriIntents".format(
telegram_bundle_id = telegram_bundle_id,
),
families = [
"iphone",
"ipad",
],
infoplists = [
":IntentsInfoPlist",
":VersionInfoPlist",
":AppNameInfoPlist",
],
minimum_os_version = "9.0",
provisioning_profile = "//build-input/data/provisioning-profiles:Intents.mobileprovision",
deps = [":IntentsExtensionLib"],
frameworks = [
":SwiftSignalKitFramework",
":PostboxFramework",
":TelegramApiFramework",
":SyncCoreFramework",
],
)
@ -1105,8 +1246,13 @@ ios_extension(
],
minimum_os_version = "10.0",
provisioning_profile = "//build-input/data/provisioning-profiles:NotificationService.mobileprovision",
deps = [":NotificationServiceExtensionLib"],
deps = ["//Telegram/NotificationService:NotificationServiceExtensionLib"],
frameworks = [
":MtProtoKitFramework",
":SwiftSignalKitFramework",
":PostboxFramework",
":TelegramApiFramework",
":SyncCoreFramework",
],
)
@ -1309,9 +1455,9 @@ ios_application(
extensions = [
":ShareExtension",
":WidgetExtension",
#":NotificationContentExtension",
#":NotificationServiceExtension",
#":IntentsExtension",
":NotificationContentExtension",
":NotificationServiceExtension",
":IntentsExtension",
],
watch_application = ":TelegramWatchApp",
deps = [

View File

@ -5,7 +5,7 @@ import TelegramUI
import BuildConfig
@objc(NotificationViewController)
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
class NotificationViewController: UIViewController, UNNotificationContentExtension {
private var impl: NotificationViewControllerImpl?

View File

@ -0,0 +1,2 @@
load("//Config:buck_rule_macros.bzl", "static_library")

View File

@ -0,0 +1,28 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "NotificationServiceExtensionLib",
module_name = "NotificationServiceExtensionLib",
srcs = glob([
"Sources/*.swift",
]),
deps = [
"//submodules/BuildConfig:BuildConfig",
"//submodules/MtProtoKit:MtProtoKit",
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/EncryptionProvider:EncryptionProvider",
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/PostboxDataTypes:PostboxDataTypes",
"//submodules/Database/MessageHistoryReadStateTable:MessageHistoryReadStateTable",
"//submodules/Database/MessageHistoryMetadataTable:MessageHistoryMetadataTable",
"//submodules/Database/PreferencesTable:PreferencesTable",
"//submodules/Database/PeerTable:PeerTable",
"//submodules/sqlcipher:sqlcipher",
"//submodules/AppLockState:AppLockState",
"//submodules/NotificationsPresentationData:NotificationsPresentationData",
"//Telegram/NotificationService/NotificationServiceObjC:NotificationServiceObjC",
],
visibility = [
"//visibility:public",
],
)

View File

@ -1,6 +0,0 @@
#ifndef NotificationService_BridgingHeader_h
#define NotificationService_BridgingHeader_h
#import "NotificationService.h"
#endif

View File

@ -0,0 +1,18 @@
load("//Config:buck_rule_macros.bzl", "static_library")
static_library(
name = "NotificationServiceObjC",
srcs = glob([
"Sources/*.m",
]),
headers = glob([
"Sources/*.h",
]),
exported_headers = glob([
"PublicHeaders/**/*.h",
]),
frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
],
)

View File

@ -0,0 +1,30 @@
objc_library(
name = "NotificationServiceObjC",
enable_modules = True,
module_name = "NotificationServiceObjC",
srcs = glob([
"Sources/**/*.m",
"Sources/**/*.h",
]),
hdrs = glob([
"PublicHeaders/**/*.h",
]),
includes = [
"PublicHeaders",
],
deps = [
"//submodules/BuildConfig:BuildConfig",
"//submodules/MtProtoKit:MtProtoKit",
"//submodules/NotificationsPresentationData:NotificationsPresentationData",
],
sdk_frameworks = [
"Foundation",
],
weak_sdk_frameworks = [
"BackgroundTasks",
],
visibility = [
"//visibility:public",
],
)

View File

@ -1,4 +1,4 @@
#import "NotificationService.h"
#import <NotificationServiceObjC/NotificationServiceObjC.h>
#import <mach/mach.h>
@ -14,8 +14,6 @@
#import "Api.h"
#import "FetchImage.h"
#import "NotificationService-Bridging-Header.h"
static NSData * _Nullable parseBase64(NSString *string) {
string = [string stringByReplacingOccurrencesOfString:@"-" withString:@"+"];
string = [string stringByReplacingOccurrencesOfString:@"_" withString:@"/"];

View File

@ -1,6 +1,7 @@
import Foundation
import UserNotifications
import SwiftSignalKit
import NotificationServiceObjC
private let queue = Queue()

View File

@ -9,6 +9,7 @@ import PeerTable
import PostboxCoding
import AppLockState
import NotificationsPresentationData
import BuildConfig
private let registeredTypes: Void = {
declareEncodable(InAppNotificationSettings.self, f: InAppNotificationSettings.init(decoder:))

View File

@ -54,7 +54,7 @@ private func cleanPhoneNumber(_ text: String) -> String {
return result
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
func matchingDeviceContacts(stableIds: [String]) -> Signal<[MatchingDeviceContact], IntentContactsError> {
guard CNContactStore.authorizationStatus(for: .contacts) == .authorized else {
return .fail(.generic)
@ -128,7 +128,7 @@ func matchingCloudContact(postbox: Postbox, peerId: PeerId) -> Signal<TelegramUs
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
func personWithUser(stableId: String, user: TelegramUser) -> INPerson {
var nameComponents = PersonNameComponents()
nameComponents.givenName = user.firstName

View File

@ -50,7 +50,7 @@ enum IntentHandlingError {
case generic
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
@objc(IntentHandler)
public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessagesIntentHandling, INSetMessageAttributeIntentHandling, INStartAudioCallIntentHandling, INSearchCallHistoryIntentHandling {
private let accountPromise = Promise<Account?>()
@ -68,7 +68,6 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
}
let baseAppBundleId = String(appBundleIdentifier[..<lastDotRange.lowerBound])
let buildConfig = BuildConfig(baseAppBundleId: baseAppBundleId)
let apiId: Int32 = buildConfig.apiId
@ -151,7 +150,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
case noResult
case skip
@available(iOSApplicationExtension 11.0, *)
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
var sendMessageRecipientResulutionResult: INSendMessageRecipientResolutionResult {
switch self {
case let .success(person):
@ -204,7 +203,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
filteredPersons.append(person)
}
if #available(iOSApplicationExtension 10.3, *) {
if #available(iOSApplicationExtension 10.3, iOS 10.3, *) {
if let siriMatches = person.siriMatches {
for match in siriMatches {
if let contactIdentifier = match.contactIdentifier, !contactIdentifier.isEmpty {
@ -237,7 +236,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
if let contactIdentifier = person.contactIdentifier {
return contactIdentifier
}
if #available(iOSApplicationExtension 10.3, *) {
if #available(iOSApplicationExtension 10.3, iOS 10.3, *) {
if let siriMatches = person.siriMatches {
for match in siriMatches {
if let contactIdentifier = match.contactIdentifier, !contactIdentifier.isEmpty {
@ -289,7 +288,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
})
}
@available(iOSApplicationExtension 11.0, *)
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
public func resolveRecipients(for intent: INSendMessageIntent, with completion: @escaping ([INSendMessageRecipientResolutionResult]) -> Void) {
if let appGroupUrl = self.appGroupUrl {
let rootPath = rootPathForBasePath(appGroupUrl.path)
@ -598,7 +597,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
})
}
@available(iOSApplicationExtension 11.0, *)
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
public func resolveDestinationType(for intent: INStartAudioCallIntent, with completion: @escaping (INCallDestinationTypeResolutionResult) -> Void) {
completion(.success(with: .normal))
}
@ -647,7 +646,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
// MARK: - INSearchCallHistoryIntentHandling
@available(iOSApplicationExtension 11.0, *)
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
public func resolveCallTypes(for intent: INSearchCallHistoryIntent, with completion: @escaping (INCallRecordTypeOptionsResolutionResult) -> Void) {
completion(.success(with: .missed))
}
@ -685,7 +684,7 @@ public class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchFo
|> deliverOnMainQueue).start(next: { calls in
let userActivity = NSUserActivity(activityType: NSStringFromClass(INSearchCallHistoryIntent.self))
let response: INSearchCallHistoryIntentResponse
if #available(iOSApplicationExtension 11.0, *) {
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
response = INSearchCallHistoryIntentResponse(code: .success, userActivity: userActivity)
response.callRecords = calls.map { $0.intentCall }
} else {

View File

@ -17,7 +17,7 @@ extension MessageId {
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
func getMessages(account: Account, ids: [MessageId]) -> Signal<[INMessage], NoError> {
return account.postbox.transaction { transaction -> [INMessage] in
var messages: [INMessage] = []
@ -30,7 +30,7 @@ func getMessages(account: Account, ids: [MessageId]) -> Signal<[INMessage], NoEr
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
return account.postbox.tailChatListView(groupId: .root, count: 20, summaryComponents: ChatListEntrySummaryComponents())
|> take(1)
@ -89,7 +89,7 @@ func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
struct CallRecord {
let identifier: String
let date: Date
@ -97,13 +97,13 @@ struct CallRecord {
let duration: Int32?
let unseen: Bool
@available(iOSApplicationExtension 11.0, *)
@available(iOSApplicationExtension 11.0, iOS 11.0, *)
var intentCall: INCallRecord {
return INCallRecord(identifier: self.identifier, dateCreated: self.date, caller: self.caller, callRecordType: .missed, callCapability: .audioCall, callDuration: self.duration.flatMap(Double.init), unseen: self.unseen)
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
func missedCalls(account: Account) -> Signal<[CallRecord], NoError> {
return account.viewTracker.callListView(type: .missed, index: MessageIndex.absoluteUpperBound(), count: 30)
|> take(1)
@ -125,7 +125,7 @@ func missedCalls(account: Account) -> Signal<[CallRecord], NoError> {
}
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
private func callWithTelegramMessage(_ telegramMessage: Message, account: Account) -> CallRecord? {
guard let author = telegramMessage.author, let user = telegramMessage.peers[author.id] as? TelegramUser else {
return nil
@ -133,7 +133,7 @@ private func callWithTelegramMessage(_ telegramMessage: Message, account: Accoun
let identifier = "\(telegramMessage.id.peerId.toInt64())_\(telegramMessage.id.namespace)_\(telegramMessage.id.id)"
let personHandle: INPersonHandle
if #available(iOSApplicationExtension 10.2, *) {
if #available(iOSApplicationExtension 10.2, iOS 10.2, *) {
var type: INPersonHandleType
var label: INPersonHandleLabel?
if let username = user.username {
@ -164,7 +164,7 @@ private func callWithTelegramMessage(_ telegramMessage: Message, account: Accoun
return CallRecord(identifier: identifier, date: date, caller: caller, duration: duration, unseen: true)
}
@available(iOSApplicationExtension 10.0, *)
@available(iOSApplicationExtension 10.0, iOS 10.0, *)
private func messageWithTelegramMessage(_ telegramMessage: Message) -> INMessage? {
guard let author = telegramMessage.author, let user = telegramMessage.peers[author.id] as? TelegramUser, user.id.id != 777000 else {
return nil
@ -172,7 +172,7 @@ private func messageWithTelegramMessage(_ telegramMessage: Message) -> INMessage
let identifier = "\(telegramMessage.id.peerId.toInt64())_\(telegramMessage.id.namespace)_\(telegramMessage.id.id)"
let personHandle: INPersonHandle
if #available(iOSApplicationExtension 10.2, *) {
if #available(iOSApplicationExtension 10.2, iOS 10.2, *) {
var type: INPersonHandleType
var label: INPersonHandleLabel?
if let username = user.username {
@ -195,7 +195,7 @@ private func messageWithTelegramMessage(_ telegramMessage: Message) -> INMessage
let date = Date(timeIntervalSince1970: TimeInterval(telegramMessage.timestamp))
let message: INMessage
if #available(iOSApplicationExtension 11.0, *) {
if #available(iOSApplicationExtension 11.0, iOS 11.0, *) {
var messageType: INMessageType = .text
loop: for media in telegramMessage.media {
if media is TelegramMediaImage {
@ -218,7 +218,7 @@ private func messageWithTelegramMessage(_ telegramMessage: Message) -> INMessage
} else if file.isAnimated {
messageType = .mediaVideo
break loop
} else if #available(iOSApplicationExtension 12.0, *) {
} else if #available(iOSApplicationExtension 12.0, iOS 12.0, *) {
messageType = .file
break loop
}

View File

@ -26,8 +26,11 @@ objc_library(
"-DAPP_SPECIFIC_URL_SCHEME=\\\"{}\\\"".format(telegram_app_specific_url_scheme),
],
hdrs = glob([
"Sources/*.h",
"PublicHeaders/**/*.h",
]),
includes = [
"PublicHeaders",
],
deps = [
],
visibility = ["//visibility:public"],

View File

@ -1,4 +1,4 @@
#import "BuildConfig.h"
#import <BuildConfig/BuildConfig.h>
static NSString *telegramApplicationSecretKey = @"telegramApplicationSecretKey_v3";
API_AVAILABLE(ios(10))

View File

@ -0,0 +1,14 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "Buffers",
module_name = "Buffers",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,18 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "MessageHistoryMetadataTable",
module_name = "MessageHistoryMetadataTable",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/Table:Table",
"//submodules/Database/PostboxDataTypes:PostboxDataTypes",
"//submodules/Database/PostboxCoding:PostboxCoding",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,17 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "MessageHistoryReadStateTable",
module_name = "MessageHistoryReadStateTable",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/Table:Table",
"//submodules/Database/PostboxDataTypes:PostboxDataTypes",
],
visibility = [
"//visibility:public",
],
)

View File

@ -13,6 +13,7 @@ static_library(
"Sources/**/*.h",
]),
deps = [
"submodules/Database/MurmurHash/Impl:MurMurHashObjC",
],
frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework",

View File

@ -0,0 +1,15 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "MurmurHash",
module_name = "MurmurHash",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/MurmurHash/Impl:MurMurHashObjC",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,18 @@
load("//Config:buck_rule_macros.bzl", "static_library")
static_library(
name = "MurMurHashObjC",
srcs = glob([
"Sources/*.m",
]),
headers = glob([
"Sources/*.h",
]),
exported_headers = glob([
"PublicHeaders/**/*.h",
]),
frameworks = [
"$SDKROOT/System/Library/Frameworks/Foundation.framework",
"$SDKROOT/System/Library/Frameworks/UIKit.framework",
],
)

View File

@ -0,0 +1,22 @@
objc_library(
name = "MurMurHashObjC",
enable_modules = True,
module_name = "MurMurHashObjC",
srcs = glob([
"Sources/**/*.m",
"Sources/**/*.h",
]),
hdrs = glob([
"PublicHeaders/**/*.h",
]),
includes = [
"PublicHeaders",
],
sdk_frameworks = [
"Foundation",
],
visibility = [
"//visibility:public",
],
)

View File

@ -1,4 +1,4 @@
#import "MurMurHash32.h"
#import <MurMurHashObjC/MurMurHashObjC.h>
#include <stdlib.h>
#include <string.h>

View File

@ -1,4 +1,5 @@
import Foundation
import MurMurHashObjC
public enum HashFunctions {
public static func murMurHash32(_ s: String) -> Int32 {

View File

@ -0,0 +1,18 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "PeerTable",
module_name = "PeerTable",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/Table:Table",
"//submodules/Database/PostboxCoding:PostboxCoding",
"//submodules/Database/PostboxDataTypes:PostboxDataTypes",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,16 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "PostboxCoding",
module_name = "PostboxCoding",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/Buffers:Buffers",
"//submodules/Database/MurmurHash:MurmurHash",
],
visibility = [
"//visibility:public",
],
)

View File

@ -26,11 +26,11 @@ private let typeStore = { () -> EncodableTypeStore in
public func declareEncodable(_ type: Any.Type, f: @escaping(PostboxDecoder) -> PostboxCoding) {
let string = "\(type)"
let hash = murMurHashString32(string)
let hash = HashFunctions.murMurHash32(string)
if typeStore.dict[hash] != nil {
assertionFailure("Encodable type hash collision for \(type)")
}
typeStore.dict[murMurHashString32("\(type)")] = f
typeStore.dict[HashFunctions.murMurHash32("\(type)")] = f
}
public func declareEncodable(typeHash: Int32, _ f: @escaping(PostboxDecoder) -> PostboxCoding) {
@ -41,7 +41,7 @@ public func declareEncodable(typeHash: Int32, _ f: @escaping(PostboxDecoder) ->
}
public func persistentHash32(_ string: String) -> Int32 {
return murMurHashString32(string)
return HashFunctions.murMurHash32(string)
}
private enum ValueType: Int8 {
@ -172,7 +172,7 @@ public final class PostboxEncoder {
self.buffer.write(&t, offset: 0, length: 1)
let string = "\(type(of: value))"
var typeHash: Int32 = murMurHashString32(string)
var typeHash: Int32 = HashFunctions.murMurHash32(string)
self.buffer.write(&typeHash, offset: 0, length: 4)
let innerEncoder = PostboxEncoder()
@ -189,7 +189,7 @@ public final class PostboxEncoder {
self.buffer.write(&t, offset: 0, length: 1)
let string = "\(type(of: value))"
var typeHash: Int32 = murMurHashString32(string)
var typeHash: Int32 = HashFunctions.murMurHash32(string)
self.buffer.write(&typeHash, offset: 0, length: 4)
let innerEncoder = PostboxEncoder()
@ -232,7 +232,7 @@ public final class PostboxEncoder {
self.buffer.write(&length, offset: 0, length: 4)
let innerEncoder = PostboxEncoder()
for object in value {
var typeHash: Int32 = murMurHashString32("\(type(of: object))")
var typeHash: Int32 = HashFunctions.murMurHash32("\(type(of: object))")
self.buffer.write(&typeHash, offset: 0, length: 4)
innerEncoder.reset()
@ -252,7 +252,7 @@ public final class PostboxEncoder {
self.buffer.write(&length, offset: 0, length: 4)
let innerEncoder = PostboxEncoder()
for object in value {
var typeHash: Int32 = murMurHashString32("\(type(of: object))")
var typeHash: Int32 = HashFunctions.murMurHash32("\(type(of: object))")
self.buffer.write(&typeHash, offset: 0, length: 4)
innerEncoder.reset()
@ -272,7 +272,7 @@ public final class PostboxEncoder {
self.buffer.write(&length, offset: 0, length: 4)
let innerEncoder = PostboxEncoder()
for object in value {
var typeHash: Int32 = murMurHashString32("\(type(of: object))")
var typeHash: Int32 = HashFunctions.murMurHash32("\(type(of: object))")
self.buffer.write(&typeHash, offset: 0, length: 4)
innerEncoder.reset()
@ -322,7 +322,7 @@ public final class PostboxEncoder {
let innerEncoder = PostboxEncoder()
for record in value {
var keyTypeHash: Int32 = murMurHashString32("\(type(of: record.0))")
var keyTypeHash: Int32 = HashFunctions.murMurHash32("\(type(of: record.0))")
self.buffer.write(&keyTypeHash, offset: 0, length: 4)
innerEncoder.reset()
record.0.encode(innerEncoder)
@ -330,7 +330,7 @@ public final class PostboxEncoder {
self.buffer.write(&keyLength, offset: 0, length: 4)
self.buffer.write(innerEncoder.buffer.memory, offset: 0, length: Int(keyLength))
var valueTypeHash: Int32 = murMurHashString32("\(type(of: record.1))")
var valueTypeHash: Int32 = HashFunctions.murMurHash32("\(type(of: record.1))")
self.buffer.write(&valueTypeHash, offset: 0, length: 4)
innerEncoder.reset()
record.1.encode(innerEncoder)
@ -349,7 +349,7 @@ public final class PostboxEncoder {
let innerEncoder = PostboxEncoder()
for record in value {
var keyTypeHash: Int32 = murMurHashString32("\(type(of: record.0))")
var keyTypeHash: Int32 = HashFunctions.murMurHash32("\(type(of: record.0))")
self.buffer.write(&keyTypeHash, offset: 0, length: 4)
innerEncoder.reset()
keyEncoder(record.0, innerEncoder)
@ -357,7 +357,7 @@ public final class PostboxEncoder {
self.buffer.write(&keyLength, offset: 0, length: 4)
self.buffer.write(innerEncoder.buffer.memory, offset: 0, length: Int(keyLength))
var valueTypeHash: Int32 = murMurHashString32("\(type(of: record.1))")
var valueTypeHash: Int32 = HashFunctions.murMurHash32("\(type(of: record.1))")
self.buffer.write(&valueTypeHash, offset: 0, length: 4)
innerEncoder.reset()
record.1.encode(innerEncoder)

View File

@ -0,0 +1,16 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "PostboxDataTypes",
module_name = "PostboxDataTypes",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/PostboxCoding:PostboxCoding",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,18 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "PreferencesTable",
module_name = "PreferencesTable",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
"//submodules/Database/Table:Table",
"//submodules/Database/PostboxCoding:PostboxCoding",
"//submodules/Database/PostboxDataTypes:PostboxDataTypes",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,15 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "Table",
module_name = "Table",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/Database/ValueBox:ValueBox",
],
visibility = [
"//visibility:public",
],
)

View File

@ -0,0 +1,17 @@
load("@build_bazel_rules_swift//swift:swift.bzl", "swift_library")
swift_library(
name = "ValueBox",
module_name = "ValueBox",
srcs = glob([
"Sources/**/*.swift",
]),
deps = [
"//submodules/SSignalKit/SwiftSignalKit:SwiftSignalKit",
"//submodules/sqlcipher:sqlcipher",
"//submodules/Database/Buffers:Buffers",
],
visibility = [
"//visibility:public",
],
)