File indexing completed on 2023-11-26 08:17:56

0001 /*
0002    SPDX-FileCopyrightText: 2017-2023 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 };
0058 
0059 struct LIBRUQOLACORE_EXPORT AvatarInfo {
0060     [[nodiscard]] bool isValid() const
0061     {
0062         return (avatarType != AvatarType::Unknown) && !identifier.isEmpty();
0063     }
0064 
0065     [[nodiscard]] bool operator==(const AvatarInfo &other) const
0066     {
0067         return etag == other.etag && identifier == other.identifier && avatarType == other.avatarType;
0068     }
0069 
0070     [[nodiscard]] QString generateAvatarIdentifier() const;
0071     QString etag;
0072     QString identifier;
0073     AvatarType avatarType = AvatarType::Unknown;
0074 };
0075 
0076 [[nodiscard]] LIBRUQOLACORE_TESTS_EXPORT QUrl avatarUrl(const QString &url, const AvatarInfo &avatarInfo);
0077 }
0078 Q_DECLARE_METATYPE(Utils::AvatarInfo)
0079 Q_DECLARE_TYPEINFO(Utils::AvatarInfo, Q_MOVABLE_TYPE);
0080 LIBRUQOLACORE_EXPORT QDebug operator<<(QDebug d, const Utils::AvatarInfo &t);