This commit is contained in:
Isaac 2026-03-13 09:00:55 +01:00
parent 33d598cbe7
commit 3d3232eedc
13 changed files with 205 additions and 113 deletions

View file

@ -22,14 +22,36 @@ build --strategy=SwiftCompile=worker
#common --registry=https://raw.githubusercontent.com/bazelbuild/bazel-central-registry/main/
# SourceKit BSP: Swift indexing features
common --features=swift.index_while_building
common --features=swift.use_global_index_store
common --features=swift.use_global_module_cache
common --features=oso_prefix_is_pwd
# rules_swift flags migration
# --swiftcopt and --host_swiftcopt are deprecated
common --flag_alias=swiftcopt=@build_bazel_rules_swift//swift:copt
common --flag_alias=host_swiftcopt=@build_bazel_rules_swift//swift:exec_copt
#common --swiftcopt=-whole-module-optimization
#common --host_swiftcopt=-whole-module-optimization
# SourceKit BSP: Index build config (used for background indexing)
common --check_visibility=false
# All of the following are Debug/Index setup configs inspired by the default rules_xcodeproj template
common --verbose_failures
common --cache_computed_file_digests=500000
common --action_cache_store_output_metadata
common --experimental_use_cpp_compile_action_args_params_file
common --define=apple.experimental.tree_artifact_outputs=1
common --features=apple.swizzle_absolute_xcttestsourcelocation
common --features=oso_prefix_is_pwd
common --features=relative_ast_path
common --features=swift.cacheable_swiftmodules
common --features=swift.index_while_building
common --features=swift.use_global_module_cache
common --features=swift.emit_swiftsourceinfo
common --nolegacy_important_outputs
build --noworker_sandboxing
build --spawn_strategy=remote,worker,local
# Only for BSP builds
common:index_build --experimental_convenience_symlinks=ignore
common:index_build --bes_backend= --bes_results_url=
common:index_build --show_result=0
common:index_build --noshow_loading_progress
common:index_build --noshow_progress
@ -37,3 +59,4 @@ common:index_build --noannounce_rc
common:index_build --noshow_timestamps
common:index_build --curses=no
common:index_build --color=no

View file

@ -23,5 +23,7 @@
]
}
},
"swift.sourcekit-lsp.serverPath": "${workspaceFolder}/build-input/sourcekit-lsp"
"swift.sourcekit-lsp.serverPath": "${workspaceFolder}/build-input/sourcekit-lsp",
"sourcekit-bazel-bsp.rulesAppleName": "build_bazel_rules_apple",
"cmake.sourceDirectory": "/Users/ali/build/telegram/telegram-ios/submodules/rlottie/rlottie/test"
}

View file

@ -1,5 +1,7 @@
load("@sourcekit_bazel_bsp//rules:setup_sourcekit_bsp.bzl", "setup_sourcekit_bsp")
exports_files(["versions.json"])
setup_sourcekit_bsp(
name = "setup_sourcekit_bsp",
bazel_wrapper = "./build-input/bazel-8.4.2-darwin-arm64",
@ -18,17 +20,12 @@ setup_sourcekit_bsp(
"submodules/**/*.cpp",
],
aquery_flags = [
"define=telegramVersion=12.5",
"define=buildNumber=100000",
],
index_flags = [
"config=index_build",
"define=telegramVersion=12.5",
"define=buildNumber=100000",
],
index_build_batch_size = 10,
targets = [
"//Telegram:Telegram",
],
merge_lsp_config = False,
)

View file

@ -385,7 +385,8 @@ plist_fragment(
"""
<key>CFBundleVersion</key>
<string>{buildNumber}</string>
"""
""",
defaults = {"buildNumber": "1"},
)
plist_fragment(
@ -574,14 +575,23 @@ plist_fragment(
])
)
plist_fragment(
genrule(
name = "VersionInfoPlist",
extension = "plist",
template =
"""
srcs = ["//:versions.json"],
outs = ["VersionInfoPlist.plist"],
cmd = """
version=$$(python3 -c "import json; print(json.load(open('$(location //:versions.json)'))['app'])")
cat > $@ <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>{telegramVersion}</string>
"""
<string>$$version</string>
</dict>
</plist>
PLIST
""",
)
plist_fragment(

View file

@ -43,14 +43,23 @@ plist_fragment(
"""
)
plist_fragment(
genrule(
name = "VersionInfoPlist",
extension = "plist",
template =
"""
srcs = ["//:versions.json"],
outs = ["VersionInfoPlist.plist"],
cmd = """
version=$$(python3 -c "import json; print(json.load(open('$(location //:versions.json)'))['app'])")
cat > $@ <<PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleShortVersionString</key>
<string>{telegramVersion}</string>
"""
<string>$$version</string>
</dict>
</plist>
PLIST
""",
)
plist_fragment(

View file

@ -212,7 +212,6 @@ class BazelCommandLine:
def get_define_arguments(self):
return [
'--define=buildNumber={}'.format(self.build_number),
'--define=telegramVersion={}'.format(self.build_environment.app_version)
]
def get_project_generation_arguments(self):

@ -1 +1 @@
Subproject commit 39cc2529241335d20afcb6700c587d064e7a2870
Subproject commit f6aef7db5b649ffc3b7497ecc83a08ad3ab19559

View file

@ -18,6 +18,8 @@ def _plist_fragment(ctx):
resolved_values = dict()
for key in found_keys:
value = ctx.var.get(key, None)
if value == None:
value = ctx.attr.defaults.get(key, None)
if value == None:
fail("Expected value for --define={} was not found".format(key))
resolved_values[key] = value
@ -38,6 +40,7 @@ plist_fragment = rule(
attrs = {
"extension": attr.string(mandatory = True),
"template": attr.string(mandatory = True),
"defaults": attr.string_dict(),
},
outputs = {
"out": "%{name}.%{extension}"

View file

@ -10,12 +10,9 @@ WORKSPACE_ROOT=$(pwd)
BAZEL_CMD="./build-input/bazel-8.4.2-darwin-arm64"
export ADDITIONAL_FLAGS=()
TELEGRAM_VERSION=$(python3 -c "import json; print(json.load(open('${WORKSPACE_ROOT}/versions.json'))['app'])")
ADDITIONAL_FLAGS+=("--keep_going")
ADDITIONAL_FLAGS+=("--color=yes")
ADDITIONAL_FLAGS+=("--define=telegramVersion=${TELEGRAM_VERSION}")
ADDITIONAL_FLAGS+=("--define=buildNumber=100000")
if [ -n "${BAZEL_EXTRA_BUILD_FLAGS:-}" ]; then
ADDITIONAL_FLAGS+=("${BAZEL_EXTRA_BUILD_FLAGS[@]}")

View file

@ -551,10 +551,16 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
}
}
let networkArguments = NetworkInitializationArguments(apiId: apiId, apiHash: apiHash, languagesCategory: languagesCategory, appVersion: appVersion, voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer, voipVersions: PresentationCallManagerImpl.voipVersions(includeExperimental: true, includeReference: false).map { version, supportsVideo -> CallSessionManagerImplementationVersion in
let networkArguments = NetworkInitializationArguments(
apiId: apiId,
apiHash: apiHash,
languagesCategory: languagesCategory,
appVersion: appVersion,
voipMaxLayer: PresentationCallManagerImpl.voipMaxLayer,
voipVersions: PresentationCallManagerImpl.voipVersions(includeExperimental: true, includeReference: false).map { version, supportsVideo -> CallSessionManagerImplementationVersion in
CallSessionManagerImplementationVersion(version: version, supportsVideo: supportsVideo)
}, appData: self.regularDeviceToken.get()
|> map { token in
},
appData: self.regularDeviceToken.get() |> map { token in
let tokenEnvironment: String
#if DEBUG
tokenEnvironment = "sandbox"
@ -568,8 +574,10 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
Logger.shared.log("data", "can't deserialize")
}
return data
}, externalRequestVerificationStream: self.firebaseRequestVerificationSecretStream.get(), externalRecaptchaRequestVerification: { method, siteKey in
return Signal { subscriber in
},
externalRequestVerificationStream: self.firebaseRequestVerificationSecretStream.get(),
externalRecaptchaRequestVerification: { method, siteKey in
return Signal<String?, NoError> { subscriber in
let recaptchaClient: Promise<RecaptchaClient>
if let current = self.recaptchaClientsBySiteKey[siteKey] {
recaptchaClient = current
@ -624,7 +632,13 @@ private func extractAccountManagerState(records: AccountRecordsView<TelegramAcco
}).startStandalone(next: subscriber.putNext, error: subscriber.putError, completed: subscriber.putCompletion)
}
|> runOn(Queue.mainQueue())
}, autolockDeadine: autolockDeadine, encryptionProvider: OpenSSLEncryptionProvider(), deviceModelName: nil, useBetaFeatures: !buildConfig.isAppStoreBuild, isICloudEnabled: buildConfig.isICloudEnabled)
},
autolockDeadine: autolockDeadine,
encryptionProvider: OpenSSLEncryptionProvider(),
deviceModelName: nil,
useBetaFeatures: !buildConfig.isAppStoreBuild,
isICloudEnabled: buildConfig.isICloudEnabled
)
guard let appGroupUrl = maybeAppGroupUrl else {
self.mainWindow?.presentNative(UIAlertController(title: nil, message: "Error 2", preferredStyle: .alert))

View file

@ -433,6 +433,12 @@ func chatHistoryEntriesForView(
var i = 0
let unreadEntry: ChatHistoryEntry = .UnreadEntry(maxReadIndex, presentationData)
for entry in entries {
if case let .MessageGroupEntry(_, messages, _) = entry {
if !messages.isEmpty && maxReadIndex >= messages[0].0.index {
i += 1
continue
}
}
if entry > unreadEntry {
if i != 0 {
entries.insert(unreadEntry, at: i)

View file

@ -65,7 +65,7 @@ func chatHistoryViewForLocation(
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
if view.isLoading {
if view.isLoading || (view.entries.isEmpty && (view.holeEarlier || view.holeLater)) {
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
}
@ -147,7 +147,7 @@ func chatHistoryViewForLocation(
if preloaded {
return .HistoryView(view: view, type: .Generic(type: updateType), scrollPosition: nil, flashIndicators: false, originalScrollPosition: nil, initialData: combinedInitialData, id: location.id)
} else {
if view.isLoading {
if view.isLoading || (view.entries.isEmpty && (view.holeEarlier || view.holeLater)) {
return .Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
}
var scrollPosition: ChatHistoryViewScrollPosition?
@ -311,7 +311,7 @@ func chatHistoryViewForLocation(
let combinedInitialData = ChatHistoryCombinedInitialData(initialData: initialData, buttonKeyboardMessage: view.topTaggedMessages.first, cachedData: cachedData, cachedDataMessages: cachedDataMessages, readStateData: readStateData)
if view.isLoading {
if view.isLoading || (view.entries.isEmpty && (view.holeEarlier || view.holeLater)) {
return ChatHistoryViewUpdate.Loading(initialData: combinedInitialData, type: .Generic(type: updateType))
}
@ -461,7 +461,7 @@ func fetchAndPreloadReplyThreadInfo(context: AccountContext, subject: ReplyThrea
case .Loading:
return nil
case let .HistoryView(view, _, _, _, _, _, _):
if view.isLoading {
if view.isLoading || (view.entries.isEmpty && (view.holeEarlier || view.holeLater)) {
return nil
}
return view.entries.isEmpty

View file

@ -50,6 +50,8 @@ private struct AccountTasks {
}
}
private let backgroundTaskSubmissionDelay: Double = 10.0
private struct PendingMediaUploadKey: Hashable {
let accountId: AccountRecordId
let messageId: MessageId
@ -99,6 +101,7 @@ public final class SharedWakeupManager {
private var backgroundProcessingTaskId: String?
private var backgroundProcessingTaskLaunched: Bool = false
private var backgroundProcessingTaskCancellationRequestedByApp: Bool = false
private var pendingBackgroundProcessingTaskTimer: SwiftSignalKit.Timer?
private var pendingStoryUploadsByKey: [PendingStoryUploadKey: Float] = [:]
private var pendingStoryUploadStatusesByKey: [PendingStoryUploadKey: PendingStoryUploadStatus] = [:]
@ -107,6 +110,7 @@ public final class SharedWakeupManager {
private var backgroundStoryProcessingTaskId: String?
private var backgroundStoryProcessingTaskLaunched: Bool = false
private var backgroundStoryProcessingTaskCancellationRequestedByApp: Bool = false
private var pendingBackgroundStoryProcessingTaskTimer: SwiftSignalKit.Timer?
public init(beginBackgroundTask: @escaping (String, @escaping () -> Void) -> UIBackgroundTaskIdentifier?, endBackgroundTask: @escaping (UIBackgroundTaskIdentifier) -> Void, backgroundTimeRemaining: @escaping () -> Double, acquireIdleExtension: @escaping () -> Disposable?, activeAccounts: Signal<(primary: Account?, accounts: [(AccountRecordId, Account)]), NoError>, liveLocationPolling: Signal<AccountRecordId?, NoError>, watchTasks: Signal<AccountRecordId?, NoError>, inForeground: Signal<Bool, NoError>, hasActiveAudioSession: Signal<Bool, NoError>, notificationManager: SharedNotificationManager?, mediaManager: MediaManager, callManager: PresentationCallManager?, accountUserInterfaceInUse: @escaping (AccountRecordId) -> Signal<Bool, NoError>, presentationData: @escaping () -> PresentationData?) {
assert(Queue.mainQueue().isCurrent())
@ -155,6 +159,10 @@ public final class SharedWakeupManager {
}
strongSelf.allowBackgroundTimeExtensionDeadlineTimer?.invalidate()
strongSelf.allowBackgroundTimeExtensionDeadlineTimer = nil
strongSelf.pendingBackgroundProcessingTaskTimer?.invalidate()
strongSelf.pendingBackgroundProcessingTaskTimer = nil
strongSelf.pendingBackgroundStoryProcessingTaskTimer?.invalidate()
strongSelf.pendingBackgroundStoryProcessingTaskTimer = nil
}
strongSelf.updateBackgroundProcessingTaskStateFromPendingMediaUploads()
strongSelf.updateBackgroundProcessingTaskStateFromPendingStoryUploads()
@ -356,6 +364,8 @@ public final class SharedWakeupManager {
self.pendingStoryUploadsDisposable?.dispose()
self.managedPausedInBackgroundPlayer?.dispose()
self.keepIdleDisposable?.dispose()
self.pendingBackgroundProcessingTaskTimer?.invalidate()
self.pendingBackgroundStoryProcessingTaskTimer?.invalidate()
if let (taskId, _, timer) = self.currentTask {
timer.invalidate()
self.endBackgroundTask(taskId)
@ -371,10 +381,21 @@ public final class SharedWakeupManager {
let hadTask = self.backgroundProcessingTaskId != nil
if shouldHaveTask {
if !hadTask {
if !hadTask && self.pendingBackgroundProcessingTaskTimer == nil {
let timer = SwiftSignalKit.Timer(timeout: backgroundTaskSubmissionDelay, repeat: false, completion: { [weak self] in
guard let self else {
return
}
self.pendingBackgroundProcessingTaskTimer = nil
self.startBackgroundProcessingTaskIfNeeded()
}, queue: .mainQueue())
self.pendingBackgroundProcessingTaskTimer = timer
timer.start()
}
} else {
self.pendingBackgroundProcessingTaskTimer?.invalidate()
self.pendingBackgroundProcessingTaskTimer = nil
if let backgroundProcessingTaskId = self.backgroundProcessingTaskId {
if !self.backgroundProcessingTaskCancellationRequestedByApp {
self.backgroundProcessingTaskCancellationRequestedByApp = true
@ -401,10 +422,21 @@ public final class SharedWakeupManager {
let hadTask = self.backgroundStoryProcessingTaskId != nil
if shouldHaveTask {
if !hadTask {
if !hadTask && self.pendingBackgroundStoryProcessingTaskTimer == nil {
let timer = SwiftSignalKit.Timer(timeout: backgroundTaskSubmissionDelay, repeat: false, completion: { [weak self] in
guard let self else {
return
}
self.pendingBackgroundStoryProcessingTaskTimer = nil
self.startBackgroundStoryProcessingTaskIfNeeded()
}, queue: .mainQueue())
self.pendingBackgroundStoryProcessingTaskTimer = timer
timer.start()
}
} else {
self.pendingBackgroundStoryProcessingTaskTimer?.invalidate()
self.pendingBackgroundStoryProcessingTaskTimer = nil
if let backgroundStoryProcessingTaskId = self.backgroundStoryProcessingTaskId {
if !self.backgroundStoryProcessingTaskCancellationRequestedByApp {
self.backgroundStoryProcessingTaskCancellationRequestedByApp = true