Various Fixes

This commit is contained in:
Ilya Laktyushin 2021-02-16 12:35:10 +04:00
parent c526024286
commit a429218fb1
10 changed files with 2010 additions and 1977 deletions

View File

@ -6091,3 +6091,5 @@ Sorry for the inconvenience.";
"Conversation.AlsoClearCacheTitle" = "You can use \"clear cache\" to remove unnecessary media — and re-downloaded files if you need them again."; "Conversation.AlsoClearCacheTitle" = "You can use \"clear cache\" to remove unnecessary media — and re-downloaded files if you need them again.";
"Conversation.DeleteAllMessagesInChat" = "Are you sure you want to delete all messages in %@?"; "Conversation.DeleteAllMessagesInChat" = "Are you sure you want to delete all messages in %@?";
"InviteLinks.InviteLinkExpired" = "This invite link has expired.";

View File

@ -273,7 +273,7 @@ public final class DatePickerNode: ASDisplayNode {
struct State { struct State {
let minDate: Date let minDate: Date
let maxDate: Date let maxDate: Date
let date: Date let date: Date?
let displayingMonthSelection: Bool let displayingMonthSelection: Bool
let selectedMonth: Date let selectedMonth: Date
@ -349,7 +349,7 @@ public final class DatePickerNode: ASDisplayNode {
} }
} }
public var date: Date { public var date: Date? {
get { get {
return self.state.date return self.state.date
} }
@ -370,10 +370,10 @@ public final class DatePickerNode: ASDisplayNode {
public init(theme: DatePickerTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) { public init(theme: DatePickerTheme, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) {
self.theme = theme self.theme = theme
self.strings = strings self.strings = strings
self.state = State(minDate: telegramReleaseDate, maxDate: upperLimitDate, date: Date(), displayingMonthSelection: false, selectedMonth: monthForDate(Date())) self.state = State(minDate: telegramReleaseDate, maxDate: upperLimitDate, date: nil, displayingMonthSelection: false, selectedMonth: monthForDate(Date()))
self.timeTitleNode = ImmediateTextNode() self.timeTitleNode = ImmediateTextNode()
self.timeTitleNode.attributedText = NSAttributedString(string: "Time", font: Font.regular(17.0), textColor: theme.textColor) self.timeTitleNode.attributedText = NSAttributedString(string: strings.InviteLink_Create_TimeLimitExpiryTime, font: Font.regular(17.0), textColor: theme.textColor)
self.timePickerNode = TimePickerNode(theme: theme, dateTimeFormat: dateTimeFormat, date: self.state.date) self.timePickerNode = TimePickerNode(theme: theme, dateTimeFormat: dateTimeFormat, date: self.state.date)
@ -390,7 +390,7 @@ public final class DatePickerNode: ASDisplayNode {
self.pickerBackgroundNode.isUserInteractionEnabled = false self.pickerBackgroundNode.isUserInteractionEnabled = false
var monthChangedImpl: ((Date) -> Void)? var monthChangedImpl: ((Date) -> Void)?
self.pickerNode = MonthPickerNode(theme: theme, strings: strings, date: self.state.date, yearRange: yearRange(for: self.state), valueChanged: { date in self.pickerNode = MonthPickerNode(theme: theme, strings: strings, date: self.state.date ?? monthForDate(Date()), yearRange: yearRange(for: self.state), valueChanged: { date in
monthChangedImpl?(date) monthChangedImpl?(date)
}) })
self.pickerNode.minimumDate = self.state.minDate self.pickerNode.minimumDate = self.state.minDate
@ -503,7 +503,7 @@ public final class DatePickerNode: ASDisplayNode {
} }
} }
} }
self.pickerNode.date = self.state.date self.pickerNode.date = self.state.date ?? self.state.selectedMonth
self.timePickerNode.date = self.state.date self.timePickerNode.date = self.state.date
if let size = self.validLayout { if let size = self.validLayout {
@ -571,13 +571,23 @@ public final class DatePickerNode: ASDisplayNode {
let location = recognizer.location(in: monthNode.view) let location = recognizer.location(in: monthNode.view)
if let day = monthNode.dateAtPoint(location) { if let day = monthNode.dateAtPoint(location) {
let monthComponents = calendar.dateComponents([.month, .year], from: monthNode.month) let monthComponents = calendar.dateComponents([.month, .year], from: monthNode.month)
var currentComponents = calendar.dateComponents([.hour, .minute, .day, .month, .year], from: self.date)
currentComponents.year = monthComponents.year var dateComponents: DateComponents
currentComponents.month = monthComponents.month if let date = self.date {
currentComponents.day = Int(day) dateComponents = calendar.dateComponents([.hour, .minute, .day, .month, .year], from: date)
dateComponents.year = monthComponents.year
dateComponents.month = monthComponents.month
dateComponents.day = Int(day)
} else {
dateComponents = DateComponents()
dateComponents.year = monthComponents.year
dateComponents.month = monthComponents.month
dateComponents.day = Int(day)
dateComponents.hour = 11
dateComponents.minute = 0
}
if let date = calendar.date(from: currentComponents), date >= self.minimumDate && date < self.maximumDate { if let date = calendar.date(from: dateComponents), date >= self.minimumDate && date < self.maximumDate {
let updatedState = State(minDate: self.state.minDate, maxDate: self.state.maxDate, date: date, displayingMonthSelection: self.state.displayingMonthSelection, selectedMonth: monthNode.month) let updatedState = State(minDate: self.state.minDate, maxDate: self.state.maxDate, date: date, displayingMonthSelection: self.state.displayingMonthSelection, selectedMonth: monthNode.month)
self.updateState(updatedState, animated: false) self.updateState(updatedState, animated: false)
@ -999,10 +1009,10 @@ private final class TimePickerNode: ASDisplayNode {
private let inputNode: TimeInputNode private let inputNode: TimeInputNode
private let amPMSelectorNode: SegmentedControlNode private let amPMSelectorNode: SegmentedControlNode
var date: Date { var date: Date? {
didSet { didSet {
if let size = self.validLayout { if let size = self.validLayout {
self.updateLayout(size: size) let _ = self.updateLayout(size: size)
} }
} }
} }
@ -1013,7 +1023,7 @@ private final class TimePickerNode: ASDisplayNode {
private var validLayout: CGSize? private var validLayout: CGSize?
init(theme: DatePickerTheme, dateTimeFormat: PresentationDateTimeFormat, date: Date) { init(theme: DatePickerTheme, dateTimeFormat: PresentationDateTimeFormat, date: Date?) {
self.theme = theme self.theme = theme
self.dateTimeFormat = dateTimeFormat self.dateTimeFormat = dateTimeFormat
self.date = date self.date = date
@ -1026,9 +1036,15 @@ private final class TimePickerNode: ASDisplayNode {
self.colonNode = ImmediateTextNode() self.colonNode = ImmediateTextNode()
self.inputNode = TimeInputNode() self.inputNode = TimeInputNode()
let isPM: Bool
if let date = date {
let hours = calendar.component(.hour, from: date) let hours = calendar.component(.hour, from: date)
isPM = hours > 12
} else {
isPM = true
}
self.amPMSelectorNode = SegmentedControlNode(theme: theme.segmentedControlTheme, items: [SegmentedControlItem(title: "AM"), SegmentedControlItem(title: "PM")], selectedIndex: hours > 12 ? 1 : 0) self.amPMSelectorNode = SegmentedControlNode(theme: theme.segmentedControlTheme, items: [SegmentedControlItem(title: "AM"), SegmentedControlItem(title: "PM")], selectedIndex: isPM ? 1 : 0)
super.init() super.init()
@ -1039,8 +1055,11 @@ private final class TimePickerNode: ASDisplayNode {
self.addSubnode(self.amPMSelectorNode) self.addSubnode(self.amPMSelectorNode)
self.amPMSelectorNode.selectedIndexChanged = { index in self.amPMSelectorNode.selectedIndexChanged = { index in
guard let date = self.date else {
return
}
let hours = calendar.component(.hour, from: date) let hours = calendar.component(.hour, from: date)
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: self.date) var components = calendar.dateComponents([.year, .month, .day, .hour, .minute], from: date)
if index == 0 && hours >= 12 { if index == 0 && hours >= 12 {
components.hour = hours - 12 components.hour = hours - 12
} else if index == 1 && hours < 12 { } else if index == 1 && hours < 12 {
@ -1067,8 +1086,15 @@ private final class TimePickerNode: ASDisplayNode {
var contentSize = CGSize() var contentSize = CGSize()
let hours = Int32(calendar.component(.hour, from: self.date)) let hours: Int32
let minutes = Int32(calendar.component(.hour, from: self.date)) let minutes: Int32
if let date = self.date {
hours = Int32(calendar.component(.hour, from: date))
minutes = Int32(calendar.component(.hour, from: date))
} else {
hours = 11
minutes = 0
}
let string = stringForShortTimestamp(hours: hours, minutes: minutes, dateTimeFormat: self.dateTimeFormat).replacingOccurrences(of: " AM", with: "").replacingOccurrences(of: " PM", with: "") let string = stringForShortTimestamp(hours: hours, minutes: minutes, dateTimeFormat: self.dateTimeFormat).replacingOccurrences(of: " AM", with: "").replacingOccurrences(of: " PM", with: "")
self.textNode.attributedText = NSAttributedString(string: string, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor) self.textNode.attributedText = NSAttributedString(string: string, font: Font.with(size: 21.0, design: .regular, weight: .regular, traits: [.monospacedNumbers]), textColor: self.theme.textColor)

View File

@ -289,7 +289,7 @@ private func inviteLinkEditControllerEntries(invite: ExportedInvitation?, state:
} }
entries.append(.timeExpiryDate(presentationData.theme, time, state.pickingTimeLimit)) entries.append(.timeExpiryDate(presentationData.theme, time, state.pickingTimeLimit))
if state.pickingTimeLimit { if state.pickingTimeLimit {
entries.append(.timeCustomPicker(presentationData.theme, presentationData.dateTimeFormat, time ?? currentTime)) entries.append(.timeCustomPicker(presentationData.theme, presentationData.dateTimeFormat, time))
} }
entries.append(.timeInfo(presentationData.theme, presentationData.strings.InviteLink_Create_TimeLimitInfo)) entries.append(.timeInfo(presentationData.theme, presentationData.strings.InviteLink_Create_TimeLimitInfo))

View File

@ -53,7 +53,7 @@ private enum InviteLinkInviteEntryId: Hashable {
private enum InviteLinkInviteEntry: Comparable, Identifiable { private enum InviteLinkInviteEntry: Comparable, Identifiable {
case header(PresentationTheme, String, String) case header(PresentationTheme, String, String)
case mainLink(PresentationTheme, ExportedInvitation) case mainLink(PresentationTheme, ExportedInvitation?)
case manage(PresentationTheme, String, Bool) case manage(PresentationTheme, String, Bool)
var stableId: InviteLinkInviteEntryId { var stableId: InviteLinkInviteEntryId {
@ -122,9 +122,13 @@ private enum InviteLinkInviteEntry: Comparable, Identifiable {
return InviteLinkInviteHeaderItem(theme: theme, title: title, text: text) return InviteLinkInviteHeaderItem(theme: theme, title: title, text: text)
case let .mainLink(_, invite): case let .mainLink(_, invite):
return ItemListPermanentInviteLinkItem(context: interaction.context, presentationData: ItemListPresentationData(presentationData), invite: invite, count: 0, peers: [], displayButton: true, displayImporters: false, buttonColor: nil, sectionId: 0, style: .plain, copyAction: { return ItemListPermanentInviteLinkItem(context: interaction.context, presentationData: ItemListPresentationData(presentationData), invite: invite, count: 0, peers: [], displayButton: true, displayImporters: false, buttonColor: nil, sectionId: 0, style: .plain, copyAction: {
if let invite = invite {
interaction.copyLink(invite) interaction.copyLink(invite)
}
}, shareAction: { }, shareAction: {
if let invite = invite {
interaction.shareLink(invite) interaction.shareLink(invite)
}
}, contextAction: { node in }, contextAction: { node in
interaction.mainLinkContextAction(invite, node, nil) interaction.mainLinkContextAction(invite, node, nil)
}, viewAction: { }, viewAction: {
@ -319,6 +323,8 @@ public final class InviteLinkInviteController: ViewController {
self.backgroundColor = nil self.backgroundColor = nil
self.isOpaque = false self.isOpaque = false
let mainInvitePromise = ValuePromise<ExportedInvitation?>(nil)
self.interaction = InviteLinkInviteInteraction(context: context, mainLinkContextAction: { [weak self] invite, node, gesture in self.interaction = InviteLinkInviteInteraction(context: context, mainLinkContextAction: { [weak self] invite, node, gesture in
guard let node = node as? ContextExtractedContentContainingNode else { guard let node = node as? ContextExtractedContentContainingNode else {
return return
@ -385,7 +391,10 @@ public final class InviteLinkInviteController: ViewController {
dismissAction() dismissAction()
if let invite = invite { if let invite = invite {
let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(completed: { let _ = (revokePeerExportedInvitation(account: context.account, peerId: peerId, link: invite.link) |> deliverOnMainQueue).start(next: { result in
if let result = result, case let .replace(_, invite) = result {
mainInvitePromise.set(invite)
}
}) })
} }
}) })
@ -418,8 +427,8 @@ public final class InviteLinkInviteController: ViewController {
let peerView = context.account.postbox.peerView(id: peerId) let peerView = context.account.postbox.peerView(id: peerId)
let invites: Signal<PeerExportedInvitationsState, NoError> = .single(PeerExportedInvitationsState()) let invites: Signal<PeerExportedInvitationsState, NoError> = .single(PeerExportedInvitationsState())
self.disposable = (combineLatest(self.presentationDataPromise.get(), peerView, invites) self.disposable = (combineLatest(self.presentationDataPromise.get(), peerView, mainInvitePromise.get(), invites)
|> deliverOnMainQueue).start(next: { [weak self] presentationData, view, invites in |> deliverOnMainQueue).start(next: { [weak self] presentationData, view, interactiveMainInvite, invites in
if let strongSelf = self { if let strongSelf = self {
var entries: [InviteLinkInviteEntry] = [] var entries: [InviteLinkInviteEntry] = []
@ -432,17 +441,17 @@ public final class InviteLinkInviteController: ViewController {
entries.append(.header(presentationData.theme, presentationData.strings.InviteLink_InviteLink, helpText)) entries.append(.header(presentationData.theme, presentationData.strings.InviteLink_InviteLink, helpText))
let mainInvite: ExportedInvitation? let mainInvite: ExportedInvitation?
if let cachedData = view.cachedData as? CachedGroupData, let invite = cachedData.exportedInvitation { if let invite = interactiveMainInvite {
mainInvite = invite
} else if let cachedData = view.cachedData as? CachedGroupData, let invite = cachedData.exportedInvitation {
mainInvite = invite mainInvite = invite
} else if let cachedData = view.cachedData as? CachedChannelData, let invite = cachedData.exportedInvitation { } else if let cachedData = view.cachedData as? CachedChannelData, let invite = cachedData.exportedInvitation {
mainInvite = invite mainInvite = invite
} else { } else {
mainInvite = nil mainInvite = nil
} }
if let mainInvite = mainInvite {
entries.append(.mainLink(presentationData.theme, mainInvite))
}
entries.append(.mainLink(presentationData.theme, mainInvite))
entries.append(.manage(presentationData.theme, presentationData.strings.InviteLink_Manage, true)) entries.append(.manage(presentationData.theme, presentationData.strings.InviteLink_Manage, true))
let previousEntries = previousEntries.swap(entries) let previousEntries = previousEntries.swap(entries)
@ -459,11 +468,6 @@ public final class InviteLinkInviteController: ViewController {
strongSelf.updateFloatingHeaderOffset(offset: offset, transition: transition) strongSelf.updateFloatingHeaderOffset(offset: offset, transition: transition)
} }
} }
self.listNode.visibleBottomContentOffsetChanged = { [weak self] offset in
if case let .known(value) = offset, value < 40.0 {
}
}
self.addSubnode(self.dimNode) self.addSubnode(self.dimNode)
self.addSubnode(self.contentNode) self.addSubnode(self.contentNode)

View File

@ -223,7 +223,7 @@ public class ItemListDatePickerItemNode: ListViewItemNode, ItemListItemNode {
} }
datePickerNode.minimumDate = Date() datePickerNode.minimumDate = Date()
datePickerNode.date = item.date.flatMap { Date(timeIntervalSince1970: TimeInterval($0)) } ?? Date() datePickerNode.date = item.date.flatMap { Date(timeIntervalSince1970: TimeInterval($0)) }
let datePickerSize = CGSize(width: width, height: contentSize.height) let datePickerSize = CGSize(width: width, height: contentSize.height)
datePickerNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((params.width - datePickerSize.width) / 2.0), y: 0.0), size: datePickerSize) datePickerNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((params.width - datePickerSize.width) / 2.0), y: 0.0), size: datePickerSize)

View File

@ -87,7 +87,7 @@ public final class JoinLinkPreviewController: ViewController {
strongSelf.navigateToPeer(peerId, ChatPeekTimeout(deadline: deadline, linkData: strongSelf.link)) strongSelf.navigateToPeer(peerId, ChatPeekTimeout(deadline: deadline, linkData: strongSelf.link))
strongSelf.dismiss() strongSelf.dismiss()
case .invalidHash: case .invalidHash:
strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.GroupInfo_InvitationLinkDoesNotExist, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root)) strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: strongSelf.presentationData.strings.InviteLinks_InviteLinkExpired, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), in: .window(.root))
strongSelf.dismiss() strongSelf.dismiss()
} }
} }

View File

@ -761,7 +761,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina
let controller = PermissionController(context: context, splashScreen: true) let controller = PermissionController(context: context, splashScreen: true)
controller.navigationPresentation = .modal controller.navigationPresentation = .modal
controller.setState(.custom(icon: .animation("BroadcastGroup"), title: presentationData.strings.BroadcastGroups_IntroTitle, subtitle: nil, text: presentationData.strings.BroadcastGroups_IntroText, buttonTitle: presentationData.strings.BroadcastGroups_Convert, secondaryButtonTitle: presentationData.strings.BroadcastGroups_Cancel, footerText: nil), animated: false) controller.setState(.custom(icon: .animation("BroadcastGroup"), title: presentationData.strings.BroadcastGroups_IntroTitle, subtitle: nil, text: presentationData.strings.BroadcastGroups_IntroText, buttonTitle: presentationData.strings.BroadcastGroups_Convert, secondaryButtonTitle: presentationData.strings.BroadcastGroups_Cancel, footerText: nil), animated: false)
controller.proceed = { result in controller.proceed = { [weak controller] result in
let attributedTitle = NSAttributedString(string: presentationData.strings.BroadcastGroups_ConfirmationAlert_Title, font: Font.medium(17.0), textColor: presentationData.theme.actionSheet.primaryTextColor, paragraphAlignment: .center) let attributedTitle = NSAttributedString(string: presentationData.strings.BroadcastGroups_ConfirmationAlert_Title, font: Font.medium(17.0), textColor: presentationData.theme.actionSheet.primaryTextColor, paragraphAlignment: .center)
let body = MarkdownAttributeSet(font: Font.regular(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor) let body = MarkdownAttributeSet(font: Font.regular(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor)
let bold = MarkdownAttributeSet(font: Font.semibold(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor) let bold = MarkdownAttributeSet(font: Font.semibold(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor)
@ -778,7 +778,7 @@ public func channelPermissionsController(context: AccountContext, peerId origina
dismissToChatController?() dismissToChatController?()
}) })
})]) })])
presentControllerImpl?(alertController, nil) controller?.present(alertController, in: .window(.root))
} }
pushControllerImpl?(controller) pushControllerImpl?(controller)
}, openChannelExample: { }, openChannelExample: {

View File

@ -7089,7 +7089,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let controller = PermissionController(context: context, splashScreen: true) let controller = PermissionController(context: context, splashScreen: true)
controller.navigationPresentation = .modal controller.navigationPresentation = .modal
controller.setState(.custom(icon: .animation("BroadcastGroup"), title: presentationData.strings.BroadcastGroups_IntroTitle, subtitle: nil, text: presentationData.strings.BroadcastGroups_IntroText, buttonTitle: presentationData.strings.BroadcastGroups_Convert, secondaryButtonTitle: presentationData.strings.BroadcastGroups_Cancel, footerText: nil), animated: false) controller.setState(.custom(icon: .animation("BroadcastGroup"), title: presentationData.strings.BroadcastGroups_IntroTitle, subtitle: nil, text: presentationData.strings.BroadcastGroups_IntroText, buttonTitle: presentationData.strings.BroadcastGroups_Convert, secondaryButtonTitle: presentationData.strings.BroadcastGroups_Cancel, footerText: nil), animated: false)
controller.proceed = { result in controller.proceed = { [weak controller] result in
let attributedTitle = NSAttributedString(string: presentationData.strings.BroadcastGroups_ConfirmationAlert_Title, font: Font.medium(17.0), textColor: presentationData.theme.actionSheet.primaryTextColor, paragraphAlignment: .center) let attributedTitle = NSAttributedString(string: presentationData.strings.BroadcastGroups_ConfirmationAlert_Title, font: Font.medium(17.0), textColor: presentationData.theme.actionSheet.primaryTextColor, paragraphAlignment: .center)
let body = MarkdownAttributeSet(font: Font.regular(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor) let body = MarkdownAttributeSet(font: Font.regular(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor)
let bold = MarkdownAttributeSet(font: Font.semibold(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor) let bold = MarkdownAttributeSet(font: Font.semibold(13.0), textColor: presentationData.theme.actionSheet.primaryTextColor)
@ -7108,7 +7108,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
strongSelf.present(UndoOverlayController(presentationData: presentationData, content: .gigagroupConversion(text: presentationData.strings.BroadcastGroups_Success(presentationStringsFormattedNumber(participantsLimit, presentationData.dateTimeFormat.decimalSeparator)).0), elevatedLayout: false, action: { _ in return false }), in: .current) strongSelf.present(UndoOverlayController(presentationData: presentationData, content: .gigagroupConversion(text: presentationData.strings.BroadcastGroups_Success(presentationStringsFormattedNumber(participantsLimit, presentationData.dateTimeFormat.decimalSeparator)).0), elevatedLayout: false, action: { _ in return false }), in: .current)
}) })
})]) })])
strongSelf.present(alertController, in: .window(.root)) controller?.present(alertController, in: .window(.root))
} }
strongSelf.push(controller) strongSelf.push(controller)
})]) })])