File indexing completed on 2024-12-01 07:41:21

0001 /*
0002    SPDX-FileCopyrightText: 2017-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #pragma once
0007 
0008 #include "libruqola_private_export.h"
0009 #include "user.h"
0010 
0011 #include <QJsonArray>
0012 #include <QJsonObject>
0013 #include <QPixmap>
0014 #include <QUrl>
0015 
0016 namespace Utils
0017 {
0018 struct LIBRUQOLACORE_EXPORT QuotedRichTextInfo {
0019     QString richText;
0020     QString url;
0021     QString displayTime;
0022 };
0023 
0024 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QUrl generateServerUrl(const QString &url);
0025 [[nodiscard]] LIBRUQOLACORE_EXPORT QString presenceStatusToString(User::PresenceStatus status);
0026 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT User::PresenceStatus presenceStatusFromString(const QString &status);
0027 [[nodiscard]] LIBRUQOLACORE_EXPORT QString formatQuotedRichText(const QuotedRichTextInfo &info);
0028 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QString extractRoomUserFromUrl(QString url);
0029 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QString userIdFromDirectChannel(const QString &rid, const QString &userId);
0030 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT qint64 parseDate(const QString &key, const QJsonObject &o);
0031 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT qint64 parseIsoDate(const QString &key, const QJsonObject &o);
0032 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QString iconFromStatus(const QString &status);
0033 [[nodiscard]] LIBRUQOLACORE_EXPORT QString iconFromPresenceStatus(User::PresenceStatus status);
0034 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QJsonObject strToJsonObject(const QString &jsonString);
0035 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QJsonArray strToJsonArray(const QString &jsonString);
0036 [[nodiscard]] LIBRUQOLACORE_EXPORT QByteArray convertSha256Password(const QString &pwd);
0037 [[nodiscard]] LIBRUQOLACORE_EXPORT QString emojiFontName();
0038 [[nodiscard]] LIBRUQOLACORE_EXPORT QString displaytextFromPresenceStatus(User::PresenceStatus status);
0039 [[nodiscard]] LIBRUQOLACORE_EXPORT QString convertTextWithCheckMark(const QString &str);
0040 [[nodiscard]] LIBRUQOLACORE_EXPORT QString convertTextHeaders(const QString &str);
0041 
0042 /**
0043  * @brief Convert []() style Markdown URLS with proper HTML tags
0044  *
0045  * Also supports strings that already contain HTML links.
0046  *
0047  * Examples:
0048  *   "[NAME](<a href=\"LINK\">...</a>)" => "<a href="LINK">NAME</a>"
0049  *   "[NAME](LINK)"                   => "<a href="LINK">NAME</a>"
0050  */
0051 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QString convertTextWithUrl(const QString &str);
0052 
0053 enum class AvatarType {
0054     Unknown,
0055     Room,
0056     User,
0057     UserAndRoom,
0058 };
0059 
0060 struct LIBRUQOLACORE_EXPORT AvatarInfo {
0061     [[nodiscard]] bool isValid() const
0062     {
0063         return (avatarType != AvatarType::Unknown) && !identifier.isEmpty();
0064     }
0065 
0066     [[nodiscard]] bool operator==(const AvatarInfo &other) const
0067     {
0068         return etag == other.etag && identifier == other.identifier && avatarType == other.avatarType;
0069     }
0070 
0071     [[nodiscard]] QString generateAvatarIdentifier() const;
0072     QString etag;
0073     QString identifier;
0074     AvatarType avatarType = AvatarType::Unknown;
0075 };
0076 
0077 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QUrl avatarUrl(const QString &url, const AvatarInfo &avatarInfo);
0078 }
0079 Q_DECLARE_METATYPE(Utils::AvatarInfo)
0080 Q_DECLARE_TYPEINFO(Utils::AvatarInfo, Q_RELOCATABLE_TYPE);
0081 Q_DECLARE_TYPEINFO(Utils::QuotedRichTextInfo, Q_RELOCATABLE_TYPE);
0082 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const Utils::AvatarInfo &t);