Chat Import fixes

This commit is contained in:
Ali 2021-01-25 01:52:48 +05:00
parent 0e21298773
commit 4b81b2cffa
5 changed files with 20 additions and 9 deletions

View File

@ -508,9 +508,14 @@ public final class ChatImportActivityScreen: ViewController {
} }
return ChatHistoryImport.uploadMedia(account: context.account, session: session, file: tempFile, fileName: fileName, mimeType: mimeTypeValue, type: mediaType) return ChatHistoryImport.uploadMedia(account: context.account, session: session, file: tempFile, fileName: fileName, mimeType: mimeTypeValue, type: mediaType)
|> mapError { _ -> ImportError in |> mapError { error -> ImportError in
switch error {
case .chatAdminRequired:
return .chatAdminRequired
case .generic:
return .generic return .generic
} }
}
|> map { progress -> (String, Float) in |> map { progress -> (String, Float) in
return (fileName, progress) return (fileName, progress)
} }

View File

@ -100,6 +100,7 @@ public enum ChatHistoryImport {
public enum UploadMediaError { public enum UploadMediaError {
case generic case generic
case chatAdminRequired
} }
public static func uploadMedia(account: Account, session: Session, file: TempBoxFile, fileName: String, mimeType: String, type: MediaType) -> Signal<Float, UploadMediaError> { public static func uploadMedia(account: Account, session: Session, file: TempBoxFile, fileName: String, mimeType: String, type: MediaType) -> Signal<Float, UploadMediaError> {
@ -136,9 +137,14 @@ public enum ChatHistoryImport {
return .fail(.generic) return .fail(.generic)
} }
return account.network.request(Api.functions.messages.uploadImportedMedia(peer: session.inputPeer, importId: session.id, fileName: fileName, media: inputMedia)) return account.network.request(Api.functions.messages.uploadImportedMedia(peer: session.inputPeer, importId: session.id, fileName: fileName, media: inputMedia))
|> mapError { _ -> UploadMediaError in |> mapError { error -> UploadMediaError in
switch error.errorDescription {
case "CHAT_ADMIN_REQUIRED":
return .chatAdminRequired
default:
return .generic return .generic
} }
}
|> mapToSignal { result -> Signal<Float, UploadMediaError> in |> mapToSignal { result -> Signal<Float, UploadMediaError> in
return .single(1.0) return .single(1.0)
} }

View File

@ -56,14 +56,14 @@ private func contentNodeMessagesAndClassesForItem(_ item: ChatMessageItem) -> ([
var isFile = false var isFile = false
inner: for media in message.media { inner: for media in message.media {
if let _ = media as? TelegramMediaImage { if let _ = media as? TelegramMediaImage {
if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported) { if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported), message.text.isEmpty {
messageWithCaptionToAdd = (message, itemAttributes) messageWithCaptionToAdd = (message, itemAttributes)
} }
result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default))) result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default)))
} else if let file = media as? TelegramMediaFile { } else if let file = media as? TelegramMediaFile {
let isVideo = file.isVideo || (file.isAnimated && file.dimensions != nil) let isVideo = file.isVideo || (file.isAnimated && file.dimensions != nil)
if isVideo { if isVideo {
if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported) { if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported), message.text.isEmpty {
messageWithCaptionToAdd = (message, itemAttributes) messageWithCaptionToAdd = (message, itemAttributes)
} }
result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default))) result.append((message, ChatMessageMediaBubbleContentNode.self, itemAttributes, BubbleItemAttributes(isAttachment: false, neighborType: .media, neighborSpacing: .default)))

View File

@ -542,7 +542,7 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
} else if let statusFrameValue = statusFrame { } else if let statusFrameValue = statusFrame {
if progressFrame.intersects(statusFrameValue) { if progressFrame.intersects(statusFrameValue) {
fittedLayoutSize.height += 10.0 fittedLayoutSize.height += 10.0
statusFrame = statusFrameValue.offsetBy(dx: 0.0, dy: 15.0) statusFrame = statusFrameValue.offsetBy(dx: 0.0, dy: 10.0)
} }
} }

View File

@ -571,7 +571,7 @@ public class ShareRootControllerImpl {
attemptSelectionImpl = { peer in attemptSelectionImpl = { peer in
var errorText: String? var errorText: String?
if let channel = peer as? TelegramChannel { if let channel = peer as? TelegramChannel {
if channel.hasPermission(.changeInfo) { if channel.hasPermission(.changeInfo), (channel.flags.contains(.isCreator) || channel.adminRights != nil) {
} else { } else {
errorText = "You need to be an admin of the group to import messages into it." errorText = "You need to be an admin of the group to import messages into it."
} }
@ -771,7 +771,7 @@ public class ShareRootControllerImpl {
var errorText: String? var errorText: String?
if let channel = peer as? TelegramChannel { if let channel = peer as? TelegramChannel {
if channel.hasPermission(.changeInfo) { if channel.hasPermission(.changeInfo), (channel.flags.contains(.isCreator) || channel.adminRights != nil) {
} else { } else {
errorText = "You need to be an admin of the group to import messages into it." errorText = "You need to be an admin of the group to import messages into it."
} }