File indexing completed on 2024-10-13 07:29:34

0001 // SPDX-FileCopyrightText: 2023 Carl Schwan <carl@carlschwan.eu>
0002 // SPDX-License-Identifier: LGPL-2.0-or-later
0003 
0004 #pragma once
0005 
0006 #include <KConfigGroup>
0007 #include <KSharedConfig>
0008 
0009 /**
0010  * Store and retrieve the last message of a room.
0011  */
0012 class RoomLastMessageProvider
0013 {
0014 public:
0015     /**
0016      * Get the global instance of RoomLastMessageProvider.
0017      */
0018     static RoomLastMessageProvider &self();
0019     ~RoomLastMessageProvider();
0020 
0021     /**
0022      * Check if we have the last message content for the specified roomId.
0023      */
0024     bool hasKey(const QString &roomId) const;
0025 
0026     /**
0027      * Read the last message content of the specified roomId.
0028      */
0029     QByteArray read(const QString &roomId) const;
0030 
0031     /**
0032      * Write the last message content for the specified roomId.
0033      */
0034     void write(const QString &roomId, const QByteArray &json);
0035 
0036 private:
0037     RoomLastMessageProvider();
0038 
0039     KSharedConfig::Ptr m_config;
0040     KConfigGroup m_configGroup;
0041 };