diff --git a/submodules/TelegramNotices/Sources/Notices.swift b/submodules/TelegramNotices/Sources/Notices.swift index 4ebdad3bab..627928f5ac 100644 --- a/submodules/TelegramNotices/Sources/Notices.swift +++ b/submodules/TelegramNotices/Sources/Notices.swift @@ -232,6 +232,7 @@ private struct ApplicationSpecificNoticeKeys { private static let botGameNoticeNamespace: Int32 = 7 private static let peerInviteRequestsNamespace: Int32 = 8 private static let dismissedPremiumGiftNamespace: Int32 = 9 + private static let groupEmojiPackNamespace: Int32 = 9 static func inlineBotLocationRequestNotice(peerId: PeerId) -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: inlineBotLocationRequestNamespace), key: noticeKey(peerId: peerId, key: 0)) @@ -253,6 +254,10 @@ private struct ApplicationSpecificNoticeKeys { return NoticeEntryKey(namespace: noticeNamespace(namespace: dismissedPremiumGiftNamespace), key: noticeKey(peerId: peerId, key: 0)) } + static func groupEmojiPackNotice(peerId: PeerId) -> NoticeEntryKey { + return NoticeEntryKey(namespace: noticeNamespace(namespace: groupEmojiPackNamespace), key: noticeKey(peerId: peerId, key: 0)) + } + static func forcedPasswordSetup() -> NoticeEntryKey { return NoticeEntryKey(namespace: noticeNamespace(namespace: globalNamespace), key: ApplicationSpecificGlobalNotice.secretChatInlineBotUsage.key) } @@ -1582,6 +1587,33 @@ public struct ApplicationSpecificNotice { } } + public static func groupEmojiPackSuggestion(accountManager: AccountManager, peerId: PeerId) -> Signal { + return accountManager.noticeEntry(key: ApplicationSpecificNoticeKeys.groupEmojiPackNotice(peerId: peerId)) + |> map { view -> Int32 in + if let value = view.value?.get(ApplicationSpecificCounterNotice.self) { + return value.value + } else { + return 0 + } + } + } + + public static func incrementGroupEmojiPackSuggestion(accountManager: AccountManager, peerId: PeerId, count: Int32 = 1) -> Signal { + return accountManager.transaction { transaction -> Int32 in + var currentValue: Int32 = 0 + if let value = transaction.getNotice(ApplicationSpecificNoticeKeys.groupEmojiPackNotice(peerId: peerId))?.get(ApplicationSpecificCounterNotice.self) { + currentValue = value.value + } + let previousValue = currentValue + currentValue += count + + if let entry = CodableEntry(ApplicationSpecificCounterNotice(value: currentValue)) { + transaction.setNotice(ApplicationSpecificNoticeKeys.groupEmojiPackNotice(peerId: peerId), entry) + } + return previousValue + } + } + public static func getSendWhenOnlineTip(accountManager: AccountManager) -> Signal { return accountManager.transaction { transaction -> Int32 in if let value = transaction.getNotice(ApplicationSpecificNoticeKeys.sendWhenOnlineTip())?.get(ApplicationSpecificCounterNotice.self) { diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index a26dcec6c6..5519a74203 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -15714,42 +15714,52 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G guard let rect = self.chatDisplayNode.frameForEmojiButton(), self.effectiveNavigationController?.topViewController === self else { return } - guard let emojiPack = (self.peerView?.cachedData as? CachedChannelData)?.emojiPack, let thumbnailFileId = emojiPack.thumbnailFileId else { + guard let peerId = self.chatLocation.peerId, let emojiPack = (self.peerView?.cachedData as? CachedChannelData)?.emojiPack, let thumbnailFileId = emojiPack.thumbnailFileId else { return } - let _ = (self.context.engine.stickers.resolveInlineStickers(fileIds: [thumbnailFileId]) - |> deliverOnMainQueue).start(next: { [weak self] files in - guard let self, let emojiFile = files.values.first else { + + let _ = (ApplicationSpecificNotice.groupEmojiPackSuggestion(accountManager: self.context.sharedContext.accountManager, peerId: peerId) + |> deliverOnMainQueue).start(next: { [weak self] counter in + guard let self, counter == 0 else { return } - let textFont = Font.regular(self.presentationData.listsFontSize.baseDisplaySize * 14.0 / 17.0) - let boldTextFont = Font.bold(self.presentationData.listsFontSize.baseDisplaySize * 14.0 / 17.0) - let textColor = UIColor.white - let markdownAttributes = MarkdownAttributes(body: MarkdownAttributeSet(font: textFont, textColor: textColor), bold: MarkdownAttributeSet(font: boldTextFont, textColor: textColor), link: MarkdownAttributeSet(font: textFont, textColor: textColor), linkAttribute: { _ in - return nil - }) - - let text = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(self.presentationData.strings.Chat_GroupEmojiTooltip(emojiPack.title).string, attributes: markdownAttributes)) - - let range = (text.string as NSString).range(of: "#") - if range.location != NSNotFound { - text.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: emojiFile.fileId.id, file: emojiFile), range: range) - } - - let tooltipScreen = TooltipScreen( - context: self.context, - account: self.context.account, - sharedContext: self.context.sharedContext, - text: .attributedString(text: text), - location: .point(rect.offsetBy(dx: 0.0, dy: -3.0), .bottom), - displayDuration: .default, - cornerRadius: 10.0, - shouldDismissOnTouch: { _, _ in - return .ignore + let _ = (self.context.engine.stickers.resolveInlineStickers(fileIds: [thumbnailFileId]) + |> deliverOnMainQueue).start(next: { [weak self] files in + guard let self, let emojiFile = files.values.first else { + return } - ) - self.present(tooltipScreen, in: .current) + + let textFont = Font.regular(self.presentationData.listsFontSize.baseDisplaySize * 14.0 / 17.0) + let boldTextFont = Font.bold(self.presentationData.listsFontSize.baseDisplaySize * 14.0 / 17.0) + let textColor = UIColor.white + let markdownAttributes = MarkdownAttributes(body: MarkdownAttributeSet(font: textFont, textColor: textColor), bold: MarkdownAttributeSet(font: boldTextFont, textColor: textColor), link: MarkdownAttributeSet(font: textFont, textColor: textColor), linkAttribute: { _ in + return nil + }) + + let text = NSMutableAttributedString(attributedString: parseMarkdownIntoAttributedString(self.presentationData.strings.Chat_GroupEmojiTooltip(emojiPack.title).string, attributes: markdownAttributes)) + + let range = (text.string as NSString).range(of: "#") + if range.location != NSNotFound { + text.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: emojiFile.fileId.id, file: emojiFile), range: range) + } + + let tooltipScreen = TooltipScreen( + context: self.context, + account: self.context.account, + sharedContext: self.context.sharedContext, + text: .attributedString(text: text), + location: .point(rect.offsetBy(dx: 0.0, dy: -3.0), .bottom), + displayDuration: .default, + cornerRadius: 10.0, + shouldDismissOnTouch: { _, _ in + return .ignore + } + ) + self.present(tooltipScreen, in: .current) + + let _ = ApplicationSpecificNotice.incrementGroupEmojiPackSuggestion(accountManager: self.context.sharedContext.accountManager, peerId: peerId).startStandalone() + }) }) }