-
Notifications
You must be signed in to change notification settings - Fork 25
/
telegramshareddatamanager.cpp
158 lines (129 loc) · 4.31 KB
/
telegramshareddatamanager.cpp
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#define DECLARE_INSERT_FNC(TYPE, VARIABLE) \
const QByteArray &_key = TelegramTools::identifier(VARIABLE); \
if(key) *key = _key; \
TYPE##Object *result = p->VARIABLE##s.value(_key); \
if(result) { \
*result = VARIABLE; \
return result; \
} \
result = new TYPE##Object(VARIABLE); \
connect(result, &TYPE##Object::destroyed, this, [this, _key](){ \
p->VARIABLE##s.remove(_key); \
}); \
p->VARIABLE##s[_key] = result; \
return result;
#define DECLARE_GET_FNC(VARIABLE) \
return p->VARIABLE##s.value(byte);
#define DECLARE_GET_ALL_FNC(VARIABLE) \
return p->VARIABLE##s.values();
#include "telegramshareddatamanager.h"
#include "telegramtools.h"
#include <QPointer>
#include <QByteArray>
#include <QHash>
class TelegramSharedDataManagerPrivate
{
public:
QHash<QByteArray, DialogObject*> dialogs;
QHash<QByteArray, TQmlMessageObject*> messages;
QHash<QByteArray, ChatObject*> chats;
QHash<QByteArray, UserObject*> users;
QHash<QByteArray, UserFullObject*> userFulls;
QHash<QByteArray, ChatFullObject*> chatFulls;
QHash<QByteArray, InputPeerObject*> peers;
QHash<QByteArray, StickerSetObject*> stickerSets;
QHash<QByteArray, DocumentObject*> documents;
};
TelegramSharedDataManager::TelegramSharedDataManager(QObject *parent) :
QObject(parent)
{
p = new TelegramSharedDataManagerPrivate;
}
TelegramSharedPointer<DialogObject> TelegramSharedDataManager::insertDialog(const Dialog &dialog, QByteArray *key)
{
DECLARE_INSERT_FNC(Dialog, dialog)
}
TelegramSharedPointer<TQmlMessageObject> TelegramSharedDataManager::insertMessage(const Message &message, QByteArray *key)
{
DECLARE_INSERT_FNC(TQmlMessage, message)
}
TelegramSharedPointer<ChatObject> TelegramSharedDataManager::insertChat(const Chat &chat, QByteArray *key)
{
DECLARE_INSERT_FNC(Chat, chat)
}
TelegramSharedPointer<UserObject> TelegramSharedDataManager::insertUser(const User &user, QByteArray *key)
{
DECLARE_INSERT_FNC(User, user)
}
TelegramSharedPointer<InputPeerObject> TelegramSharedDataManager::insertInputPeer(const InputPeer &peer, QByteArray *key)
{
DECLARE_INSERT_FNC(InputPeer, peer)
}
TelegramSharedPointer<UserFullObject> TelegramSharedDataManager::insertUserFull(const UserFull &userFull, QByteArray *key)
{
DECLARE_INSERT_FNC(UserFull, userFull)
}
TelegramSharedPointer<ChatFullObject> TelegramSharedDataManager::insertChatFull(const ChatFull &chatFull, QByteArray *key)
{
DECLARE_INSERT_FNC(ChatFull, chatFull)
}
TelegramSharedPointer<StickerSetObject> TelegramSharedDataManager::insertStickerSet(const StickerSet &stickerSet, QByteArray *key)
{
DECLARE_INSERT_FNC(StickerSet, stickerSet)
}
TelegramSharedPointer<DocumentObject> TelegramSharedDataManager::insertDocument(const Document &document, QByteArray *key)
{
DECLARE_INSERT_FNC(Document, document)
}
TelegramSharedPointer<DialogObject> TelegramSharedDataManager::getDialog(const QByteArray &byte)
{
DECLARE_GET_FNC(dialog)
}
TelegramSharedPointer<TQmlMessageObject> TelegramSharedDataManager::getMessage(const QByteArray &byte)
{
DECLARE_GET_FNC(message)
}
TelegramSharedPointer<ChatObject> TelegramSharedDataManager::getChat(const QByteArray &byte)
{
DECLARE_GET_FNC(chat)
}
TelegramSharedPointer<UserObject> TelegramSharedDataManager::getUser(const QByteArray &byte)
{
DECLARE_GET_FNC(user)
}
TelegramSharedPointer<UserFullObject> TelegramSharedDataManager::getUserFull(const QByteArray &byte)
{
DECLARE_GET_FNC(userFull)
}
TelegramSharedPointer<ChatFullObject> TelegramSharedDataManager::getChatFull(const QByteArray &byte)
{
DECLARE_GET_FNC(chatFull)
}
TelegramSharedPointer<StickerSetObject> TelegramSharedDataManager::getStickerSet(const QByteArray &byte)
{
DECLARE_GET_FNC(stickerSet)
}
TelegramSharedPointer<DocumentObject> TelegramSharedDataManager::getDocument(const QByteArray &byte)
{
DECLARE_GET_FNC(document)
}
QList<DialogObject *> TelegramSharedDataManager::dialogs()
{
DECLARE_GET_ALL_FNC(dialog)
}
QList<TQmlMessageObject *> TelegramSharedDataManager::messages()
{
DECLARE_GET_ALL_FNC(message)
}
QList<ChatObject *> TelegramSharedDataManager::chats()
{
DECLARE_GET_ALL_FNC(chat)
}
QList<UserObject *> TelegramSharedDataManager::users()
{
DECLARE_GET_ALL_FNC(user)
}
TelegramSharedDataManager::~TelegramSharedDataManager()
{
delete p;
}