mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 22:55:00 +00:00
Emoji improvements
This commit is contained in:
@@ -7,6 +7,8 @@ import AccountContext
|
||||
import Emoji
|
||||
import ChatInterfaceState
|
||||
import ChatPresentationInterfaceState
|
||||
import SwiftSignalKit
|
||||
import TextFormat
|
||||
|
||||
struct PossibleContextQueryTypes: OptionSet {
|
||||
var rawValue: Int32
|
||||
@@ -109,7 +111,9 @@ func textInputStateContextQueryRangeAndType(_ inputState: ChatTextInputState) ->
|
||||
let string = (inputString as String)
|
||||
let trimmedString = string.trimmingTrailingSpaces()
|
||||
if string.count < 3, trimmedString.isSingleEmoji {
|
||||
return [(NSRange(location: 0, length: inputString.length - (string.count - trimmedString.count)), [.emoji], nil)]
|
||||
if inputText.attribute(ChatTextInputAttributes.customEmoji, at: 0, effectiveRange: nil) == nil {
|
||||
return [(NSRange(location: 0, length: inputString.length - (string.count - trimmedString.count)), [.emoji], nil)]
|
||||
}
|
||||
}
|
||||
|
||||
var possibleTypes = PossibleContextQueryTypes([.command, .mention, .hashtag, .emojiSearch])
|
||||
@@ -173,6 +177,49 @@ func textInputStateContextQueryRangeAndType(_ inputState: ChatTextInputState) ->
|
||||
return results
|
||||
}
|
||||
|
||||
func serviceTasksForChatPresentationIntefaceState(context: AccountContext, chatPresentationInterfaceState: ChatPresentationInterfaceState, updateState: @escaping ((ChatPresentationInterfaceState) -> ChatPresentationInterfaceState) -> Void) -> [AnyHashable: () -> Disposable] {
|
||||
var missingEmoji = Set<Int64>()
|
||||
let inputText = chatPresentationInterfaceState.interfaceState.composeInputState.inputText
|
||||
inputText.enumerateAttribute(ChatTextInputAttributes.customEmoji, in: NSRange(location: 0, length: inputText.length), using: { value, _, _ in
|
||||
if let value = value as? ChatTextInputTextCustomEmojiAttribute {
|
||||
if value.file == nil {
|
||||
missingEmoji.insert(value.fileId)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var result: [AnyHashable: () -> Disposable] = [:]
|
||||
for id in missingEmoji {
|
||||
result["emoji-\(id)"] = {
|
||||
return (context.engine.stickers.resolveInlineStickers(fileIds: [id])
|
||||
|> deliverOnMainQueue).start(next: { result in
|
||||
if let file = result[id] {
|
||||
updateState({ state -> ChatPresentationInterfaceState in
|
||||
return state.updatedInterfaceState { interfaceState -> ChatInterfaceState in
|
||||
var inputState = interfaceState.composeInputState
|
||||
let text = NSMutableAttributedString(attributedString: inputState.inputText)
|
||||
|
||||
inputState.inputText.enumerateAttribute(ChatTextInputAttributes.customEmoji, in: NSRange(location: 0, length: inputText.length), using: { value, range, _ in
|
||||
if let value = value as? ChatTextInputTextCustomEmojiAttribute {
|
||||
if value.fileId == id {
|
||||
text.removeAttribute(ChatTextInputAttributes.customEmoji, range: range)
|
||||
text.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(stickerPack: nil, fileId: file.fileId.id, file: file), range: range)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
inputState.inputText = text
|
||||
|
||||
return interfaceState.withUpdatedComposeInputState(inputState)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func inputContextQueriesForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState) -> [ChatPresentationInputQuery] {
|
||||
let inputState = chatPresentationInterfaceState.interfaceState.effectiveInputState
|
||||
let inputString: NSString = inputState.inputText.string as NSString
|
||||
|
||||
Reference in New Issue
Block a user