File indexing completed on 2024-11-10 04:32:41

0001 /*
0002    SPDX-FileCopyrightText: 2018-2024 Laurent Montel <montel@kde.org>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include "libruqola_private_export.h"
0010 #include "managerdatapaths.h"
0011 #include "utils.h"
0012 #include <QHash>
0013 #include <QObject>
0014 #include <QSet>
0015 
0016 namespace RocketChatRestApi
0017 {
0018 class Connection;
0019 }
0020 
0021 class RocketChatAccount;
0022 class AvatarManager;
0023 class LIBRUQOLACORE_TESTS_EXPORT RocketChatCache : public QObject
0024 {
0025     Q_OBJECT
0026 public:
0027     explicit RocketChatCache(RocketChatAccount *account, QObject *parent = nullptr);
0028     ~RocketChatCache() override;
0029 
0030     void setRestApiConnection(RocketChatRestApi::Connection *restApi);
0031 
0032     [[nodiscard]] QString recordingVideoPath(const QString &accountName) const;
0033     [[nodiscard]] QString recordingImagePath(const QString &accountName) const;
0034     [[nodiscard]] QString avatarUrl(const Utils::AvatarInfo &info);
0035     void insertAvatarUrl(const QString &userId, const QUrl &url);
0036 
0037     void downloadFileFromServer(const QString &filename, bool needAuthentication, ManagerDataPaths::PathType type = ManagerDataPaths::Cache);
0038 
0039     [[nodiscard]] QUrl attachmentUrlFromLocalCache(const QString &url);
0040     void downloadFile(const QString &url, const QUrl &localFile);
0041     [[nodiscard]] QString avatarUrlFromCacheOnly(const QString &userId);
0042 
0043     void updateAvatar(const Utils::AvatarInfo &info);
0044     [[nodiscard]] bool attachmentIsInLocalCache(const QString &url);
0045     [[nodiscard]] QUrl faviconLogoUrlFromLocalCache(const QString &url);
0046     [[nodiscard]] QUrl previewUrlFromLocalCache(const QString &url);
0047     [[nodiscard]] QUrl avatarUrlFromLocalCache(const QString &url);
0048 Q_SIGNALS:
0049     void fileDownloaded(const QString &filePath, const QUrl &cacheImageUrl);
0050 
0051 private:
0052     Q_DISABLE_COPY(RocketChatCache)
0053     [[nodiscard]] QUrl urlFromLocalCache(const QString &url, bool needAuthentication, ManagerDataPaths::PathType type = ManagerDataPaths::Cache);
0054     [[nodiscard]] bool fileInCache(const QUrl &url);
0055     [[nodiscard]] QString fileCachePath(const QUrl &url, ManagerDataPaths::PathType type = ManagerDataPaths::Cache);
0056     void downloadAvatarFromServer(const Utils::AvatarInfo &info);
0057     void slotDataDownloaded(const QUrl &url, const QUrl &localFileUrl);
0058     void removeAvatar(const QString &avatarIdentifier);
0059     void loadAvatarCache();
0060     QHash<QString, QUrl> mAvatarUrl;
0061     QSet<QString> mFileInDownload;
0062     RocketChatAccount *const mAccount;
0063     AvatarManager *const mAvatarManager;
0064 };