61 lines
1.3 KiB
C++
61 lines
1.3 KiB
C++
#pragma once
|
|
|
|
#include "session.hpp"
|
|
|
|
#include <QObject>
|
|
#include <QSqlDatabase>
|
|
#include <QString>
|
|
#include <QVariantList>
|
|
|
|
namespace ZShell {
|
|
|
|
class Chat;
|
|
|
|
class ChatStore : public QObject {
|
|
Q_OBJECT
|
|
QML_ANONYMOUS
|
|
|
|
Q_PROPERTY(int count READ count NOTIFY countChanged)
|
|
Q_PROPERTY(QVariantList values READ values NOTIFY valuesChanged)
|
|
|
|
public:
|
|
explicit ChatStore(QObject* parent = nullptr);
|
|
~ChatStore();
|
|
|
|
[[nodiscard]] int count() const;
|
|
[[nodiscard]] QVariantList values() const;
|
|
[[nodiscard]] ChatSession* at(int index) const;
|
|
|
|
Q_INVOKABLE ChatSession* insert(int index = -1);
|
|
Q_INVOKABLE void remove(int index);
|
|
Q_INVOKABLE void remove(ChatSession* chat);
|
|
Q_INVOKABLE void move(int from, int to);
|
|
Q_INVOKABLE void clear();
|
|
|
|
[[nodiscard]] ChatSession* sessionById(const QString& id);
|
|
void persist(ChatSession* session);
|
|
void saveMeta(ChatSession* session);
|
|
void loadMessagesInto(ChatSession* session);
|
|
|
|
Q_SIGNALS:
|
|
void countChanged();
|
|
void valuesChanged();
|
|
|
|
private:
|
|
void openDb();
|
|
void load();
|
|
bool saveSession(ChatSession* session);
|
|
void sortAndNotify();
|
|
void removeSession(ChatSession* session);
|
|
void notify(const QList<ChatSession*>& before);
|
|
|
|
QList<ChatSession*> m_sessions;
|
|
QString m_connectionName;
|
|
|
|
[[nodiscard]] QSqlDatabase db() const;
|
|
|
|
friend class Chat;
|
|
};
|
|
|
|
} // namespace ZShell
|