Skip to content

Commit 8c54db6

Browse files
author
Isaac
committed
Experiment
1 parent facd51e commit 8c54db6

23 files changed

Lines changed: 3901 additions & 125 deletions

File tree

Telegram/NotificationService/Sources/NotificationService.swift

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1978,13 +1978,18 @@ private final class NotificationServiceHandler {
19781978
if let media = message.media.first {
19791979
parsedMedia = media
19801980
}
1981-
if enableInlineEmoji, let textEntitiesAttribute = message.textEntitiesAttribute {
1982-
content.body = message.text
1981+
if enableInlineEmoji, let textEntitiesAttribute = message.textEntitiesAttribute, let author = message.author {
1982+
let authorTitle = author.debugDisplayTitle
1983+
let messagePrefix = "\(authorTitle): "
1984+
let messagePrefixLength = (messagePrefix as NSString).length
19831985
for entity in textEntitiesAttribute.entities {
19841986
if case let .CustomEmoji(_, fileId) = entity.type {
1985-
content.customEmoji.append(NotificationContent.CustomEmoji(range: entity.range, fileId: fileId))
1987+
content.customEmoji.append(NotificationContent.CustomEmoji(range: (entity.range.lowerBound + messagePrefixLength) ..< (entity.range.upperBound + messagePrefixLength), fileId: fileId))
19861988
}
19871989
}
1990+
if !content.customEmoji.isEmpty {
1991+
content.body = messagePrefix + message.text
1992+
}
19881993
}
19891994
}
19901995

submodules/DebugSettingsUI/Sources/DebugController.swift

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
109109
case playerV2(Bool)
110110
case devRequests(Bool)
111111
case enableUpdates(Bool)
112-
case fakeAds(Bool)
112+
case pwa(Bool)
113113
case enableLocalTranslation(Bool)
114114
case preferredVideoCodec(Int, String, String?, Bool)
115115
case disableVideoAspectScaling(Bool)
@@ -135,7 +135,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
135135
return DebugControllerSection.web.rawValue
136136
case .keepChatNavigationStack, .skipReadHistory, .alwaysDisplayTyping, .debugRatingLayout, .crashOnSlowQueries, .crashOnMemoryPressure:
137137
return DebugControllerSection.experiments.rawValue
138-
case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .compressedEmojiCache, .storiesJpegExperiment, .checkSerializedData, .enableQuickReactionSwitch, .experimentalCompatibility, .enableDebugDataDisplay, .fakeGlass, .browserExperiment, .allForumsHaveTabs, .enableReactionOverrides, .restorePurchases, .disableReloginTokens, .liveStreamV2, .experimentalCallMute, .playerV2, .devRequests, .enableUpdates, .fakeAds, .enableLocalTranslation:
138+
case .clearTips, .resetNotifications, .crash, .fillLocalSavedMessageCache, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .resetTagHoles, .reindexUnread, .resetCacheIndex, .reindexCache, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .compressedEmojiCache, .storiesJpegExperiment, .checkSerializedData, .enableQuickReactionSwitch, .experimentalCompatibility, .enableDebugDataDisplay, .fakeGlass, .browserExperiment, .allForumsHaveTabs, .enableReactionOverrides, .restorePurchases, .disableReloginTokens, .liveStreamV2, .experimentalCallMute, .playerV2, .devRequests, .enableUpdates, .pwa, .enableLocalTranslation:
139139
return DebugControllerSection.experiments.rawValue
140140
case .logTranslationRecognition, .resetTranslationStates:
141141
return DebugControllerSection.translation.rawValue
@@ -258,7 +258,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
258258
return 54
259259
case .devRequests:
260260
return 55
261-
case .fakeAds:
261+
case .pwa:
262262
return 56
263263
case .enableLocalTranslation:
264264
return 57
@@ -1392,12 +1392,12 @@ private enum DebugControllerEntry: ItemListNodeEntry {
13921392
})
13931393
}).start()
13941394
})
1395-
case let .fakeAds(value):
1396-
return ItemListSwitchItem(presentationData: presentationData, systemStyle: .glass, title: "Fake Ads", value: value, sectionId: self.section, style: .blocks, updated: { value in
1395+
case let .pwa(value):
1396+
return ItemListSwitchItem(presentationData: presentationData, systemStyle: .glass, title: "Test1", value: value, sectionId: self.section, style: .blocks, updated: { value in
13971397
let _ = arguments.sharedContext.accountManager.transaction ({ transaction in
13981398
transaction.updateSharedData(ApplicationSpecificSharedDataKeys.experimentalUISettings, { settings in
13991399
var settings = settings?.get(ExperimentalUISettings.self) ?? ExperimentalUISettings.defaultSettings
1400-
settings.fakeAds = value
1400+
settings.enablePWA = value
14011401
return PreferencesEntry(settings)
14021402
})
14031403
}).start()
@@ -1488,7 +1488,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
14881488
}
14891489
}
14901490

1491-
private func debugControllerEntries(sharedContext: SharedAccountContext, presentationData: PresentationData, loggingSettings: LoggingSettings, mediaInputSettings: MediaInputSettings, experimentalSettings: ExperimentalUISettings, networkSettings: NetworkSettings?, hasLegacyAppData: Bool, useBetaFeatures: Bool) -> [DebugControllerEntry] {
1491+
private func debugControllerEntries(context: AccountContext?, sharedContext: SharedAccountContext, presentationData: PresentationData, loggingSettings: LoggingSettings, mediaInputSettings: MediaInputSettings, experimentalSettings: ExperimentalUISettings, networkSettings: NetworkSettings?, hasLegacyAppData: Bool, useBetaFeatures: Bool) -> [DebugControllerEntry] {
14921492
var entries: [DebugControllerEntry] = []
14931493

14941494
let isMainApp = sharedContext.applicationBindings.isMainApp
@@ -1572,7 +1572,18 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
15721572
entries.append(.playerV2(experimentalSettings.playerV2))
15731573

15741574
entries.append(.devRequests(experimentalSettings.devRequests))
1575-
entries.append(.fakeAds(experimentalSettings.fakeAds))
1575+
1576+
if let data = context?.currentAppConfiguration.with({ $0 }).data {
1577+
var displayPwa = false
1578+
if let _ = data["ios_display_pwa"] {
1579+
displayPwa = true
1580+
} else if let isDev = data["dev"] as? Double, isDev == 1.0 {
1581+
displayPwa = true
1582+
}
1583+
if displayPwa {
1584+
entries.append(.pwa(experimentalSettings.enablePWA))
1585+
}
1586+
}
15761587
entries.append(.enableLocalTranslation(experimentalSettings.enableLocalTranslation))
15771588
entries.append(.enableUpdates(experimentalSettings.enableUpdates))
15781589
}
@@ -1658,7 +1669,7 @@ public func debugController(sharedContext: SharedAccountContext, context: Accoun
16581669
}
16591670

16601671
let controllerState = ItemListControllerState(presentationData: ItemListPresentationData(presentationData), title: .text("Debug"), leftNavigationButton: leftNavigationButton, rightNavigationButton: nil, backNavigationButton: ItemListBackButton(title: presentationData.strings.Common_Back))
1661-
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: debugControllerEntries(sharedContext: sharedContext, presentationData: presentationData, loggingSettings: loggingSettings, mediaInputSettings: mediaInputSettings, experimentalSettings: experimentalSettings, networkSettings: networkSettings, hasLegacyAppData: hasLegacyAppData, useBetaFeatures: useBetaFeatures), style: .blocks)
1672+
let listState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: debugControllerEntries(context: context, sharedContext: sharedContext, presentationData: presentationData, loggingSettings: loggingSettings, mediaInputSettings: mediaInputSettings, experimentalSettings: experimentalSettings, networkSettings: networkSettings, hasLegacyAppData: hasLegacyAppData, useBetaFeatures: useBetaFeatures), style: .blocks)
16621673

16631674
return (controllerState, (listState, arguments))
16641675
}

submodules/TelegramCore/Sources/Network/FetchedMediaResource.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -729,7 +729,7 @@ final class MediaReferenceRevalidationContext {
729729

730730
func attachBot(accountPeerId: PeerId, postbox: Postbox, network: Network, background: Bool, peer: PeerReference) -> Signal<AttachMenuBot, RevalidateMediaReferenceError> {
731731
return self.genericItem(key: .attachBot(peer: peer), background: background, request: { next, error in
732-
return (_internal_getAttachMenuBot(accountPeerId: accountPeerId, postbox: postbox, network: network, botId: peer.id, cached: false)
732+
return (_internal_getAttachMenuBot(accountPeerId: accountPeerId, postbox: postbox, network: network, botId: peer.id, cached: false, allowManuallyCached: false)
733733
|> mapError { _ -> RevalidateMediaReferenceError in
734734
return .generic
735735
}).start(next: { value in

submodules/TelegramCore/Sources/SyncCore/SyncCore_Namespaces.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ public struct Namespaces {
149149
public static let cachedChatThemes: Int8 = 50
150150
public static let cachedLiveStorySendAsPeers: Int8 = 51
151151
public static let cachedGiftUpgradesAttributes: Int8 = 52
152+
public static let manuallyCachedAttachMenuBots: Int8 = 53
153+
public static let cachedBotWebViews: Int8 = 54
152154
}
153155

154156
public struct UnorderedItemList {

submodules/TelegramCore/Sources/TelegramEngine/Messages/AttachMenuBots.swift

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,51 @@ private func removeCachedAttachMenuBot(postbox: Postbox, botId: PeerId) -> Signa
283283
}
284284
}
285285

286+
enum CachedAttachMenuBotResult {
287+
case empty
288+
case bot(AttachMenuBots.Bot)
289+
}
290+
291+
private func manuallyCachedAttachMenuBot(transaction: Transaction, peerId: PeerId) -> CachedAttachMenuBotResult? {
292+
let key = ValueBoxKey(length: 8)
293+
key.setInt64(0, value: peerId.toInt64())
294+
295+
if let entry = transaction.retrieveItemCacheEntry(id: ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.manuallyCachedAttachMenuBots, key: key)) {
296+
let cached = entry.get(AttachMenuBots.Bot.self)
297+
if let cached {
298+
return .bot(cached)
299+
} else if let _ = entry.get(EmptyAttachMenuBotMarker.self) {
300+
return .empty
301+
} else {
302+
return nil
303+
}
304+
} else {
305+
return nil
306+
}
307+
}
308+
309+
struct EmptyAttachMenuBotMarker: Codable {
310+
var trueValue: Bool
311+
}
312+
313+
private func setManuallyCachedAttachMenuBot(transaction: Transaction, peerId: PeerId, bot: AttachMenuBots.Bot?) {
314+
let key = ValueBoxKey(length: 8)
315+
key.setInt64(0, value: peerId.toInt64())
316+
317+
let entryId = ItemCacheEntryId(collectionId: Namespaces.CachedItemCollection.manuallyCachedAttachMenuBots, key: key)
318+
if let bot {
319+
if let entry = CodableEntry(bot) {
320+
transaction.putItemCacheEntry(id: entryId, entry: entry)
321+
} else {
322+
transaction.removeItemCacheEntry(id: entryId)
323+
}
324+
} else {
325+
if let entry = CodableEntry(EmptyAttachMenuBotMarker(trueValue: true)) {
326+
transaction.putItemCacheEntry(id: entryId, entry: entry)
327+
}
328+
}
329+
}
330+
286331
func managedSynchronizeAttachMenuBots(accountPeerId: PeerId, postbox: Postbox, network: Network, force: Bool = false) -> Signal<Void, NoError> {
287332
let poll = Signal<Void, NoError> { subscriber in
288333
let signal: Signal<Void, NoError> = cachedAttachMenuBots(postbox: postbox)
@@ -509,19 +554,33 @@ public enum GetAttachMenuBotError {
509554
case generic
510555
}
511556

512-
func _internal_getAttachMenuBot(accountPeerId: PeerId, postbox: Postbox, network: Network, botId: PeerId, cached: Bool) -> Signal<AttachMenuBot, GetAttachMenuBotError> {
557+
func _internal_getAttachMenuBot(accountPeerId: PeerId, postbox: Postbox, network: Network, botId: PeerId, cached: Bool, allowManuallyCached: Bool) -> Signal<AttachMenuBot, GetAttachMenuBotError> {
513558
return postbox.transaction { transaction -> Signal<AttachMenuBot, GetAttachMenuBotError> in
514559
if cached, let cachedBots = cachedAttachMenuBots(transaction: transaction)?.bots {
515560
if let bot = cachedBots.first(where: { $0.peerId == botId }), let peer = transaction.getPeer(bot.peerId) {
516561
return .single(AttachMenuBot(peer: EnginePeer(peer), shortName: bot.name, icons: bot.icons, peerTypes: bot.peerTypes, flags: bot.flags))
517562
}
518563
}
564+
if allowManuallyCached, let bot = manuallyCachedAttachMenuBot(transaction: transaction, peerId: botId) {
565+
switch bot {
566+
case let .bot(bot):
567+
if let peer = transaction.getPeer(bot.peerId) {
568+
return .single(AttachMenuBot(peer: EnginePeer(peer), shortName: bot.name, icons: bot.icons, peerTypes: bot.peerTypes, flags: bot.flags))
569+
}
570+
case .empty:
571+
return .fail(.generic)
572+
}
573+
}
519574

520575
guard let peer = transaction.getPeer(botId), let inputUser = apiInputUser(peer) else {
521576
return .complete()
522577
}
523578
return network.request(Api.functions.messages.getAttachMenuBot(bot: inputUser))
524579
|> mapError { _ -> GetAttachMenuBotError in
580+
let _ = postbox.transaction({ transaction -> Void in
581+
setManuallyCachedAttachMenuBot(transaction: transaction, peerId: peer.id, bot: nil)
582+
}).startStandalone()
583+
525584
return .generic
526585
}
527586
|> mapToSignal { result -> Signal<AttachMenuBot, GetAttachMenuBotError> in
@@ -586,6 +645,15 @@ func _internal_getAttachMenuBot(accountPeerId: PeerId, postbox: Postbox, network
586645
if (apiFlags & (1 << 5)) != 0 {
587646
flags.insert(.showInSettingsDisclaimer)
588647
}
648+
649+
setManuallyCachedAttachMenuBot(transaction: transaction, peerId: peer.id, bot: AttachMenuBots.Bot(
650+
peerId: peer.id,
651+
name: name,
652+
icons: icons,
653+
peerTypes: peerTypes,
654+
flags: flags
655+
))
656+
589657
return .single(AttachMenuBot(peer: EnginePeer(peer), shortName: name, icons: icons, peerTypes: peerTypes, flags: flags))
590658
}
591659
}

0 commit comments

Comments
 (0)