mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
CarPlay fixes
This commit is contained in:
parent
7b147bc8e1
commit
d748b3e881
@ -56,8 +56,7 @@ class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessag
|
|||||||
override init() {
|
override init() {
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
let appBundleIdentifier = Bundle.main.bundleIdentifier!
|
guard let appBundleIdentifier = Bundle.main.bundleIdentifier, let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else {
|
||||||
guard let lastDotRange = appBundleIdentifier.range(of: ".", options: [.backwards]) else {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +412,13 @@ class IntentHandler: INExtension, INSendMessageIntentHandling, INSearchForMessag
|
|||||||
|> introduceError(IntentHandlingError.self)
|
|> introduceError(IntentHandlingError.self)
|
||||||
|> take(1)
|
|> take(1)
|
||||||
|> mapToSignal { _ -> Signal<[INMessage], IntentHandlingError> in
|
|> mapToSignal { _ -> Signal<[INMessage], IntentHandlingError> in
|
||||||
return unreadMessages(account: account)
|
let messages: Signal<[INMessage], NoError>
|
||||||
|
if let identifiers = intent.identifiers, !identifiers.isEmpty {
|
||||||
|
messages = getMessages(account: account, ids: identifiers.compactMap(MessageId.init(string:)))
|
||||||
|
} else {
|
||||||
|
messages = unreadMessages(account: account)
|
||||||
|
}
|
||||||
|
return messages
|
||||||
|> introduceError(IntentHandlingError.self)
|
|> introduceError(IntentHandlingError.self)
|
||||||
|> afterDisposed {
|
|> afterDisposed {
|
||||||
account.shouldBeServiceTaskMaster.set(.single(.never))
|
account.shouldBeServiceTaskMaster.set(.single(.never))
|
||||||
|
@ -1,11 +1,33 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
import Display
|
|
||||||
import SwiftSignalKit
|
import SwiftSignalKit
|
||||||
import Postbox
|
import Postbox
|
||||||
import TelegramCore
|
import TelegramCore
|
||||||
import Contacts
|
import Contacts
|
||||||
import Intents
|
import Intents
|
||||||
|
|
||||||
|
extension MessageId {
|
||||||
|
init?(string: String) {
|
||||||
|
let components = string.components(separatedBy: "_")
|
||||||
|
if components.count == 3, let peerIdValue = Int64(components[0]), let namespaceValue = Int32(components[1]), let idValue = Int32(components[2]) {
|
||||||
|
self.init(peerId: PeerId(peerIdValue), namespace: namespaceValue, id: idValue)
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessages(account: Account, ids: [MessageId]) -> Signal<[INMessage], NoError> {
|
||||||
|
return account.postbox.transaction { transaction -> [INMessage] in
|
||||||
|
var messages: [INMessage] = []
|
||||||
|
for id in ids {
|
||||||
|
if let message = transaction.getMessage(id).flatMap(messageWithTelegramMessage) {
|
||||||
|
messages.append(message)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return messages.sorted { $0.dateSent!.compare($1.dateSent!) == .orderedDescending }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
|
func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
|
||||||
return account.postbox.tailChatListView(groupId: .root, count: 20, summaryComponents: ChatListEntrySummaryComponents())
|
return account.postbox.tailChatListView(groupId: .root, count: 20, summaryComponents: ChatListEntrySummaryComponents())
|
||||||
|> take(1)
|
|> take(1)
|
||||||
@ -42,7 +64,7 @@ func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !isRead {
|
if !isRead {
|
||||||
if let message = messageWithTelegramMessage(entry.message, account: account) {
|
if let message = messageWithTelegramMessage(entry.message) {
|
||||||
messages.append(message)
|
messages.append(message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,7 +80,7 @@ func unreadMessages(account: Account) -> Signal<[INMessage], NoError> {
|
|||||||
} else {
|
} else {
|
||||||
return combineLatest(signals)
|
return combineLatest(signals)
|
||||||
|> map { results -> [INMessage] in
|
|> map { results -> [INMessage] in
|
||||||
return results.flatMap { $0 }.sorted(by: { $0.dateSent!.compare($1.dateSent!) == ComparisonResult.orderedDescending })
|
return results.flatMap { $0 }.sorted { $0.dateSent!.compare($1.dateSent!) == .orderedDescending }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -94,7 +116,7 @@ func missedCalls(account: Account) -> Signal<[CallRecord], NoError> {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return calls.sorted(by: { $0.date.compare($1.date) == ComparisonResult.orderedDescending })
|
return calls.sorted { $0.date.compare($1.date) == .orderedDescending }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,7 +158,7 @@ private func callWithTelegramMessage(_ telegramMessage: Message, account: Accoun
|
|||||||
return CallRecord(identifier: identifier, date: date, caller: caller, duration: duration, unseen: true)
|
return CallRecord(identifier: identifier, date: date, caller: caller, duration: duration, unseen: true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func messageWithTelegramMessage(_ telegramMessage: Message, account: Account) -> INMessage? {
|
private func messageWithTelegramMessage(_ telegramMessage: Message) -> INMessage? {
|
||||||
guard let author = telegramMessage.author, let user = telegramMessage.peers[author.id] as? TelegramUser, user.id.id != 777000 else {
|
guard let author = telegramMessage.author, let user = telegramMessage.peers[author.id] as? TelegramUser, user.id.id != 777000 else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -181,7 +203,7 @@ private func messageWithTelegramMessage(_ telegramMessage: Message, account: Acc
|
|||||||
messageType = .mediaAudio
|
messageType = .mediaAudio
|
||||||
break loop
|
break loop
|
||||||
} else if file.isVoice {
|
} else if file.isVoice {
|
||||||
messageType = .audio
|
messageType = .mediaAudio
|
||||||
break loop
|
break loop
|
||||||
} else if file.isSticker || file.isAnimatedSticker {
|
} else if file.isSticker || file.isAnimatedSticker {
|
||||||
messageType = .sticker
|
messageType = .sticker
|
||||||
@ -189,6 +211,9 @@ private func messageWithTelegramMessage(_ telegramMessage: Message, account: Acc
|
|||||||
} else if file.isAnimated {
|
} else if file.isAnimated {
|
||||||
messageType = .mediaVideo
|
messageType = .mediaVideo
|
||||||
break loop
|
break loop
|
||||||
|
} else if #available(iOSApplicationExtension 12.0, *) {
|
||||||
|
messageType = .file
|
||||||
|
break loop
|
||||||
}
|
}
|
||||||
} else if media is TelegramMediaMap {
|
} else if media is TelegramMediaMap {
|
||||||
messageType = .mediaLocation
|
messageType = .mediaLocation
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
<string>merchant.privatbank.test.telergramios</string>
|
<string>merchant.privatbank.test.telergramios</string>
|
||||||
<string>merchant.privatbank.prod.telergram</string>
|
<string>merchant.privatbank.prod.telergram</string>
|
||||||
</array>
|
</array>
|
||||||
<key>com.apple.developer.carplay-messaging</key><true/>
|
<key>com.apple.developer.carplay-messaging</key>
|
||||||
<key>com.apple.developer.carplay-calling</key><true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
@ -97,7 +97,7 @@ public func searchStickers(account: Account, query: String, scope: SearchSticker
|
|||||||
for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudSavedStickers) {
|
for entry in transaction.getOrderedListItems(collectionId: Namespaces.OrderedItemList.CloudSavedStickers) {
|
||||||
if let item = entry.contents as? SavedStickerItem {
|
if let item = entry.contents as? SavedStickerItem {
|
||||||
for representation in item.stringRepresentations {
|
for representation in item.stringRepresentations {
|
||||||
if representation == query {
|
if representation.hasPrefix(query) {
|
||||||
result.append(FoundStickerItem(file: item.file, stringRepresentations: item.stringRepresentations))
|
result.append(FoundStickerItem(file: item.file, stringRepresentations: item.stringRepresentations))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ public func searchStickers(account: Account, query: String, scope: SearchSticker
|
|||||||
if let item = entry.contents as? RecentMediaItem, let file = item.media as? TelegramMediaFile {
|
if let item = entry.contents as? RecentMediaItem, let file = item.media as? TelegramMediaFile {
|
||||||
if !currentItems.contains(file.fileId) {
|
if !currentItems.contains(file.fileId) {
|
||||||
for case let .Sticker(sticker) in file.attributes {
|
for case let .Sticker(sticker) in file.attributes {
|
||||||
if sticker.displayText == query {
|
if sticker.displayText.hasPrefix(query) {
|
||||||
matchingRecentItemsIds.insert(file.fileId)
|
matchingRecentItemsIds.insert(file.fileId)
|
||||||
}
|
}
|
||||||
recentItemsIds.insert(file.fileId)
|
recentItemsIds.insert(file.fileId)
|
||||||
@ -130,9 +130,14 @@ public func searchStickers(account: Account, query: String, scope: SearchSticker
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var searchQuery: ItemCollectionSearchQuery = .exact(ValueBoxKey(query))
|
||||||
|
if query == "\u{2764}" {
|
||||||
|
searchQuery = .matching([ValueBoxKey("\u{2764}"), ValueBoxKey("\u{2764}\u{fe0f}")])
|
||||||
|
}
|
||||||
|
|
||||||
var installedItems: [FoundStickerItem] = []
|
var installedItems: [FoundStickerItem] = []
|
||||||
var installedAnimatedItems: [FoundStickerItem] = []
|
var installedAnimatedItems: [FoundStickerItem] = []
|
||||||
for item in transaction.searchItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, query: .exact(ValueBoxKey(query))) {
|
for item in transaction.searchItemCollection(namespace: Namespaces.ItemCollection.CloudStickerPacks, query: searchQuery) {
|
||||||
if let item = item as? StickerPackItem {
|
if let item = item as? StickerPackItem {
|
||||||
if !currentItems.contains(item.file.fileId) {
|
if !currentItems.contains(item.file.fileId) {
|
||||||
var stringRepresentations: [String] = []
|
var stringRepresentations: [String] = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user