mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Chat Import improvements
This commit is contained in:
@@ -17,9 +17,15 @@ import ConfettiEffect
|
||||
import TelegramUniversalVideoContent
|
||||
|
||||
public final class ChatImportActivityScreen: ViewController {
|
||||
enum ImportError {
|
||||
case generic
|
||||
case chatAdminRequired
|
||||
case invalidChatType
|
||||
}
|
||||
|
||||
private enum State {
|
||||
case progress(CGFloat)
|
||||
case error
|
||||
case error(ImportError)
|
||||
case done
|
||||
}
|
||||
|
||||
@@ -213,8 +219,17 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
switch self.state {
|
||||
case .progress:
|
||||
self.statusText.attributedText = NSAttributedString(string: "Please keep this window open\nduring the import.", font: Font.regular(17.0), textColor: self.presentationData.theme.list.itemSecondaryTextColor)
|
||||
case .error:
|
||||
self.statusText.attributedText = NSAttributedString(string: "An error occurred.", font: Font.regular(17.0), textColor: self.presentationData.theme.list.itemDestructiveColor)
|
||||
case let .error(error):
|
||||
let errorText: String
|
||||
switch error {
|
||||
case .chatAdminRequired:
|
||||
errorText = "You need to be an admin."
|
||||
case .invalidChatType:
|
||||
errorText = "You can't import this history in this type of chat."
|
||||
case .generic:
|
||||
errorText = "An error occurred."
|
||||
}
|
||||
self.statusText.attributedText = NSAttributedString(string: errorText, font: Font.regular(17.0), textColor: self.presentationData.theme.list.itemDestructiveColor)
|
||||
case .done:
|
||||
self.statusText.attributedText = NSAttributedString(string: "This chat has been imported\nsuccessfully.", font: Font.semibold(17.0), textColor: self.presentationData.theme.list.itemPrimaryTextColor)
|
||||
}
|
||||
@@ -427,10 +442,6 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
}
|
||||
|
||||
private func beginImport() {
|
||||
enum ImportError {
|
||||
case generic
|
||||
}
|
||||
|
||||
for (key, value) in self.pendingEntries {
|
||||
self.pendingEntries[key] = (value.0, 0.0)
|
||||
}
|
||||
@@ -459,8 +470,15 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
}
|
||||
|
||||
return ChatHistoryImport.initSession(account: context.account, peerId: peerId, file: mainEntry, mediaCount: Int32(otherEntries.count))
|
||||
|> mapError { _ -> ImportError in
|
||||
return .generic
|
||||
|> mapError { error -> ImportError in
|
||||
switch error {
|
||||
case .chatAdminRequired:
|
||||
return .chatAdminRequired
|
||||
case .invalidChatType:
|
||||
return .invalidChatType
|
||||
case .generic:
|
||||
return .generic
|
||||
}
|
||||
}
|
||||
}
|
||||
|> mapToSignal { session -> Signal<(String, Float), ImportError> in
|
||||
@@ -531,11 +549,11 @@ public final class ChatImportActivityScreen: ViewController {
|
||||
totalProgress = CGFloat(totalDoneBytes) / CGFloat(strongSelf.totalBytes)
|
||||
}
|
||||
strongSelf.controllerNode.updateState(state: .progress(totalProgress), animated: true)
|
||||
}, error: { [weak self] _ in
|
||||
}, error: { [weak self] error in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
}
|
||||
strongSelf.controllerNode.updateState(state: .error, animated: true)
|
||||
strongSelf.controllerNode.updateState(state: .error(error), animated: true)
|
||||
}, completed: { [weak self] in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
|
||||
@@ -958,7 +958,11 @@ class ChatListItemNode: ItemListRevealOptionsItemNode {
|
||||
} else if let message = messages.last, let author = message.author as? TelegramUser, let peer = itemPeer.chatMainPeer, !(peer is TelegramUser) {
|
||||
if let peer = peer as? TelegramChannel, case .broadcast = peer.info {
|
||||
} else if !displayAsMessage {
|
||||
peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
|
||||
if let forwardInfo = message.forwardInfo, forwardInfo.flags.contains(.isImported), let authorSignature = forwardInfo.authorSignature {
|
||||
peerText = authorSignature
|
||||
} else {
|
||||
peerText = author.id == account.peerId ? item.presentationData.strings.DialogList_You : author.displayTitle(strings: item.presentationData.strings, displayOrder: item.presentationData.nameDisplayOrder)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,8 @@ public enum ChatHistoryImport {
|
||||
|
||||
public enum InitImportError {
|
||||
case generic
|
||||
case chatAdminRequired
|
||||
case invalidChatType
|
||||
}
|
||||
|
||||
public enum ParsedInfo {
|
||||
@@ -63,8 +65,15 @@ public enum ChatHistoryImport {
|
||||
return .fail(.generic)
|
||||
}
|
||||
return account.network.request(Api.functions.messages.initHistoryImport(peer: inputPeer, file: inputFile, mediaCount: mediaCount))
|
||||
|> mapError { _ -> InitImportError in
|
||||
return .generic
|
||||
|> mapError { error -> InitImportError in
|
||||
switch error.errorDescription {
|
||||
case "CHAT_ADMIN_REQUIRED":
|
||||
return .chatAdminRequired
|
||||
case "IMPORT_PEER_TYPE_INVALID":
|
||||
return .invalidChatType
|
||||
default:
|
||||
return .generic
|
||||
}
|
||||
}
|
||||
|> map { result -> Session in
|
||||
switch result {
|
||||
|
||||
@@ -62,19 +62,15 @@ final class ChatMessageAvatarAccessoryItem: ListViewAccessoryItem {
|
||||
if abs(effectiveTimestamp - effectiveOtherTimestamp) >= 10 * 60 {
|
||||
return false
|
||||
}
|
||||
if let forwardInfo = self.forwardInfo, let otherForwardInfo = other.forwardInfo {
|
||||
if forwardInfo.flags.contains(.isImported) && forwardInfo.flags.contains(.isImported) == forwardInfo.flags.contains(.isImported) {
|
||||
if let authorSignature = forwardInfo.authorSignature, let otherAuthorSignature = otherForwardInfo.authorSignature {
|
||||
if authorSignature != otherAuthorSignature {
|
||||
return false
|
||||
}
|
||||
} else if let authorId = forwardInfo.author?.id, let otherAuthorId = other.forwardInfo?.author?.id {
|
||||
if authorId != otherAuthorId {
|
||||
return false
|
||||
}
|
||||
if let forwardInfo = self.forwardInfo, let otherForwardInfo = other.forwardInfo, forwardInfo.flags.contains(.isImported), otherForwardInfo.flags.contains(.isImported) {
|
||||
if let authorSignature = forwardInfo.authorSignature, let otherAuthorSignature = otherForwardInfo.authorSignature {
|
||||
if authorSignature != otherAuthorSignature {
|
||||
return false
|
||||
}
|
||||
} else if let authorId = forwardInfo.author?.id, let otherAuthorId = other.forwardInfo?.author?.id {
|
||||
if authorId != otherAuthorId {
|
||||
return false
|
||||
}
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
} else if let forwardInfo = self.forwardInfo, forwardInfo.flags.contains(.isImported) {
|
||||
return false
|
||||
|
||||
@@ -534,9 +534,16 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
|
||||
let addedWidth = intersection.width + 20
|
||||
fittedLayoutSize.width += addedWidth
|
||||
}
|
||||
if let statusFrameValue = statusFrame, let iconFrame = iconFrame, iconFrame.intersects(statusFrameValue) {
|
||||
fittedLayoutSize.height += 15.0
|
||||
statusFrame = statusFrameValue.offsetBy(dx: 0.0, dy: 15.0)
|
||||
if let statusFrameValue = statusFrame, let iconFrame = iconFrame {
|
||||
if iconFrame.intersects(statusFrameValue) {
|
||||
fittedLayoutSize.height += 15.0
|
||||
statusFrame = statusFrameValue.offsetBy(dx: 0.0, dy: 15.0)
|
||||
}
|
||||
} else if let statusFrameValue = statusFrame {
|
||||
if progressFrame.intersects(statusFrameValue) {
|
||||
fittedLayoutSize.height += 10.0
|
||||
statusFrame = statusFrameValue.offsetBy(dx: 0.0, dy: 15.0)
|
||||
}
|
||||
}
|
||||
|
||||
if (isAudio && !isVoice) || file.previewRepresentations.isEmpty {
|
||||
|
||||
Reference in New Issue
Block a user