mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2026-04-06 05:25:03 +00:00
Fixes
fix localeWithStrings globally (#30)
Fix badge on zoomed devices. closes #9
Hide channel bottom panel closes #27
Another attempt to fix badge on some Zoomed devices
Force System Share sheet tg://sg/debug
fixes for device badge
New Crowdin updates (#34)
* New translations sglocalizable.strings (Chinese Traditional)
* New translations sglocalizable.strings (Chinese Simplified)
* New translations sglocalizable.strings (Chinese Traditional)
Fix input panel hidden on selection (#31)
* added if check for selectionState != nil
* same order of subnodes
Revert "Fix input panel hidden on selection (#31)"
This reverts commit e8a8bb1496.
Fix input panel for channels Closes #37
Quickly share links with system's share menu
force tabbar when editing
increase height for correct animation
New translations sglocalizable.strings (Ukrainian) (#38)
Hide Post Story button
Fix 10.15.1
Fix archive option for long-tap
Enable in-app Safari
Disable some unsupported purchases
disableDeleteChatSwipeOption + refactor restart alert
Hide bot in suggestions list
Fix merge v11.0
Fix exceptions for safari webview controller
New Crowdin updates (#47)
* New translations sglocalizable.strings (Romanian)
* New translations sglocalizable.strings (French)
* New translations sglocalizable.strings (Spanish)
* New translations sglocalizable.strings (Afrikaans)
* New translations sglocalizable.strings (Arabic)
* New translations sglocalizable.strings (Catalan)
* New translations sglocalizable.strings (Czech)
* New translations sglocalizable.strings (Danish)
* New translations sglocalizable.strings (German)
* New translations sglocalizable.strings (Greek)
* New translations sglocalizable.strings (Finnish)
* New translations sglocalizable.strings (Hebrew)
* New translations sglocalizable.strings (Hungarian)
* New translations sglocalizable.strings (Italian)
* New translations sglocalizable.strings (Japanese)
* New translations sglocalizable.strings (Korean)
* New translations sglocalizable.strings (Dutch)
* New translations sglocalizable.strings (Norwegian)
* New translations sglocalizable.strings (Polish)
* New translations sglocalizable.strings (Portuguese)
* New translations sglocalizable.strings (Serbian (Cyrillic))
* New translations sglocalizable.strings (Swedish)
* New translations sglocalizable.strings (Turkish)
* New translations sglocalizable.strings (Vietnamese)
* New translations sglocalizable.strings (Indonesian)
* New translations sglocalizable.strings (Hindi)
* New translations sglocalizable.strings (Uzbek)
New Crowdin updates (#49)
* New translations sglocalizable.strings (Arabic)
* New translations sglocalizable.strings (Arabic)
New translations sglocalizable.strings (Russian) (#51)
Call confirmation
WIP Settings search
Settings Search
Localize placeholder
Update AccountUtils.swift
mark mutual contact
Align back context action to left
New Crowdin updates (#54)
* New translations sglocalizable.strings (Chinese Simplified)
* New translations sglocalizable.strings (Chinese Traditional)
* New translations sglocalizable.strings (Ukrainian)
Independent Playground app for simulator
New translations sglocalizable.strings (Ukrainian) (#55)
Playground UIKit base and controllers
Inject SwiftUI view with overflow to AsyncDisplayKit
Launch Playgound project on simulator
Create .swiftformat
Move Playground to example
Update .swiftformat
Init SwiftUIViewController
wip
New translations sglocalizable.strings (Chinese Traditional) (#57)
Xcode 16 fixes
Fix
New translations sglocalizable.strings (Italian) (#59)
New translations sglocalizable.strings (Chinese Simplified) (#63)
Force disable CallKit integration due to missing NSE Entitlement
Fix merge
Fix whole chat translator
Sweetpad config
Bump version
11.3.1 fixes
Mutual contact placement fix
Disable Video PIP swipe
Update versions.json
Fix PIP crash
271 lines
15 KiB
Swift
271 lines
15 KiB
Swift
import SGSimpleSettings
|
|
import Foundation
|
|
import UIKit
|
|
import TelegramCore
|
|
import Postbox
|
|
import Display
|
|
import AccountContext
|
|
import Emoji
|
|
import ChatInterfaceState
|
|
import ChatPresentationInterfaceState
|
|
import SwiftSignalKit
|
|
import TextFormat
|
|
import ChatContextQuery
|
|
|
|
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).startStrict(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(interactivelySelectedFromPackId: nil, fileId: file.fileId.id, file: file), range: range)
|
|
}
|
|
}
|
|
})
|
|
|
|
inputState.inputText = text
|
|
|
|
return interfaceState.withUpdatedComposeInputState(inputState)
|
|
}
|
|
})
|
|
}
|
|
})
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func inputContextQueriesForChatPresentationIntefaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState) -> [ChatPresentationInputQuery] {
|
|
if case let .customChatContents(customChatContents) = chatPresentationInterfaceState.subject {
|
|
switch customChatContents.kind {
|
|
case .hashTagSearch:
|
|
return []
|
|
case .quickReplyMessageInput:
|
|
break
|
|
case .businessLinkSetup:
|
|
return []
|
|
}
|
|
}
|
|
|
|
let inputState = chatPresentationInterfaceState.interfaceState.effectiveInputState
|
|
let inputString: NSString = inputState.inputText.string as NSString
|
|
var result: [ChatPresentationInputQuery] = []
|
|
for (possibleQueryRange, possibleTypes, additionalStringRange) in textInputStateContextQueryRangeAndType(inputState) {
|
|
let query = inputString.substring(with: possibleQueryRange)
|
|
if possibleTypes == [.emoji] {
|
|
result.append(.emoji(query.basicEmoji.0))
|
|
} else if possibleTypes == [.hashtag] {
|
|
result.append(.hashtag(query))
|
|
} else if possibleTypes == [.mention] {
|
|
var types: ChatInputQueryMentionTypes = [.members]
|
|
if possibleQueryRange.lowerBound == 1 {
|
|
types.insert(.contextBots)
|
|
}
|
|
result.append(.mention(query: query, types: types))
|
|
} else if possibleTypes == [.command] {
|
|
result.append(.command(query))
|
|
} else if possibleTypes == [.contextRequest], let additionalStringRange = additionalStringRange {
|
|
let additionalString = inputString.substring(with: additionalStringRange)
|
|
result.append(.contextRequest(addressName: query, query: additionalString))
|
|
} else if possibleTypes == [.emojiSearch], !query.isEmpty, let inputLanguage = chatPresentationInterfaceState.interfaceState.inputLanguage {
|
|
result.append(.emojiSearch(query: query, languageCode: inputLanguage, range: possibleQueryRange))
|
|
}
|
|
}
|
|
return result
|
|
}
|
|
|
|
func inputTextPanelStateForChatPresentationInterfaceState(_ chatPresentationInterfaceState: ChatPresentationInterfaceState, context: AccountContext) -> ChatTextInputPanelState {
|
|
var contextPlaceholder: NSAttributedString?
|
|
loop: for (_, result) in chatPresentationInterfaceState.inputQueryResults {
|
|
if case let .contextRequestResult(peer, _) = result, case let .user(botUser) = peer, let botInfo = botUser.botInfo, let inlinePlaceholder = botInfo.inlinePlaceholder {
|
|
let inputQueries = inputContextQueriesForChatPresentationIntefaceState(chatPresentationInterfaceState)
|
|
for inputQuery in inputQueries {
|
|
if case let .contextRequest(addressName, query) = inputQuery, query.isEmpty {
|
|
let baseFontSize: CGFloat = max(chatTextInputMinFontSize, chatPresentationInterfaceState.fontSize.baseDisplaySize)
|
|
|
|
let string = NSMutableAttributedString()
|
|
string.append(NSAttributedString(string: "@" + addressName, font: Font.regular(baseFontSize), textColor: UIColor.clear))
|
|
string.append(NSAttributedString(string: " " + inlinePlaceholder, font: Font.regular(baseFontSize), textColor: chatPresentationInterfaceState.theme.chat.inputPanel.inputPlaceholderColor))
|
|
contextPlaceholder = string
|
|
}
|
|
}
|
|
|
|
break loop
|
|
}
|
|
}
|
|
|
|
var currentAutoremoveTimeout: Int32? = chatPresentationInterfaceState.autoremoveTimeout
|
|
var canSetupAutoremoveTimeout = false
|
|
|
|
var canSendTextMessages = true
|
|
|
|
var accessoryItems: [ChatTextInputAccessoryItem] = []
|
|
|
|
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat {
|
|
var extendedSearchLayout = false
|
|
loop: for (_, result) in chatPresentationInterfaceState.inputQueryResults {
|
|
if case let .contextRequestResult(peer, _) = result, peer != nil {
|
|
extendedSearchLayout = true
|
|
break loop
|
|
}
|
|
}
|
|
|
|
if !extendedSearchLayout {
|
|
currentAutoremoveTimeout = peer.messageAutoremoveTimeout
|
|
canSetupAutoremoveTimeout = true
|
|
}
|
|
} else if let group = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramGroup {
|
|
if !group.hasBannedPermission(.banChangeInfo) {
|
|
canSetupAutoremoveTimeout = true
|
|
}
|
|
canSendTextMessages = !group.hasBannedPermission(.banSendText)
|
|
} else if let user = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramUser {
|
|
if user.botInfo == nil {
|
|
canSetupAutoremoveTimeout = true
|
|
}
|
|
} else if let channel = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramChannel {
|
|
if channel.hasPermission(.changeInfo) {
|
|
canSetupAutoremoveTimeout = true
|
|
}
|
|
canSendTextMessages = channel.hasBannedPermission(.banSendText) == nil
|
|
}
|
|
|
|
if canSetupAutoremoveTimeout {
|
|
if case .scheduledMessages = chatPresentationInterfaceState.subject {
|
|
} else if chatPresentationInterfaceState.renderedPeer?.peerId != context.account.peerId {
|
|
if currentAutoremoveTimeout != nil || chatPresentationInterfaceState.renderedPeer?.peer is TelegramSecretChat {
|
|
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
|
}
|
|
}
|
|
}
|
|
|
|
switch chatPresentationInterfaceState.inputMode {
|
|
case .media:
|
|
accessoryItems.append(.input(isEnabled: true, inputMode: .keyboard))
|
|
return ChatTextInputPanelState(accessoryItems: accessoryItems, contextPlaceholder: contextPlaceholder, mediaRecordingState: chatPresentationInterfaceState.inputTextPanelState.mediaRecordingState)
|
|
case .inputButtons:
|
|
return ChatTextInputPanelState(accessoryItems: [.botInput(isEnabled: true, inputMode: .keyboard)], contextPlaceholder: contextPlaceholder, mediaRecordingState: chatPresentationInterfaceState.inputTextPanelState.mediaRecordingState)
|
|
case .none, .text:
|
|
if let _ = chatPresentationInterfaceState.interfaceState.editMessage {
|
|
accessoryItems.append(.input(isEnabled: true, inputMode: .emoji))
|
|
|
|
return ChatTextInputPanelState(accessoryItems: accessoryItems, contextPlaceholder: contextPlaceholder, mediaRecordingState: chatPresentationInterfaceState.inputTextPanelState.mediaRecordingState)
|
|
} else {
|
|
var accessoryItems: [ChatTextInputAccessoryItem] = []
|
|
let isTextEmpty = chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0
|
|
let hasForward = chatPresentationInterfaceState.interfaceState.forwardMessageIds != nil
|
|
|
|
if case .scheduledMessages = chatPresentationInterfaceState.subject {
|
|
} else {
|
|
let premiumConfiguration = PremiumConfiguration.with(appConfiguration: context.currentAppConfiguration.with { $0 })
|
|
var showPremiumGift = false
|
|
if !premiumConfiguration.isPremiumDisabled {
|
|
if chatPresentationInterfaceState.hasBirthdayToday {
|
|
showPremiumGift = true
|
|
} else if premiumConfiguration.showPremiumGiftInAttachMenu && premiumConfiguration.showPremiumGiftInTextField {
|
|
showPremiumGift = true
|
|
}
|
|
}
|
|
if isTextEmpty, showPremiumGift, let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramUser, !peer.isDeleted && peer.botInfo == nil && !peer.flags.contains(.isSupport) && !peer.isPremium && !chatPresentationInterfaceState.premiumGiftOptions.isEmpty && chatPresentationInterfaceState.suggestPremiumGift {
|
|
accessoryItems.append(.gift)
|
|
}
|
|
}
|
|
|
|
var extendedSearchLayout = false
|
|
loop: for (_, result) in chatPresentationInterfaceState.inputQueryResults {
|
|
if case let .contextRequestResult(peer, _) = result, peer != nil {
|
|
extendedSearchLayout = true
|
|
break loop
|
|
}
|
|
}
|
|
if !extendedSearchLayout {
|
|
if case .scheduledMessages = chatPresentationInterfaceState.subject {
|
|
} else if chatPresentationInterfaceState.renderedPeer?.peerId != context.account.peerId {
|
|
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramSecretChat, chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0 {
|
|
accessoryItems.append(.messageAutoremoveTimeout(peer.messageAutoremoveTimeout))
|
|
} else if currentAutoremoveTimeout != nil && chatPresentationInterfaceState.interfaceState.composeInputState.inputText.length == 0 {
|
|
accessoryItems.append(.messageAutoremoveTimeout(currentAutoremoveTimeout))
|
|
}
|
|
}
|
|
}
|
|
|
|
if isTextEmpty && chatPresentationInterfaceState.hasScheduledMessages && !hasForward {
|
|
accessoryItems.append(.scheduledMessages)
|
|
}
|
|
|
|
var stickersEnabled = true
|
|
var stickersAreEmoji = !isTextEmpty
|
|
if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramChannel {
|
|
if isTextEmpty, case .broadcast = peer.info, canSendMessagesToPeer(peer) {
|
|
accessoryItems.append(.silentPost(chatPresentationInterfaceState.interfaceState.silentPosting))
|
|
}
|
|
if let boostsToUnrestrict = chatPresentationInterfaceState.boostsToUnrestrict, boostsToUnrestrict > 0 {
|
|
|
|
} else {
|
|
if peer.hasBannedPermission(.banSendStickers) != nil {
|
|
stickersEnabled = false
|
|
}
|
|
}
|
|
} else if let peer = chatPresentationInterfaceState.renderedPeer?.peer as? TelegramGroup {
|
|
if peer.hasBannedPermission(.banSendStickers) {
|
|
stickersEnabled = false
|
|
}
|
|
}
|
|
|
|
if case let .customChatContents(customChatContents) = chatPresentationInterfaceState.subject {
|
|
switch customChatContents.kind {
|
|
case .hashTagSearch:
|
|
break
|
|
case .quickReplyMessageInput:
|
|
break
|
|
case .businessLinkSetup:
|
|
stickersEnabled = false
|
|
}
|
|
}
|
|
|
|
if isTextEmpty && chatPresentationInterfaceState.hasBots && chatPresentationInterfaceState.hasBotCommands && !hasForward {
|
|
accessoryItems.append(.commands)
|
|
}
|
|
|
|
if !canSendTextMessages {
|
|
if stickersEnabled && !stickersAreEmoji && !hasForward {
|
|
accessoryItems.append(.input(isEnabled: true, inputMode: .stickers))
|
|
}
|
|
} else {
|
|
stickersAreEmoji = stickersAreEmoji || hasForward
|
|
if stickersEnabled, !SGSimpleSettings.shared.forceEmojiTab {
|
|
accessoryItems.append(.input(isEnabled: true, inputMode: stickersAreEmoji ? .emoji : .stickers))
|
|
} else {
|
|
accessoryItems.append(.input(isEnabled: true, inputMode: .emoji))
|
|
}
|
|
}
|
|
|
|
if isTextEmpty, let message = chatPresentationInterfaceState.keyboardButtonsMessage, let _ = message.visibleButtonKeyboardMarkup, chatPresentationInterfaceState.interfaceState.messageActionsState.dismissedButtonKeyboardMessageId != message.id {
|
|
accessoryItems.append(.botInput(isEnabled: true, inputMode: .bot))
|
|
}
|
|
|
|
return ChatTextInputPanelState(accessoryItems: accessoryItems, contextPlaceholder: contextPlaceholder, mediaRecordingState: chatPresentationInterfaceState.inputTextPanelState.mediaRecordingState)
|
|
}
|
|
}
|
|
}
|