diff --git a/TelegramCore/ApplyUpdateMessage.swift b/TelegramCore/ApplyUpdateMessage.swift index ead9655700..e4c47f2f17 100644 --- a/TelegramCore/ApplyUpdateMessage.swift +++ b/TelegramCore/ApplyUpdateMessage.swift @@ -105,7 +105,15 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes } } - return StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media) + var entitiesAttribute: TextEntitiesMessageAttribute? + for attribute in attributes { + if let attribute = attribute as? TextEntitiesMessageAttribute { + entitiesAttribute = attribute + break + } + } + + return StoreMessage(id: updatedId, globallyUniqueId: nil, timestamp: updatedTimestamp ?? currentMessage.timestamp, flags: [], tags: tagsForStoreMessage(media: media, textEntities: entitiesAttribute?.entities), forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: text, attributes: attributes, media: media) }) if let updatedTimestamp = updatedTimestamp { modifier.offsetPendingMessagesTimestamps(lowerBound: message.id, timestamp: updatedTimestamp) diff --git a/TelegramCore/EnqueueMessage.swift b/TelegramCore/EnqueueMessage.swift index b77e7b6c93..0968025e0d 100644 --- a/TelegramCore/EnqueueMessage.swift +++ b/TelegramCore/EnqueueMessage.swift @@ -155,8 +155,16 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa if let media = media { mediaList.append(media) } + + var entitiesAttribute: TextEntitiesMessageAttribute? + for attribute in attributes { + if let attribute = attribute as? TextEntitiesMessageAttribute { + entitiesAttribute = attribute + break + } + } - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(mediaList), forwardInfo: nil, authorId: account.peerId, text: text, attributes: attributes, media: mediaList)) + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: mediaList, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: account.peerId, text: text, attributes: attributes, media: mediaList)) case let .forward(source): if let sourceMessage = modifier.getMessage(source), let author = sourceMessage.author { if let peer = peer as? TelegramSecretChat { @@ -186,7 +194,16 @@ func enqueueMessages(modifier: Modifier, account: Account, peerId: PeerId, messa } forwardInfo = StoreMessageForwardInfo(authorId: author.id, sourceId: sourceId, sourceMessageId: sourceMessageId, date: sourceMessage.timestamp) } - storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(sourceMessage.media), forwardInfo: forwardInfo, authorId: account.peerId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) + + var entitiesAttribute: TextEntitiesMessageAttribute? + for attribute in attributes { + if let attribute = attribute as? TextEntitiesMessageAttribute { + entitiesAttribute = attribute + break + } + } + + storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, timestamp: timestamp, flags: flags, tags: tagsForStoreMessage(media: sourceMessage.media, textEntities: entitiesAttribute?.entities), forwardInfo: forwardInfo, authorId: account.peerId, text: sourceMessage.text, attributes: attributes, media: sourceMessage.media)) } } } diff --git a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift index 89eeebf941..ea738c28f1 100644 --- a/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift +++ b/TelegramCore/ProcessSecretChatIncomingDecryptedOperations.swift @@ -512,7 +512,16 @@ private func parseMessage(peerId: PeerId, authorId: PeerId, tagLocalIndex: Int32 if let replyToRandomId = replyToRandomId, let replyMessageId = messageIdForGloballyUniqueMessageId(replyToRandomId) { attributes.append(ReplyMessageAttribute(messageId: replyMessageId)) } - return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: tagsForStoreMessage(parsedMedia), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: parsedMedia), resources) + + var entitiesAttribute: TextEntitiesMessageAttribute? + for attribute in attributes { + if let attribute = attribute as? TextEntitiesMessageAttribute { + entitiesAttribute = attribute + break + } + } + + return (StoreMessage(id: MessageId(peerId: peerId, namespace: Namespaces.Message.SecretIncoming, id: tagLocalIndex), globallyUniqueId: randomId, timestamp: timestamp, flags: [.Incoming], tags: tagsForStoreMessage(media: parsedMedia, textEntities: entitiesAttribute?.entities), forwardInfo: nil, authorId: authorId, text: text, attributes: attributes, media: parsedMedia), resources) case let .decryptedMessageService(randomId, action): switch action { case let .decryptedMessageActionDeleteMessages(randomIds): diff --git a/TelegramCore/StoreMessage_Telegram.swift b/TelegramCore/StoreMessage_Telegram.swift index f5eabd6eb0..88e71565c9 100644 --- a/TelegramCore/StoreMessage_Telegram.swift +++ b/TelegramCore/StoreMessage_Telegram.swift @@ -5,12 +5,12 @@ import Foundation import Postbox #endif -func tagsForStoreMessage(_ medias: [Media]) -> MessageTags { +func tagsForStoreMessage(media: [Media], textEntities: [MessageTextEntity]?) -> MessageTags { var tags = MessageTags() - for media in medias { - if let _ = media as? TelegramMediaImage { + for attachment in media { + if let _ = attachment as? TelegramMediaImage { let _ = tags.insert(.PhotoOrVideo) - } else if let file = media as? TelegramMediaFile { + } else if let file = attachment as? TelegramMediaFile { if file.isSticker || file.isAnimated { } else if file.isVideo { let _ = tags.insert(.PhotoOrVideo) @@ -21,10 +21,20 @@ func tagsForStoreMessage(_ medias: [Media]) -> MessageTags { } else { let _ = tags.insert(.File) } - } else if let webpage = media as? TelegramMediaWebpage, case .Loaded = webpage.content { + } else if let webpage = attachment as? TelegramMediaWebpage, case .Loaded = webpage.content { tags.insert(.WebPage) } } + if let textEntities = textEntities, !textEntities.isEmpty && !tags.contains(.WebPage) { + for entity in textEntities { + switch entity.type { + case .Url, .Email: + tags.insert(.WebPage) + default: + break + } + } + } return tags } @@ -351,8 +361,11 @@ extension StoreMessage { attributes.append(EditedMessageAttribute(date: editDate)) } + var entitiesAttribute: TextEntitiesMessageAttribute? if let entities = entities, !entities.isEmpty { - attributes.append(TextEntitiesMessageAttribute(entities: messageTextEntitiesFromApiEntities(entities))) + let attribute = TextEntitiesMessageAttribute(entities: messageTextEntitiesFromApiEntities(entities)) + entitiesAttribute = attribute + attributes.append(attribute) } var storeFlags = StoreMessageFlags() @@ -372,7 +385,7 @@ extension StoreMessage { storeFlags.insert(.Personal) } - self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: tagsForStoreMessage(medias), forwardInfo: forwardInfo, authorId: authorId, text: messageText, attributes: attributes, media: medias) + self.init(id: MessageId(peerId: peerId, namespace: Namespaces.Message.Cloud, id: id), globallyUniqueId: nil, timestamp: date, flags: storeFlags, tags: tagsForStoreMessage(media: medias, textEntities: entitiesAttribute?.entities), forwardInfo: forwardInfo, authorId: authorId, text: messageText, attributes: attributes, media: medias) case .messageEmpty: return nil case let .messageService(flags, id, fromId, toId, replyToMsgId, date, action):