no message

This commit is contained in:
Peter 2017-03-06 17:22:54 +03:00
parent 49d1aea8d2
commit 91ed2e4bd0
4 changed files with 58 additions and 11 deletions

View File

@ -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)

View File

@ -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))
}
}
}

View File

@ -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):

View File

@ -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):