Fix send when online

This commit is contained in:
Ilya Laktyushin 2019-11-19 22:38:57 +04:00
parent bab231a71f
commit 66f78760be
2 changed files with 23 additions and 5 deletions

View File

@ -43,7 +43,7 @@ func applyUpdateMessage(postbox: Postbox, stateManager: AccountStateManager, mes
}
}
if let apiMessage = apiMessage, let id = apiMessage.id(namespace: message.scheduleTime != nil ? Namespaces.Message.ScheduledCloud : Namespaces.Message.Cloud) {
if let apiMessage = apiMessage, let id = apiMessage.id(namespace: message.scheduleTime != nil && message.scheduleTime == apiMessage.timestamp ? Namespaces.Message.ScheduledCloud : Namespaces.Message.Cloud) {
messageId = id.id
} else {
messageId = result.rawMessageIds.first

View File

@ -267,6 +267,8 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
}
if let peer = transaction.getPeer(peerId), let accountPeer = transaction.getPeer(account.peerId) {
let peerPresence = transaction.getPeerPresence(peerId: peerId)
var storeMessages: [StoreMessage] = []
var timestamp = Int32(account.network.context.globalTime())
switch peerId.namespace {
@ -377,12 +379,20 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
var effectiveTimestamp = timestamp
for attribute in attributes {
if let attribute = attribute as? OutgoingScheduleInfoMessageAttribute {
messageNamespace = Namespaces.Message.ScheduledLocal
effectiveTimestamp = attribute.scheduleTime
if attribute.scheduleTime == scheduleWhenOnlineTimestamp, let presence = peerPresence as? TelegramUserPresence, case let .present(statusTimestamp) = presence.status, statusTimestamp >= timestamp {
} else {
messageNamespace = Namespaces.Message.ScheduledLocal
effectiveTimestamp = attribute.scheduleTime
}
break
}
}
if messageNamespace != Namespaces.Message.ScheduledLocal {
attributes.removeAll(where: { $0 is OutgoingScheduleInfoMessageAttribute })
}
if let peer = peer as? TelegramChannel {
switch peer.info {
case let .broadcast(info):
@ -515,11 +525,19 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
entitiesAttribute = attribute
}
if let attribute = attribute as? OutgoingScheduleInfoMessageAttribute {
messageNamespace = Namespaces.Message.ScheduledLocal
effectiveTimestamp = attribute.scheduleTime
if attribute.scheduleTime == scheduleWhenOnlineTimestamp, let presence = peerPresence as? TelegramUserPresence, case let .present(statusTimestamp) = presence.status, statusTimestamp >= timestamp {
} else {
messageNamespace = Namespaces.Message.ScheduledLocal
effectiveTimestamp = attribute.scheduleTime
}
}
}
if messageNamespace != Namespaces.Message.ScheduledLocal {
attributes.removeAll(where: { $0 is OutgoingScheduleInfoMessageAttribute })
}
let (tags, globalTags) = tagsForStoreMessage(incoming: false, attributes: attributes, media: sourceMessage.media, textEntities: entitiesAttribute?.entities)
let localGroupingKey: Int64?