no message

This commit is contained in:
Peter
2018-07-21 21:31:04 +03:00
parent 26a1164939
commit 152d25f4ff
5 changed files with 86 additions and 66 deletions

View File

@@ -57,7 +57,7 @@ public extension Message {
case _ as TelegramMediaImage:
return true
case let file as TelegramMediaFile:
if file.isVideo {
if file.isVideo || file.isAnimated || file.isVoice {
return true
}
default:

View File

@@ -1032,61 +1032,61 @@ private func sendMessage(postbox: Postbox, network: Network, messageId: MessageI
if let message = transaction.getMessage(messageId), let globallyUniqueId = message.globallyUniqueId {
let decryptedMessage = boxedDecryptedMessage(transaction: transaction, message: message, globallyUniqueId: globallyUniqueId, uploadedFile: file, thumbnailData: thumbnailData, layer: layer)
return sendBoxedDecryptedMessage(postbox: postbox, network: network, peer: peer, state: state, operationIndex: tagLocalIndex, decryptedMessage: decryptedMessage, globallyUniqueId: globallyUniqueId, file: file, asService: wasDelivered, wasDelivered: wasDelivered)
|> mapToSignal { result in
return postbox.transaction { transaction -> Void in
if result == nil {
replaceOutgoingOperationWithEmptyMessage(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, globallyUniqueId: globallyUniqueId)
} else {
markOutgoingOperationAsCompleted(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, forceRemove: result == nil)
}
var timestamp = message.timestamp
var encryptedFile: SecretChatFileReference?
if let result = result {
switch result {
case let .sentEncryptedMessage(date):
timestamp = date
case let .sentEncryptedFile(date, file):
timestamp = date
encryptedFile = SecretChatFileReference(file)
}
}
transaction.offsetPendingMessagesTimestamps(lowerBound: message.id, excludeIds: Set([messageId]), timestamp: timestamp)
transaction.updateMessage(message.id, update: { currentMessage in
var flags = StoreMessageFlags(currentMessage.flags)
if let _ = result {
flags.remove(.Unsent)
flags.remove(.Sending)
} else {
flags = [.Failed]
}
var storeForwardInfo: StoreMessageForwardInfo?
if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature)
}
var updatedMedia = currentMessage.media
if let fromMedia = currentMessage.media.first, let encryptedFile = encryptedFile, let file = file {
var toMedia: Media?
if let fromMedia = fromMedia as? TelegramMediaFile {
let updatedFile = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.CloudSecretFile, id: encryptedFile.id), reference: nil, resource: SecretFileMediaResource(fileId: encryptedFile.id, accessHash: encryptedFile.accessHash, containerSize: encryptedFile.size, decryptedSize: file.size, datacenterId: Int(encryptedFile.datacenterId), key: file.key), previewRepresentations: fromMedia.previewRepresentations, mimeType: fromMedia.mimeType, size: fromMedia.size, attributes: fromMedia.attributes)
toMedia = updatedFile
updatedMedia = [updatedFile]
}
if let toMedia = toMedia {
applyMediaResourceChanges(from: fromMedia, to: toMedia, postbox: postbox)
}
}
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: updatedMedia))
})
maybeReadSecretOutgoingMessage(transaction: transaction, index: MessageIndex(id: message.id, timestamp: timestamp))
|> mapToSignal { result in
return postbox.transaction { transaction -> Void in
if result == nil {
replaceOutgoingOperationWithEmptyMessage(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, globallyUniqueId: globallyUniqueId)
} else {
markOutgoingOperationAsCompleted(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, forceRemove: result == nil)
}
var timestamp = message.timestamp
var encryptedFile: SecretChatFileReference?
if let result = result {
switch result {
case let .sentEncryptedMessage(date):
timestamp = date
case let .sentEncryptedFile(date, file):
timestamp = date
encryptedFile = SecretChatFileReference(file)
}
}
transaction.offsetPendingMessagesTimestamps(lowerBound: message.id, excludeIds: Set([messageId]), timestamp: timestamp)
transaction.updateMessage(message.id, update: { currentMessage in
var flags = StoreMessageFlags(currentMessage.flags)
if let _ = result {
flags.remove(.Unsent)
flags.remove(.Sending)
} else {
flags = [.Failed]
}
var storeForwardInfo: StoreMessageForwardInfo?
if let forwardInfo = currentMessage.forwardInfo {
storeForwardInfo = StoreMessageForwardInfo(authorId: forwardInfo.author.id, sourceId: forwardInfo.source?.id, sourceMessageId: forwardInfo.sourceMessageId, date: forwardInfo.date, authorSignature: forwardInfo.authorSignature)
}
var updatedMedia = currentMessage.media
if let fromMedia = currentMessage.media.first, let encryptedFile = encryptedFile, let file = file {
var toMedia: Media?
if let fromMedia = fromMedia as? TelegramMediaFile {
let updatedFile = TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.CloudSecretFile, id: encryptedFile.id), reference: nil, resource: SecretFileMediaResource(fileId: encryptedFile.id, accessHash: encryptedFile.accessHash, containerSize: encryptedFile.size, decryptedSize: file.size, datacenterId: Int(encryptedFile.datacenterId), key: file.key), previewRepresentations: fromMedia.previewRepresentations, mimeType: fromMedia.mimeType, size: fromMedia.size, attributes: fromMedia.attributes)
toMedia = updatedFile
updatedMedia = [updatedFile]
}
if let toMedia = toMedia {
applyMediaResourceChanges(from: fromMedia, to: toMedia, postbox: postbox)
}
}
return .update(StoreMessage(id: currentMessage.id, globallyUniqueId: currentMessage.globallyUniqueId, groupingKey: currentMessage.groupingKey, timestamp: timestamp, flags: flags, tags: currentMessage.tags, globalTags: currentMessage.globalTags, localTags: currentMessage.localTags, forwardInfo: storeForwardInfo, authorId: currentMessage.author?.id, text: currentMessage.text, attributes: currentMessage.attributes, media: updatedMedia))
})
maybeReadSecretOutgoingMessage(transaction: transaction, index: MessageIndex(id: message.id, timestamp: timestamp))
}
}
} else {
replaceOutgoingOperationWithEmptyMessage(transaction: transaction, peerId: messageId.peerId, tagLocalIndex: tagLocalIndex, globallyUniqueId: arc4random64())
@@ -1211,12 +1211,12 @@ private func sendBoxedDecryptedMessage(postbox: Postbox, network: Network, peer:
}
}
return sendMessage
|> map { next -> Api.messages.SentEncryptedMessage? in
return next
}
|> `catch`{ _ in
return .single(nil)
}
|> map { next -> Api.messages.SentEncryptedMessage? in
return next
}
|> `catch`{ _ in
return .single(nil)
}
}
private func requestTerminateSecretChat(postbox: Postbox, network: Network, peerId: PeerId, tagLocalIndex: Int32, reportSpam: Bool) -> Signal<Void, NoError> {

View File

@@ -7,9 +7,17 @@ import Foundation
import SwiftSignalKit
#endif
public func topPeerActiveLiveLocationMessages(viewTracker: AccountViewTracker, peerId: PeerId) -> Signal<[Message], NoError> {
return viewTracker.aroundMessageHistoryViewForLocation(.peer(peerId), index: .upperBound, anchorIndex: .upperBound, count: 100, fixedCombinedReadStates: nil, tagMask: .liveLocation, orderStatistics: [])
|> map { (view, _, _) -> [Message] in
public func topPeerActiveLiveLocationMessages(viewTracker: AccountViewTracker, accountPeerId: PeerId, peerId: PeerId) -> Signal<(Peer?, [Message]), NoError> {
return viewTracker.aroundMessageHistoryViewForLocation(.peer(peerId), index: .upperBound, anchorIndex: .upperBound, count: 100, fixedCombinedReadStates: nil, tagMask: .liveLocation, orderStatistics: [], additionalData: [.peer(accountPeerId)])
|> map { (view, _, _) -> (Peer?, [Message]) in
var accountPeer: Peer?
for entry in view.additionalData {
if case let .peer(id, peer) = entry {
accountPeer = peer
break
}
}
let timestamp = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970)
var result: [Message] = []
for entry in view.entries {
@@ -25,6 +33,6 @@ public func topPeerActiveLiveLocationMessages(viewTracker: AccountViewTracker, p
}
}
}
return result
return (accountPeer, result)
}
}

View File

@@ -141,6 +141,14 @@ public final class PendingMessageManager {
updateUploadingPeerIds.insert(id.peerId)
context.sendDisposable.dispose()
context.uploadDisposable.dispose()
if context.status != nil {
context.status = nil
for subscriber in context.statusSubscribers.copyItems() {
subscriber(nil)
}
}
if context.statusSubscribers.isEmpty {
self.messageContexts.removeValue(forKey: id)
}

View File

@@ -21,6 +21,7 @@ public enum RequestEditMessageResult {
public enum RequestEditMessageError {
case generic
case restricted
}
public func requestEditMessage(account: Account, messageId: MessageId, text: String, media: RequestEditMessageMedia, entities: TextEntitiesMessageAttribute? = nil, disableUrlPreview: Bool = false) -> Signal<RequestEditMessageResult, RequestEditMessageError> {
@@ -125,7 +126,10 @@ public func requestEditMessage(account: Account, messageId: MessageId, text: Str
return .fail(error)
}
}
|> mapError { _ -> RequestEditMessageError in
|> mapError { error -> RequestEditMessageError in
if error.errorDescription.hasPrefix("CHAT_SEND_") && error.errorDescription.hasSuffix("_FORBIDDEN") {
return .restricted
}
return .generic
}
|> mapToSignal { result -> Signal<RequestEditMessageResult, RequestEditMessageError> in