File indexing completed on 2023-11-26 08:17:53
0001 /* 0002 SPDX-FileCopyrightText: 2018-2023 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 "utils.h" 0011 #include <QHash> 0012 #include <QObject> 0013 #include <QSet> 0014 0015 namespace RocketChatRestApi 0016 { 0017 class Connection; 0018 } 0019 0020 class RocketChatAccount; 0021 class AvatarManager; 0022 class LIBRUQOLACORE_TESTS_EXPORT RocketChatCache : public QObject 0023 { 0024 Q_OBJECT 0025 public: 0026 explicit RocketChatCache(RocketChatAccount *account, QObject *parent = nullptr); 0027 ~RocketChatCache() override; 0028 0029 void setRestApiConnection(RocketChatRestApi::Connection *restApi); 0030 0031 [[nodiscard]] QString recordingVideoPath(const QString &accountName) const; 0032 [[nodiscard]] QString recordingImagePath(const QString &accountName) const; 0033 [[nodiscard]] QString avatarUrl(const Utils::AvatarInfo &info); 0034 void insertAvatarUrl(const QString &userId, const QUrl &url); 0035 0036 void downloadFileFromServer(const QString &filename, bool needAuthentication); 0037 0038 [[nodiscard]] QUrl attachmentUrlFromLocalCache(const QString &url); 0039 void downloadFile(const QString &url, const QUrl &localFile); 0040 [[nodiscard]] QString avatarUrlFromCacheOnly(const QString &userId); 0041 0042 void updateAvatar(const Utils::AvatarInfo &info); 0043 [[nodiscard]] bool attachmentIsInLocalCache(const QString &url); 0044 [[nodiscard]] QUrl faviconLogoUrlFromLocalCache(const QString &url); 0045 [[nodiscard]] QUrl urlFromLocalCache(const QString &url, bool needAuthentication); 0046 Q_SIGNALS: 0047 void fileDownloaded(const QString &filePath, const QUrl &cacheImageUrl); 0048 0049 private: 0050 Q_DISABLE_COPY(RocketChatCache) 0051 [[nodiscard]] bool fileInCache(const QUrl &url); 0052 [[nodiscard]] QString fileCachePath(const QUrl &url); 0053 void downloadAvatarFromServer(const Utils::AvatarInfo &info); 0054 void slotDataDownloaded(const QUrl &url, const QUrl &localFileUrl); 0055 void removeAvatar(const QString &avatarIdentifier); 0056 void loadAvatarCache(); 0057 QHash<QString, QUrl> mAvatarUrl; 0058 QSet<QString> mFileInDownload; 0059 RocketChatAccount *const mAccount; 0060 AvatarManager *mAvatarManager = nullptr; 0061 };