-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathclient.h
205 lines (180 loc) · 6.97 KB
/
client.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
Hanghish
Copyright (C) 2015 Daniele Rogora
This file is part of Hangish.
Hangish is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Hangish is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Nome-Programma. If not, see <http://www.gnu.org/licenses/>
*/
#ifndef CLIENT_H
#define CLIENT_H
#include <QtCore/QScopedPointer>
#include <sailfishapp.h>
#include <QDateTime>
//#include "authenticator.h"
#include "oauth2auth.h"
#include "channel.h"
#include "rostermodel.h"
#include "conversationmodel.h"
#include "contactsmodel.h"
#include <QCryptographicHash>
#include "utils.h"
#include "notifier.h"
class MessageField;
class Client : public QObject
{
Q_OBJECT
//Authenticator *auth;
OAuth2Auth *auth;
QNetworkAccessManager *nam;
QList<QNetworkCookie> sessionCookies;
InitialData iData;
QString api_key, header_date, header_version, header_id, channel_path, clid, channel_ec_param, channel_prop_param, sync_timestamp;
User myself;
Channel *channel;
QNetworkCookie pvt;
private:
User getEntityById(QString cid);
bool connectedToInternet;
QSet<QNetworkReply *> pendingRequests;
QTimer timeoutTimer;
QString syncAllNewEventsString;
Notifier *notifier;
bool needInit;
bool needLogin;
bool needSync;
bool stuckWithNoNetwork;
bool pvtUpdateNeeded;
QDateTime needSyncTS;
QDateTime lastSetActive, lastSetPresence;
QList<OutgoingImage> outgoingImages;
QNetworkReply *imageBeingUploaded;
QString conversationBeingRemoved;
QString convNameBeingSet;
int notificationLevelBeingSet;
void sendImageMessage(QString convId, QString imgId, QString segments);
void performImageUpload(QString url);
bool appPaused;
void forceChannelCheckAndRestore();
bool initCompleted;
User parseMySelf(const QString &sreply);
void getPVTToken();
User getUserById(QString chatId);
User parseEntity(QList<MessageField> entity);
QList<User> parseClientEntities(QList<MessageField> entities);
QList<User> parseGroup(QList<MessageField> group);
QList<User> users;
QList<User> parseUsers(const QString &userString);
Conversation getConvById(QString cid);
RosterModel *rosterModel;
ConversationModel *conversationModel;
ContactsModel *contactsModel;
QString getRequestHeader();
void parseSelfConversationState(QList<MessageField> stateFields, Conversation& res);
void parseConversationAbstract(QList<MessageField> abstractFields, Conversation& res);
Conversation parseConversation(QList<MessageField> conversation);
void parseConversationState(MessageField conv);
void parseConversationLog(MessageField conv);
QList<Conversation> parseConversations(const QString &conv);
void followRedirection(QUrl url);
QByteArray getAuthHeader();
QNetworkReply * sendRequest(QString function, QString json);
void syncAllNewEvents(QDateTime timestamp);
void processCookies(QNetworkReply *reply);
public:
Client(RosterModel *prosterModel, ConversationModel *pconversationModel, ContactsModel *pcontactsModel);
void initChat(QString pvt);
Q_INVOKABLE void sendChatMessage(QString segments, QString conversationId);
Q_INVOKABLE void sendImage(QString segments, QString conversationId, QString filename);
Q_INVOKABLE QString getSelfChatId();
Q_INVOKABLE void deleteCookies();
Q_INVOKABLE void testNotification();
Q_INVOKABLE void forceChannelRestore();
Q_INVOKABLE void setActiveClient();
Q_INVOKABLE void setFocus(QString convId, int status);
Q_INVOKABLE void setTyping(QString convId, int status);
Q_INVOKABLE void setPresence(bool goingOffline);
Q_INVOKABLE void setAppPaused();
Q_INVOKABLE void setAppOpened();
Q_INVOKABLE QString getLastIncomingConversationId();
Q_INVOKABLE QString getLastIncomingConversationName();
Q_INVOKABLE QString getConversationName(QString convId);
Q_INVOKABLE void retrieveConversationLog(QString convId);
Q_INVOKABLE void renameConversation(QString convId, QString newName);
Q_INVOKABLE void leaveConversation(QString convId);
Q_INVOKABLE void deleteConversation(QString convId);
Q_INVOKABLE void changeNotificationsForConversation(QString convId, int level);
Q_INVOKABLE void deleteMessageWError(QString text);
Q_INVOKABLE void testFunction();
Q_INVOKABLE void sendPassword(QString uname, QString pwd);
Q_INVOKABLE void sendPin(QString pin);
Q_INVOKABLE bool isLoginNeeded();
Q_INVOKABLE void kill();
Q_INVOKABLE bool toggleDaemonize(bool t);
Q_INVOKABLE bool getDaemonize();
OAuth2Auth *getAuthenticator();
public slots:
Q_INVOKABLE void updateWatermark(QString convId);
void slotError(QNetworkReply::NetworkError err);
void notificationPushedSlot(QString convId);
void authenticationDone();
void initDone();
void networkReply();
void sendMessageReply();
void uploadImageReply();
void uploadPerformedReply();
void syncAllNewEventsReply();
void syncAllNewEventsDataArrval();
void setActiveClientReply();
void setTypingReply();
void setPresenceReply();
void updateWatermarkReply();
void pvtReply();
void channelLostSlot();
void channelRestoredSlot(QDateTime lastRec);
void connectivityChanged(QString a,QDBusVariant b);
void isTypingSlot(QString convId, QString chatId, int type);
void authFailedSlot(QString error);
void secondFactorNeededSlot();
void loginNeededSlot();
void updateClientId(QString newID);
void setFocusReply();
void cookieUpdateSlot(QList<QNetworkCookie> c);
void catchNotificationForCover(int num);
void catchDeletedNotifications();
void retrieveConversationLogReply();
void networkTimeout();
void renameConversationReply();
void leaveConversationReply();
void deleteConversationReply();
void changeNotificationsForConversationReply();
void renameConvSlot(QString convId, QString newname);
signals:
void initializing();
void initContacts();
void initConvs();
void imageUploadFailed();
void notificationPushed(QString convId);
void loginNeeded();
void messageSent();
void messageNotSent();
void conversationLoaded();
void initFinished();
void channelLost();
void channelRestored();
void isTyping(QString convid, QString uname, int status);
void showNotification(QString preview, QString summary, QString body, QString sender, int num, QString convId);
void authFailed(QString error);
void secondFactorNeeded();
void showNotificationForCover(int num);
void deletedNotifications();
void cancelAllActiveRequests();
};
#endif // CLIENT_H