forked from CPP-Final-Project/Chat_Server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LocalStorage_Service.h
59 lines (46 loc) · 2.08 KB
/
LocalStorage_Service.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#pragma once
#ifndef LOCALSTORAGE_SERVICE_H
#define LOCALSTORAGE_SERVICE_H
#include <QObject>
#include <QMutex>
#include <QMap>
#include <QDir>
#include <QtCore>
#include <qthread.h>
#include <QtConcurrent>
#include <algorithm>
#include <plog/Log.h>
#include <QTimer>
#include "DBMessage.h"
#include "Message.h"
#include "DTOMessage.h"
#include "DTOMessage.h"
class LocalStorage_Service:
public QObject
{
Q_OBJECT
static QSharedPointer<LocalStorage_Service> shp_instance;
static QMutex mutex;
explicit LocalStorage_Service(QObject* object_ = nullptr);
QMap<quint32, QSet<QSharedPointer<DBEntity::DBMessage>>> message_storage;
public:
[[nodiscard]] QString searchForFiles(const QDateTime& date_, const quint32& room_) const;
QString searchForFiles(const QDateTime& date_, const quint32& room_, const bool& from_to_) const;
bool addLikeToMessage(const quint32& room_id_, const QUuid& message_id_, const QDateTime& message_datetime_, const QString& user_login_, const bool like_dislike_);
static QSet<QSharedPointer<DBEntity::DBMessage>> readMessagesFromDB(const QString& file_name_) ;
QList<QString> searchForFiles(const QDateTime& from_, const QDateTime& to_, const quint32& room_) const;
static QSharedPointer<LocalStorage_Service> getInstance(int minutes_ = 0);
LocalStorage_Service& operator=(const LocalStorage_Service&) = delete;
LocalStorage_Service(const LocalStorage_Service&) = delete;
signals:
void messageRetrieved(QList<QSharedPointer<DBEntity::DBMessage>> messages_);
void close();
public slots:
void addMessages(const QSet<QSharedPointer<User_Message>>& messages_, const quint32 room_id_);
void addMessage(const QSharedPointer<User_Message>& shp_message_, quint32 room_id_);
QSet<QSharedPointer<User_Message>> getMessages(const QDateTime& from_, const QDateTime& to_, const quint32& room_id_);
QSet<QSharedPointer<User_Message>> getMessages(const quint32& room_id_, const QDateTime& time_, bool from_to_, const quint32& pool_size_);
void saveAllMessages();
void safeExit() ;
};
#endif //LOCALSTORAGE_SERVICE_H