From 3d866fe7a1099a19033e8007dc21c0d6972a0de9 Mon Sep 17 00:00:00 2001 From: phosit Date: Thu, 26 Mar 2026 18:08:04 +0100 Subject: [PATCH] Move ComputeTimestamp to XmppClient.cpp It is only used there. --- source/lobby/XmppClient.cpp | 55 +++++++++++++++++++------------------ source/lobby/XmppClient.h | 5 ---- 2 files changed, 29 insertions(+), 31 deletions(-) diff --git a/source/lobby/XmppClient.cpp b/source/lobby/XmppClient.cpp index 5d334f8e22..d18362c3cc 100644 --- a/source/lobby/XmppClient.cpp +++ b/source/lobby/XmppClient.cpp @@ -50,23 +50,50 @@ #include #include +namespace +{ //debug #if 1 #define DbgXMPP(x) #else #define DbgXMPP(x) std::cout << "XMPP DEBUG: " << x << std::endl; -static std::string tag_xml(const gloox::IQ& iq) +std::string tag_xml(const gloox::IQ& iq) { return iq.tag()->xml(); } #endif -static std::string tag_name(const gloox::IQ& iq) +std::string tag_name(const gloox::IQ& iq) { return iq.tag()->name(); } +/** + * Parse and return the timestamp of a historic chat message and return the current time for new chat messages. + * Historic chat messages are implement as DelayedDelivers as specified in XEP-0203. + * Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082. + * + * @returns Seconds since the epoch. + */ +std::time_t ComputeTimestamp(const gloox::Message& msg) +{ + // Only historic messages contain a timestamp! + if (!msg.when()) + return std::time(nullptr); + + // The locale is irrelevant, because the XMPP date format doesn't contain written month names + for (const std::string& format : std::vector{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" }) + { + UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp(), format, icu::Locale::getUS()); + if (dateTime) + return dateTime / 1000.0; + } + + return std::time(nullptr); +} +} // anonymous namespace + IXmppClient* IXmppClient::create(const ScriptInterface* scriptInterface, const std::string& sUsername, const std::string& sPassword, const std::string& sRoom, const std::string& sNick, const int historyRequestSize,bool regOpt) { return new XmppClient(scriptInterface, sUsername, sPassword, sRoom, sNick, historyRequestSize, regOpt); @@ -1300,30 +1327,6 @@ std::wstring XmppClient::GetRating(const std::string& nick) * Utilities * *****************************************************/ -/** - * Parse and return the timestamp of a historic chat message and return the current time for new chat messages. - * Historic chat messages are implement as DelayedDelivers as specified in XEP-0203. - * Hence, their timestamp MUST be in UTC and conform to the DateTime format XEP-0082. - * - * @returns Seconds since the epoch. - */ -std::time_t XmppClient::ComputeTimestamp(const gloox::Message& msg) -{ - // Only historic messages contain a timestamp! - if (!msg.when()) - return std::time(nullptr); - - // The locale is irrelevant, because the XMPP date format doesn't contain written month names - for (const std::string& format : std::vector{ "Y-M-d'T'H:m:sZ", "Y-M-d'T'H:m:s.SZ" }) - { - UDate dateTime = g_L10n.ParseDateTime(msg.when()->stamp(), format, icu::Locale::getUS()); - if (dateTime) - return dateTime / 1000.0; - } - - return std::time(nullptr); -} - void XmppClient::SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJIDStr) { DbgXMPP("SendStunEndpointToHost " << hostJIDStr); diff --git a/source/lobby/XmppClient.h b/source/lobby/XmppClient.h index 355f8fce7e..ac1cd0a7ff 100644 --- a/source/lobby/XmppClient.h +++ b/source/lobby/XmppClient.h @@ -111,11 +111,6 @@ public: void SendStunEndpointToHost(const std::string& ip, u16 port, const std::string& hostJID) override; - /** - * Convert gloox values to time. - */ - static std::time_t ComputeTimestamp(const gloox::Message& msg); - protected: /* Xmpp handlers */ /* MUC handlers */