mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
no message
This commit is contained in:
@@ -194,13 +194,15 @@ func applyUpdateGroupMessages(postbox: Postbox, stateManager: AccountStateManage
|
|||||||
|
|
||||||
mapping.sort { $0.1 < $1.1 }
|
mapping.sort { $0.1 < $1.1 }
|
||||||
|
|
||||||
|
let latestPreviousId = mapping.map({ $0.0.id }).max()
|
||||||
|
|
||||||
var sentStickers: [TelegramMediaFile] = []
|
var sentStickers: [TelegramMediaFile] = []
|
||||||
var sentGifs: [TelegramMediaFile] = []
|
var sentGifs: [TelegramMediaFile] = []
|
||||||
|
|
||||||
var updatedGroupingKey: Int64?
|
var updatedGroupingKey: Int64?
|
||||||
|
|
||||||
if let latestIndex = mapping.last?.1 {
|
if let latestPreviousId = latestPreviousId, let latestIndex = mapping.last?.1 {
|
||||||
transaction.offsetPendingMessagesTimestamps(lowerBound: latestIndex.id, excludeIds: Set(mapping.map { $0.0.id }), timestamp: latestIndex.timestamp)
|
transaction.offsetPendingMessagesTimestamps(lowerBound: latestPreviousId, excludeIds: Set(mapping.map { $0.0.id }), timestamp: latestIndex.timestamp)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (message, _, updatedMessage) in mapping {
|
for (message, _, updatedMessage) in mapping {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ public enum AuthorizationCodeRequestError {
|
|||||||
case generic
|
case generic
|
||||||
case phoneLimitExceeded
|
case phoneLimitExceeded
|
||||||
case phoneBanned
|
case phoneBanned
|
||||||
|
case timeout
|
||||||
}
|
}
|
||||||
|
|
||||||
public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: String, apiId: Int32, apiHash: String) -> Signal<UnauthorizedAccount, AuthorizationCodeRequestError> {
|
public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: String, apiId: Int32, apiHash: String) -> Signal<UnauthorizedAccount, AuthorizationCodeRequestError> {
|
||||||
@@ -23,7 +24,8 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str
|
|||||||
let codeAndAccount = account.network.request(sendCode, automaticFloodWait: false)
|
let codeAndAccount = account.network.request(sendCode, automaticFloodWait: false)
|
||||||
|> map { result in
|
|> map { result in
|
||||||
return (result, account)
|
return (result, account)
|
||||||
} |> `catch` { error -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in
|
}
|
||||||
|
|> `catch` { error -> Signal<(Api.auth.SentCode, UnauthorizedAccount), MTRpcError> in
|
||||||
switch (error.errorDescription ?? "") {
|
switch (error.errorDescription ?? "") {
|
||||||
case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"):
|
case Regex("(PHONE_|USER_|NETWORK_)MIGRATE_(\\d+)"):
|
||||||
let range = error.errorDescription.range(of: "MIGRATE_")!
|
let range = error.errorDescription.range(of: "MIGRATE_")!
|
||||||
@@ -53,6 +55,7 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str
|
|||||||
return .generic
|
return .generic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|> timeout(20.0, queue: Queue.concurrentDefaultQueue(), alternate: .fail(.timeout))
|
||||||
|
|
||||||
return codeAndAccount
|
return codeAndAccount
|
||||||
|> mapToSignal { (sentCode, account) -> Signal<UnauthorizedAccount, AuthorizationCodeRequestError> in
|
|> mapToSignal { (sentCode, account) -> Signal<UnauthorizedAccount, AuthorizationCodeRequestError> in
|
||||||
@@ -67,7 +70,10 @@ public func sendAuthorizationCode(account: UnauthorizedAccount, phoneNumber: Str
|
|||||||
transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .confirmationCodeEntry(number: phoneNumber, type: SentAuthorizationCodeType(apiType: type), hash: phoneCodeHash, timeout: timeout, nextType: parsedNextType, termsOfService: termsOfService.flatMap(UnauthorizedAccountTermsOfService.init(apiTermsOfService:)))))
|
transaction.setState(UnauthorizedAccountState(isTestingEnvironment: account.testingEnvironment, masterDatacenterId: account.masterDatacenterId, contents: .confirmationCodeEntry(number: phoneNumber, type: SentAuthorizationCodeType(apiType: type), hash: phoneCodeHash, timeout: timeout, nextType: parsedNextType, termsOfService: termsOfService.flatMap(UnauthorizedAccountTermsOfService.init(apiTermsOfService:)))))
|
||||||
}
|
}
|
||||||
return account
|
return account
|
||||||
} |> mapError { _ -> AuthorizationCodeRequestError in return .generic }
|
}
|
||||||
|
|> mapError { _ -> AuthorizationCodeRequestError in
|
||||||
|
return .generic
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,16 @@ func augmentMediaWithReference(_ mediaReference: AnyMediaReference) -> Media {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func convertForwardedMediaForSecretChat(_ media: Media) -> Media {
|
||||||
|
if let file = media as? TelegramMediaFile {
|
||||||
|
return TelegramMediaFile(fileId: MediaId(namespace: Namespaces.Media.LocalFile, id: arc4random64()), partialReference: file.partialReference, resource: file.resource, previewRepresentations: file.previewRepresentations, mimeType: file.mimeType, size: file.size, attributes: file.attributes)
|
||||||
|
} else if let image = media as? TelegramMediaImage {
|
||||||
|
return TelegramMediaImage(imageId: MediaId(namespace: Namespaces.Media.LocalImage, id: arc4random64()), representations: image.representations, reference: image.reference, partialReference: image.partialReference)
|
||||||
|
} else {
|
||||||
|
return media
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private func filterMessageAttributesForOutgoingMessage(_ attributes: [MessageAttribute]) -> [MessageAttribute] {
|
private func filterMessageAttributesForOutgoingMessage(_ attributes: [MessageAttribute]) -> [MessageAttribute] {
|
||||||
return attributes.filter { attribute in
|
return attributes.filter { attribute in
|
||||||
switch attribute {
|
switch attribute {
|
||||||
@@ -449,10 +459,14 @@ func enqueueMessages(transaction: Transaction, account: Account, peerId: PeerId,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let augmentedMediaList = sourceMessage.media.map { media -> Media in
|
var augmentedMediaList = sourceMessage.media.map { media -> Media in
|
||||||
return augmentMediaWithReference(.message(message: MessageReference(sourceMessage), media: media))
|
return augmentMediaWithReference(.message(message: MessageReference(sourceMessage), media: media))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if peerId.namespace == Namespaces.Peer.SecretChat {
|
||||||
|
augmentedMediaList = augmentedMediaList.map(convertForwardedMediaForSecretChat)
|
||||||
|
}
|
||||||
|
|
||||||
storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, groupingKey: localGroupingKey, timestamp: timestamp, flags: flags, tags: tags, globalTags: globalTags, localTags: [], forwardInfo: forwardInfo, authorId: authorId, text: sourceMessage.text, attributes: attributes, media: augmentedMediaList))
|
storeMessages.append(StoreMessage(peerId: peerId, namespace: Namespaces.Message.Local, globallyUniqueId: randomId, groupingKey: localGroupingKey, timestamp: timestamp, flags: flags, tags: tags, globalTags: globalTags, localTags: [], forwardInfo: forwardInfo, authorId: authorId, text: sourceMessage.text, attributes: attributes, media: augmentedMediaList))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ public final class LoggingSettings: PreferencesEntry, Equatable {
|
|||||||
public let redactSensitiveData: Bool
|
public let redactSensitiveData: Bool
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true)
|
public static var defaultSettings = LoggingSettings(logToFile: true, logToConsole: true, redactSensitiveData: true)
|
||||||
#else
|
#else
|
||||||
public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true)
|
public static var defaultSettings = LoggingSettings(logToFile: false, logToConsole: false, redactSensitiveData: true)
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -253,7 +253,7 @@ public final class PendingMessageManager {
|
|||||||
private func beginSendingMessages(_ ids: [MessageId]) {
|
private func beginSendingMessages(_ ids: [MessageId]) {
|
||||||
assert(self.queue.isCurrent())
|
assert(self.queue.isCurrent())
|
||||||
|
|
||||||
for id in ids {
|
for id in ids.sorted() {
|
||||||
let messageContext: PendingMessageContext
|
let messageContext: PendingMessageContext
|
||||||
if let current = self.messageContexts[id] {
|
if let current = self.messageContexts[id] {
|
||||||
messageContext = current
|
messageContext = current
|
||||||
@@ -284,8 +284,6 @@ public final class PendingMessageManager {
|
|||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
assert(strongSelf.queue.isCurrent())
|
assert(strongSelf.queue.isCurrent())
|
||||||
|
|
||||||
var currentGroupId: Int64? = nil
|
|
||||||
|
|
||||||
for message in messages.filter({ !$0.flags.contains(.Sending) }).sorted(by: { $0.id < $1.id }) {
|
for message in messages.filter({ !$0.flags.contains(.Sending) }).sorted(by: { $0.id < $1.id }) {
|
||||||
guard let messageContext = strongSelf.messageContexts[message.id] else {
|
guard let messageContext = strongSelf.messageContexts[message.id] else {
|
||||||
continue
|
continue
|
||||||
@@ -300,16 +298,6 @@ public final class PendingMessageManager {
|
|||||||
} else {
|
} else {
|
||||||
messageContext.state = .waitingForUploadToStart(groupId: message.groupingKey, upload: contentUploadSignal)
|
messageContext.state = .waitingForUploadToStart(groupId: message.groupingKey, upload: contentUploadSignal)
|
||||||
}
|
}
|
||||||
|
|
||||||
if let _ = currentGroupId, message.groupingKey != currentGroupId {
|
|
||||||
currentGroupId = nil
|
|
||||||
} else {
|
|
||||||
currentGroupId = message.groupingKey
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if let currentGroupId = currentGroupId {
|
|
||||||
strongSelf.beginSendingGroupIfPossible(groupId: currentGroupId)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
@@ -439,8 +427,10 @@ public final class PendingMessageManager {
|
|||||||
}
|
}
|
||||||
self.addContextActivityIfNeeded(messageContext, peerId: id.peerId)
|
self.addContextActivityIfNeeded(messageContext, peerId: id.peerId)
|
||||||
|
|
||||||
|
let queue = self.queue
|
||||||
|
|
||||||
messageContext.uploadDisposable.set((uploadSignal
|
messageContext.uploadDisposable.set((uploadSignal
|
||||||
|> deliverOn(self.queue)
|
|> deliverOn(queue)
|
||||||
|> `catch` { [weak self] _ -> Signal<PendingMessageUploadedContentResult, NoError> in
|
|> `catch` { [weak self] _ -> Signal<PendingMessageUploadedContentResult, NoError> in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
let modify = strongSelf.postbox.transaction { transaction -> Void in
|
let modify = strongSelf.postbox.transaction { transaction -> Void in
|
||||||
@@ -458,6 +448,19 @@ public final class PendingMessageManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return .complete()
|
return .complete()
|
||||||
|
}
|
||||||
|
|> mapToSignal { result -> Signal<PendingMessageUploadedContentResult, NoError> in
|
||||||
|
if groupId != nil, case .content = result {
|
||||||
|
return Signal { subscriber in
|
||||||
|
queue.justDispatch {
|
||||||
|
subscriber.putNext(result)
|
||||||
|
subscriber.putCompletion()
|
||||||
|
}
|
||||||
|
return EmptyDisposable
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return .single(result)
|
||||||
|
}
|
||||||
}).start(next: { [weak self] next in
|
}).start(next: { [weak self] next in
|
||||||
if let strongSelf = self {
|
if let strongSelf = self {
|
||||||
assert(strongSelf.queue.isCurrent())
|
assert(strongSelf.queue.isCurrent())
|
||||||
@@ -475,9 +478,9 @@ public final class PendingMessageManager {
|
|||||||
if let current = strongSelf.messageContexts[id] {
|
if let current = strongSelf.messageContexts[id] {
|
||||||
strongSelf.beginSendingMessage(messageContext: current, messageId: id, groupId: groupId, content: content)
|
strongSelf.beginSendingMessage(messageContext: current, messageId: id, groupId: groupId, content: content)
|
||||||
strongSelf.updateWaitingUploads(peerId: id.peerId)
|
strongSelf.updateWaitingUploads(peerId: id.peerId)
|
||||||
//if let groupId = groupId {
|
if let groupId = groupId {
|
||||||
// strongSelf.beginSendingGroupIfPossible(groupId: groupId)
|
strongSelf.beginSendingGroupIfPossible(groupId: groupId)
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -522,10 +525,10 @@ public final class PendingMessageManager {
|
|||||||
case let .content(content):
|
case let .content(content):
|
||||||
if let current = strongSelf.messageContexts[contextId] {
|
if let current = strongSelf.messageContexts[contextId] {
|
||||||
strongSelf.beginSendingMessage(messageContext: current, messageId: contextId, groupId: groupId, content: content)
|
strongSelf.beginSendingMessage(messageContext: current, messageId: contextId, groupId: groupId, content: content)
|
||||||
strongSelf.updateWaitingUploads(peerId: peerId)
|
|
||||||
if let groupId = groupId {
|
if let groupId = groupId {
|
||||||
strongSelf.beginSendingGroupIfPossible(groupId: groupId)
|
strongSelf.beginSendingGroupIfPossible(groupId: groupId)
|
||||||
}
|
}
|
||||||
|
strongSelf.updateWaitingUploads(peerId: peerId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user