From 1b0cecd76d9aca06cfaa6e347d048e68879898b2 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Wed, 15 Mar 2023 00:51:25 +0400 Subject: [PATCH] Fix send when online tooltip display condition --- .../TelegramStringFormatting/Sources/DateFormat.swift | 8 ++++++++ submodules/TelegramUI/Sources/ChatController.swift | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/submodules/TelegramStringFormatting/Sources/DateFormat.swift b/submodules/TelegramStringFormatting/Sources/DateFormat.swift index c11a1c705b..759d3811ec 100644 --- a/submodules/TelegramStringFormatting/Sources/DateFormat.swift +++ b/submodules/TelegramStringFormatting/Sources/DateFormat.swift @@ -42,6 +42,14 @@ public func stringForMessageTimestamp(timestamp: Int32, dateTimeFormat: Presenta return stringForShortTimestamp(hours: timeinfo.tm_hour, minutes: timeinfo.tm_min, dateTimeFormat: dateTimeFormat) } +public func getDateTimeComponents(timestamp: Int32) -> (day: Int32, month: Int32, year: Int32, hour: Int32, minutes: Int32) { + var t: time_t = Int(timestamp) + var timeinfo = tm() + localtime_r(&t, &timeinfo); + + return (timeinfo.tm_mday, timeinfo.tm_mon + 1, timeinfo.tm_year, timeinfo.tm_hour, timeinfo.tm_min) +} + public func stringForMediumDate(timestamp: Int32, strings: PresentationStrings, dateTimeFormat: PresentationDateTimeFormat) -> String { var t: time_t = Int(timestamp) var timeinfo = tm() diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 10b0c69025..ad982e7b52 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -17539,7 +17539,8 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var sendWhenOnlineAvailable = false if let presence = peerView.peerPresences[peer.id] as? TelegramUserPresence, case let .present(until) = presence.status { let currentTime = Int32(CFAbsoluteTimeGetCurrent() + kCFAbsoluteTimeIntervalSince1970) - if currentTime > until { + let (_, _, _, hours, _) = getDateTimeComponents(timestamp: currentTime) + if currentTime > until + 60 * 30 && hours >= 0 && hours < 8 { sendWhenOnlineAvailable = true } }