Skip to content

Commit dded7c4

Browse files
committed
Cloud animated emojis
1 parent 78f08d4 commit dded7c4

18 files changed

Lines changed: 188 additions & 136 deletions

‎submodules/TelegramCore/TelegramCore/Account.swift‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1303,8 +1303,8 @@ public class Account {
13031303
self.managedOperationsDisposable.add(managedLocalizationUpdatesOperations(accountManager: accountManager, postbox: self.postbox, network: self.network).start())
13041304
self.managedOperationsDisposable.add(managedPendingPeerNotificationSettings(postbox: self.postbox, network: self.network).start())
13051305
self.managedOperationsDisposable.add(managedSynchronizeAppLogEventsOperations(postbox: self.postbox, network: self.network).start())
1306-
13071306
self.managedOperationsDisposable.add(managedNotificationSettingsBehaviors(postbox: self.postbox).start())
1307+
self.managedOperationsDisposable.add(managedAnimatedEmojiUpdates(postbox: self.postbox, network: self.network).start())
13081308

13091309
let mediaBox = postbox.mediaBox
13101310
self.storageSettingsDisposable = accountManager.sharedData(keys: [SharedDataKeys.cacheStorageSettings]).start(next: { [weak mediaBox] sharedData in
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import Foundation
2+
#if os(macOS)
3+
import PostboxMac
4+
import SwiftSignalKitMac
5+
import MtProtoKitMac
6+
import TelegramApiMac
7+
#else
8+
import Postbox
9+
import SwiftSignalKit
10+
import TelegramApi
11+
#if BUCK
12+
import MtProtoKit
13+
#else
14+
import MtProtoKitDynamic
15+
#endif
16+
#endif
17+
18+
func managedAnimatedEmojiUpdates(postbox: Postbox, network: Network) -> Signal<Void, NoError> {
19+
let poll = loadedStickerPack(postbox: postbox, network: network, reference: .animatedEmoji, forceActualized: false)
20+
|> mapToSignal { _ -> Signal<Void, NoError> in
21+
return .complete()
22+
}
23+
return (poll |> then(.complete() |> suspendAwareDelay(2.0 * 60.0 * 60.0, queue: Queue.concurrentDefaultQueue()))) |> restart
24+
}

‎submodules/TelegramCore/TelegramCore_Xcode.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
09028386218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09028385218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift */; };
1212
090E778322A9862100CD99F5 /* ChannelOwnershipTransfer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090E778222A9862100CD99F5 /* ChannelOwnershipTransfer.swift */; };
1313
090E779022AAABC600CD99F5 /* PeersNearby.swift in Sources */ = {isa = PBXBuildFile; fileRef = 090E778F22AAABC600CD99F5 /* PeersNearby.swift */; };
14+
0925903722F0D02D003D6283 /* ManagedAnimatedEmojiUpdates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0925903622F0D02D003D6283 /* ManagedAnimatedEmojiUpdates.swift */; };
1415
093857A82243D87900EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857A62243D87800EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift */; };
1516
093857A92243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857A72243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift */; };
1617
093857AB2243D88D00EB6A54 /* EmojiKeywords.swift in Sources */ = {isa = PBXBuildFile; fileRef = 093857AA2243D88C00EB6A54 /* EmojiKeywords.swift */; };
@@ -827,6 +828,7 @@
827828
09028385218E5DBB0067EFBD /* ManagedVoipConfigurationUpdates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedVoipConfigurationUpdates.swift; sourceTree = "<group>"; };
828829
090E778222A9862100CD99F5 /* ChannelOwnershipTransfer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChannelOwnershipTransfer.swift; sourceTree = "<group>"; };
829830
090E778F22AAABC600CD99F5 /* PeersNearby.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PeersNearby.swift; sourceTree = "<group>"; };
831+
0925903622F0D02D003D6283 /* ManagedAnimatedEmojiUpdates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ManagedAnimatedEmojiUpdates.swift; sourceTree = "<group>"; };
830832
093857A62243D87800EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ManagedSynchronizeEmojiKeywordsOperations.swift; sourceTree = "<group>"; };
831833
093857A72243D87900EB6A54 /* SynchronizeEmojiKeywordsOperation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SynchronizeEmojiKeywordsOperation.swift; sourceTree = "<group>"; };
832834
093857AA2243D88C00EB6A54 /* EmojiKeywords.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EmojiKeywords.swift; sourceTree = "<group>"; };
@@ -1582,6 +1584,7 @@
15821584
093857A62243D87800EB6A54 /* ManagedSynchronizeEmojiKeywordsOperations.swift */,
15831585
D0CA8E4A227209C4008A74C3 /* ManagedSynchronizeGroupMessageStats.swift */,
15841586
D06CA13422772EB20094E707 /* ManagedNotificationSettingsBehaviors.swift */,
1587+
0925903622F0D02D003D6283 /* ManagedAnimatedEmojiUpdates.swift */,
15851588
);
15861589
name = State;
15871590
sourceTree = "<group>";
@@ -2351,6 +2354,7 @@
23512354
D00D34421E6EDD2E0057B307 /* ManagedSynchronizeConsumeMessageContentsOperations.swift in Sources */,
23522355
D08984FB2118816A00918162 /* Reachability.m in Sources */,
23532356
D0DA1D321F7043D50034E892 /* ManagedPendingPeerNotificationSettings.swift in Sources */,
2357+
0925903722F0D02D003D6283 /* ManagedAnimatedEmojiUpdates.swift in Sources */,
23542358
D099D7491EEF418D00A3128C /* HistoryViewChannelStateValidation.swift in Sources */,
23552359
C23BC3871E9BE3CA00D79F92 /* ImportContact.swift in Sources */,
23562360
D0D376E622DCCFD600FA7D7C /* SlowMode.swift in Sources */,

‎submodules/TelegramUI/TelegramUI/AnimatedStickerUtils.swift‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -321,25 +321,3 @@ func fetchLocalBundleResource(postbox: Postbox, resource: LocalBundleResource) -
321321
return EmptyDisposable
322322
}
323323
}
324-
325-
private let emojis: [String: (String, CGFloat)] = [
326-
"👍": ("thumbs_up_1", 450.0),
327-
"👍🏻": ("thumbs_up_2", 450.0),
328-
"👍🏼": ("thumbs_up_3", 450.0),
329-
"👍🏽": ("thumbs_up_4", 450.0),
330-
"👍🏾": ("thumbs_up_5", 450.0),
331-
"👍🏿": ("thumbs_up_6", 450.0),
332-
"😂": ("lol", 350.0),
333-
"😒": ("meh", 350.0),
334-
"❤️": ("heart", 350.0),
335-
"🥳": ("celeb", 430.0),
336-
"😳": ("confused", 350.0)
337-
]
338-
339-
func animatedEmojiResource(emoji: String) -> (LocalBundleResource, CGFloat)? {
340-
if let (name, size) = emojis[emoji] {
341-
return (LocalBundleResource(name: name, ext: "tgs"), size)
342-
} else {
343-
return nil
344-
}
345-
}

‎submodules/TelegramUI/TelegramUI/ChatHistoryEntriesForView.swift‎

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Foundation
22
import Postbox
33
import TelegramCore
44

5-
func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView, includeUnreadEntry: Bool, includeEmptyEntry: Bool, includeChatInfoEntry: Bool, includeSearchEntry: Bool, reverse: Bool, groupMessages: Bool, selectedMessages: Set<MessageId>?, presentationData: ChatPresentationData, historyAppearsCleared: Bool) -> [ChatHistoryEntry] {
5+
func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView, includeUnreadEntry: Bool, includeEmptyEntry: Bool, includeChatInfoEntry: Bool, includeSearchEntry: Bool, reverse: Bool, groupMessages: Bool, selectedMessages: Set<MessageId>?, presentationData: ChatPresentationData, historyAppearsCleared: Bool, associatedData: ChatMessageItemAssociatedData) -> [ChatHistoryEntry] {
66
if historyAppearsCleared {
77
return []
88
}
@@ -36,6 +36,15 @@ func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView,
3636
if let author = entry.message.author {
3737
adminRank = adminRanks[author.id]
3838
}
39+
40+
var contentTypeHint: ChatMessageEntryContentType = .generic
41+
if presentationData.largeEmoji {
42+
if let _ = associatedData.animatedEmojiStickers[entry.message.text.trimmedEmoji] {
43+
contentTypeHint = .animatedEmoji
44+
} else if messageIsElligibleForLargeEmoji(entry.message) {
45+
contentTypeHint = .largeEmoji
46+
}
47+
}
3948

4049
if groupMessages {
4150
if !groupBucket.isEmpty && entry.message.groupInfo != groupBucket[0].0.groupInfo {
@@ -49,15 +58,15 @@ func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView,
4958
} else {
5059
selection = .none
5160
}
52-
groupBucket.append((entry.message, entry.isRead, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact)))
61+
groupBucket.append((entry.message, entry.isRead, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact, contentTypeHint: contentTypeHint)))
5362
} else {
5463
let selection: ChatHistoryMessageSelection
5564
if let selectedMessages = selectedMessages {
5665
selection = .selectable(selected: selectedMessages.contains(entry.message.id))
5766
} else {
5867
selection = .none
5968
}
60-
entries.append(.MessageEntry(entry.message, presentationData, entry.isRead, entry.monthLocation, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact)))
69+
entries.append(.MessageEntry(entry.message, presentationData, entry.isRead, entry.monthLocation, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact, contentTypeHint: contentTypeHint)))
6170
}
6271
} else {
6372
let selection: ChatHistoryMessageSelection
@@ -66,7 +75,7 @@ func chatHistoryEntriesForView(location: ChatLocation, view: MessageHistoryView,
6675
} else {
6776
selection = .none
6877
}
69-
entries.append(.MessageEntry(entry.message, presentationData, entry.isRead, entry.monthLocation, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact)))
78+
entries.append(.MessageEntry(entry.message, presentationData, entry.isRead, entry.monthLocation, selection, ChatMessageEntryAttributes(rank: adminRank, isContact: entry.attributes.authorIsContact, contentTypeHint: contentTypeHint)))
7079
}
7180
}
7281

‎submodules/TelegramUI/TelegramUI/ChatHistoryEntry.swift‎

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,28 @@ public enum ChatHistoryMessageSelection: Equatable {
2424
}
2525
}
2626

27+
public enum ChatMessageEntryContentType {
28+
case generic
29+
case largeEmoji
30+
case animatedEmoji
31+
}
32+
2733
public struct ChatMessageEntryAttributes: Equatable {
2834
let rank: CachedChannelAdminRank?
2935
let isContact: Bool
36+
let contentTypeHint: ChatMessageEntryContentType
37+
38+
init(rank: CachedChannelAdminRank?, isContact: Bool, contentTypeHint: ChatMessageEntryContentType) {
39+
self.rank = rank
40+
self.isContact = isContact
41+
self.contentTypeHint = contentTypeHint
42+
}
43+
44+
public init() {
45+
self.rank = nil
46+
self.isContact = false
47+
self.contentTypeHint = .generic
48+
}
3049
}
3150

3251
enum ChatHistoryEntry: Identifiable, Comparable {
@@ -38,16 +57,17 @@ enum ChatHistoryEntry: Identifiable, Comparable {
3857

3958
var stableId: UInt64 {
4059
switch self {
41-
case let .MessageEntry(message, presentationData, _, _, _, _):
42-
var type = 2
43-
if presentationData.largeEmoji && message.elligibleForLargeEmoji && messageIsElligibleForLargeEmoji(message) {
44-
if animatedEmojiResource(emoji: message.text) != nil {
60+
case let .MessageEntry(message, _, _, _, _, attributes):
61+
let type: UInt64
62+
switch attributes.contentTypeHint {
63+
case .generic:
64+
type = 2
65+
case .largeEmoji:
4566
type = 3
46-
} else {
67+
case .animatedEmoji:
4768
type = 4
48-
}
4969
}
50-
return UInt64(message.stableId) | ((UInt64(type) << 40))
70+
return UInt64(message.stableId) | ((type << 40))
5171
case let .MessageGroupEntry(groupInfo, _, _):
5272
return UInt64(groupInfo.stableId) | ((UInt64(2) << 40))
5373
case .UnreadEntry:

‎submodules/TelegramUI/TelegramUI/ChatHistoryGridNode.swift‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ public final class ChatHistoryGridNode: GridNode, ChatHistoryNode {
301301
}
302302
}
303303

304-
let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: .peer(peerId), view: view, includeUnreadEntry: false, includeEmptyEntry: false, includeChatInfoEntry: false, includeSearchEntry: false, reverse: false, groupMessages: false, selectedMessages: nil, presentationData: chatPresentationData, historyAppearsCleared: false), associatedData: ChatMessageItemAssociatedData(automaticDownloadPeerType: .channel, automaticDownloadNetworkType: .cellular, isRecentActions: false), id: id)
304+
let associatedData = ChatMessageItemAssociatedData(automaticDownloadPeerType: .channel, automaticDownloadNetworkType: .cellular, isRecentActions: false)
305+
let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: .peer(peerId), view: view, includeUnreadEntry: false, includeEmptyEntry: false, includeChatInfoEntry: false, includeSearchEntry: false, reverse: false, groupMessages: false, selectedMessages: nil, presentationData: chatPresentationData, historyAppearsCleared: false, associatedData: associatedData), associatedData: associatedData, id: id)
305306
let previous = previousView.swap(processedView)
306307

307308
let rawTransition = preparedChatHistoryViewTransition(from: previous, to: processedView, reason: reason, reverse: false, chatLocation: .peer(peerId), controllerInteraction: controllerInteraction, scrollPosition: scrollPosition, initialData: nil, keyboardButtonsMessage: nil, cachedData: nil, cachedDataMessages: nil, readStateData: nil, flashIndicators: flashIndicators)

‎submodules/TelegramUI/TelegramUI/ChatHistoryListNode.swift‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ private final class ChatHistoryTransactionOpaqueState {
253253
}
254254
}
255255

256-
private func extractAssociatedData(chatLocation: ChatLocation, view: MessageHistoryView, automaticDownloadNetworkType: MediaAutoDownloadNetworkType) -> ChatMessageItemAssociatedData {
256+
private func extractAssociatedData(chatLocation: ChatLocation, view: MessageHistoryView, automaticDownloadNetworkType: MediaAutoDownloadNetworkType, animatedEmojiStickers: [String: StickerPackItem]) -> ChatMessageItemAssociatedData {
257257
var automaticMediaDownloadPeerType: MediaAutoDownloadPeerType = .channel
258258
var contactsPeerIds: Set<PeerId> = Set()
259259
if case let .peer(peerId) = chatLocation {
@@ -292,7 +292,7 @@ private func extractAssociatedData(chatLocation: ChatLocation, view: MessageHist
292292
}
293293
}
294294
}
295-
let associatedData = ChatMessageItemAssociatedData(automaticDownloadPeerType: automaticMediaDownloadPeerType, automaticDownloadNetworkType: automaticDownloadNetworkType, isRecentActions: false, contactsPeerIds: contactsPeerIds)
295+
let associatedData = ChatMessageItemAssociatedData(automaticDownloadPeerType: automaticMediaDownloadPeerType, automaticDownloadNetworkType: automaticDownloadNetworkType, isRecentActions: false, contactsPeerIds: contactsPeerIds, animatedEmojiStickers: animatedEmojiStickers)
296296
return associatedData
297297
}
298298

@@ -517,11 +517,27 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
517517
}
518518
|> distinctUntilChanged
519519

520+
let animatedEmojiStickers = loadedStickerPack(postbox: context.account.postbox, network: context.account.network, reference: .animatedEmoji, forceActualized: false)
521+
|> map { result -> [String: StickerPackItem] in
522+
switch result {
523+
case let .result(_, items, _):
524+
var animatedEmojiStickers: [String: StickerPackItem] = [:]
525+
for case let item as StickerPackItem in items {
526+
if let emoji = item.getStringRepresentationsOfIndexKeys().first {
527+
animatedEmojiStickers[emoji] = item
528+
}
529+
}
530+
return animatedEmojiStickers
531+
default:
532+
return [:]
533+
}
534+
}
535+
520536
let previousHistoryAppearsCleared = Atomic<Bool?>(value: nil)
521537

522538
let nextTransitionVersion = Atomic<Int>(value: 0)
523539

524-
let historyViewTransitionDisposable = combineLatest(queue: messageViewQueue, historyViewUpdate, self.chatPresentationDataPromise.get(), selectedMessages, automaticDownloadNetworkType, self.historyAppearsClearedPromise.get()).start(next: { [weak self] update, chatPresentationData, selectedMessages, networkType, historyAppearsCleared in
540+
let historyViewTransitionDisposable = combineLatest(queue: messageViewQueue, historyViewUpdate, self.chatPresentationDataPromise.get(), selectedMessages, automaticDownloadNetworkType, self.historyAppearsClearedPromise.get(), animatedEmojiStickers).start(next: { [weak self] update, chatPresentationData, selectedMessages, networkType, historyAppearsCleared, animatedEmojiStickers in
525541
func applyHole() {
526542
Queue.mainQueue().async {
527543
if let strongSelf = self {
@@ -590,9 +606,9 @@ public final class ChatHistoryListNode: ListView, ChatHistoryNode {
590606
reverse = reverseValue
591607
}
592608

593-
let associatedData = extractAssociatedData(chatLocation: chatLocation, view: view, automaticDownloadNetworkType: networkType)
609+
let associatedData = extractAssociatedData(chatLocation: chatLocation, view: view, automaticDownloadNetworkType: networkType, animatedEmojiStickers: animatedEmojiStickers)
594610

595-
let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: chatLocation, view: view, includeUnreadEntry: mode == .bubbles, includeEmptyEntry: mode == .bubbles && tagMask == nil, includeChatInfoEntry: mode == .bubbles, includeSearchEntry: includeSearchEntry && tagMask != nil, reverse: reverse, groupMessages: mode == .bubbles, selectedMessages: selectedMessages, presentationData: chatPresentationData, historyAppearsCleared: historyAppearsCleared), associatedData: associatedData, id: id)
611+
let processedView = ChatHistoryView(originalView: view, filteredEntries: chatHistoryEntriesForView(location: chatLocation, view: view, includeUnreadEntry: mode == .bubbles, includeEmptyEntry: mode == .bubbles && tagMask == nil, includeChatInfoEntry: mode == .bubbles, includeSearchEntry: includeSearchEntry && tagMask != nil, reverse: reverse, groupMessages: mode == .bubbles, selectedMessages: selectedMessages, presentationData: chatPresentationData, historyAppearsCleared: historyAppearsCleared, associatedData: associatedData), associatedData: associatedData, id: id)
596612
let previousValueAndVersion = previousView.swap((processedView, update.1))
597613
let previous = previousValueAndVersion?.0
598614

0 commit comments

Comments
 (0)