Merge lp:~libqtelegram-team/telegram-app/dev-block-users into lp:telegram-app/dev

Proposed by Michał Karnicki
Status: Merged
Approved by: Giulio Collura
Approved revision: 193
Merged at revision: 189
Proposed branch: lp:~libqtelegram-team/telegram-app/dev-block-users
Merge into: lp:telegram-app/dev
Diff against target: 1843 lines (+923/-344)
24 files modified
lib/telegram.h (+1/-0)
lib/types/inputpeer.h (+3/-0)
qmlplugin/CMakeLists.txt (+4/-0)
qmlplugin/data.cpp (+94/-12)
qmlplugin/data.h (+11/-1)
qmlplugin/dbmanager.cpp (+15/-1)
qmlplugin/dbmanager.h (+1/-0)
qmlplugin/dbschema.h (+6/-0)
qmlplugin/models/blockedusersmodel.cpp (+74/-0)
qmlplugin/models/blockedusersmodel.h (+56/-0)
qmlplugin/models/dialogmodel.cpp (+61/-62)
qmlplugin/models/dialogmodel.h (+6/-0)
qmlplugin/models/groupmodel.cpp (+1/-3)
qmlplugin/models/profilemodel.cpp (+366/-197)
qmlplugin/models/profilemodel.h (+151/-66)
qmlplugin/rawapiclient.cpp (+12/-1)
qmlplugin/rawapiclient.h (+4/-1)
qmlplugin/rawapiservice.cpp (+2/-0)
qmlplugin/rawapiservice.h (+2/-0)
qmlplugin/telegramclient.cpp (+3/-0)
qmlplugin/telegramclient.h (+3/-0)
qmlplugin/telegramplugin.cpp (+4/-0)
qmlplugin/telegramservice.cpp (+35/-0)
qmlplugin/telegramservice.h (+8/-0)
To merge this branch: bzr merge lp:~libqtelegram-team/telegram-app/dev-block-users
Reviewer Review Type Date Requested Status
Giulio Collura Approve
Review via email: mp+254009@code.launchpad.net

Description of the change

Support for blocking users.
- ads user ProfileModel class
- ads blocking capability

To post a comment you must log in.
Revision history for this message
Michał Karnicki (karni) wrote :

// TODO replace getBlockedContacts with getFullUser

Intentionally left. I think the lib doesn't yet support getFullUser / FullUser type, and we've sat on this feature long already, so let's get this going, we can revisit this part later.

// TODO: Merge groupmodel into this class.
This (and couple lines commented in the profilemodel are left for when I merge groupmodel into the profilemodel class.

Revision history for this message
Giulio Collura (gcollura) wrote :

This is perfect too.
I tested it by:
 - already have a blocked contact
 - install this version
 - see that all the already blocked contacts are correctly showed
 - block/unblock sync with android (block from android, unblock from ubuntu and vice-versa)
Nicely done!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/telegram.h'
2--- lib/telegram.h 2015-03-03 21:38:35 +0000
3+++ lib/telegram.h 2015-03-27 11:52:28 +0000
4@@ -229,6 +229,7 @@
5 // Working with blacklist
6 void contactsBlockAnswer(qint64 id, bool ok);
7 void contactsUnblockAnswer(qint64 id, bool ok);
8+ void contactsBlockResult(qint64 id, bool ok);
9 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
10
11 // Working with messages
12
13=== modified file 'lib/types/inputpeer.h'
14--- lib/types/inputpeer.h 2014-10-03 10:34:51 +0000
15+++ lib/types/inputpeer.h 2015-03-27 11:52:28 +0000
16@@ -41,6 +41,9 @@
17 m_accessHash(0),
18 m_classType(classType) {}
19
20+ qint32 id() {
21+ return (m_classType == typeInputPeerChat) ? m_chatId : m_userId;
22+ }
23 void setUserId(qint32 userId) {
24 m_userId = userId;
25 }
26
27=== modified file 'qmlplugin/CMakeLists.txt'
28--- qmlplugin/CMakeLists.txt 2015-02-18 17:53:54 +0000
29+++ qmlplugin/CMakeLists.txt 2015-03-27 11:52:28 +0000
30@@ -40,6 +40,10 @@
31 models/dialogmodel.cpp
32 models/groupmembersmodel.h
33 models/groupmembersmodel.cpp
34+ models/profilemodel.h
35+ models/profilemodel.cpp
36+ models/blockedusersmodel.h
37+ models/blockedusersmodel.cpp
38 models/messagesmodel.cpp
39 models/contactsmodel.cpp
40 models/dialogsmodel.cpp
41
42=== modified file 'qmlplugin/data.cpp'
43--- qmlplugin/data.cpp 2015-03-17 11:39:18 +0000
44+++ qmlplugin/data.cpp 2015-03-27 11:52:28 +0000
45@@ -864,6 +864,75 @@
46 qCDebug(TG_PLUGIN_PROFILING) << "onContactsGetContactsAnswer - elapsed time:" << time.elapsed() << "ms";
47 }
48
49+void Data::putBlockedUsers(const QList<qint32> ids, const bool replace) {
50+ if (ids.length() == 0) return;
51+
52+ QSqlQuery query;
53+ if (replace) {
54+ query.prepare("DELETE FROM blocked_users");
55+ query.exec();
56+ }
57+ mDbManager.beginTransaction();
58+ query.prepare("REPLACE INTO blockedUsers VALUES(:id)");
59+ foreach (const qint32 &id, ids) {
60+ query.bindValue(":id", id);
61+ if (!query.exec()) {
62+ mDbManager.rollbackTransaction();
63+ return;
64+ }
65+ }
66+ mDbManager.finishTransaction();
67+}
68+
69+void Data::blockUser(qint32 id) {
70+ QSqlQuery query;
71+ query.prepare("REPLACE INTO blockedUsers VALUES(:id)");
72+ query.bindValue(":id", id);
73+ query.exec();
74+ Q_EMIT userBlocked(id);
75+}
76+
77+void Data::unblockUser(qint32 id) {
78+ QSqlQuery query;
79+ query.prepare("DELETE FROM blockedUsers WHERE uid = :id");
80+ query.bindValue(":id", id);
81+ query.exec();
82+ Q_EMIT userUnblocked(id);
83+}
84+
85+void Data::onGetBlockedContactsAnswer(qint64, qint32, QList<ContactBlocked> blocked, QList<User> users) {
86+ qCDebug(TG_PLUGIN_LOGIC) << "onGetBlockedContactsAnswer";
87+
88+ mDbManager.beginTransaction();
89+ Q_FOREACH (const User &user, users) {
90+ if (!insertOrUpdateUser(user)) {
91+ mDbManager.rollbackTransaction();
92+ return;
93+ }
94+ }
95+ QList<qint32> blockedUserIds;
96+ Q_FOREACH (const ContactBlocked &contact, blocked) {
97+ blockedUserIds.append(contact.userId());
98+ }
99+ putBlockedUsers(blockedUserIds, true);
100+ mDbManager.finishTransaction();
101+ Q_EMIT usersBlocked(blockedUserIds);
102+}
103+
104+void Data::onBlockContactAnswer(qint64 requestId, bool ok) {
105+ qint32 userId = mBlockRequests.take(requestId);
106+ if (userId != 0 && ok) {
107+ blockUser(userId);
108+ }
109+}
110+
111+void Data::onUnblockContactsAnswer(qint64 requestId, bool ok) {
112+ qint32 userId = mBlockRequests.take(requestId);
113+ if (userId != 0 && ok) {
114+ unblockUser(userId);
115+ }
116+}
117+
118 void Data::onMessagesGetHistoryAnswer(qint64, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users) {
119 QTime time;
120 time.start();
121@@ -954,7 +1023,9 @@
122 qint32 deleteChatId = mChatsToDelete.take(id);
123 if (deleteChatId != 0) {
124 qCDebug(TG_PLUGIN_LOGIC) << "deleting chat:" << deleteChatId;
125- deleteDialog(deleteChatId);
126+ TelegramService *service = static_cast<TelegramService *>(mServiceRef);
127+ qint32 id = service->deleteChatUser(deleteChatId, service->ourId());
128+ mChatsToDelete.insert(id, service->ourId());
129 }
130
131 clientState.setPts(pts);
132@@ -1469,15 +1540,21 @@
133 return;
134 }
135
136+ mDbManager.finishTransaction();
137+
138+ Q_FOREACH (const Chat &chat, chats) {
139+ Q_EMIT chatUpdated(chat.id());
140+ }
141+
142+ // handle chat deletion - after self has deleted the chat from UI
143+ qint32 chatId = mChatsToDelete.take(id);
144+ if (chatId != 0) {
145+ deleteChat(chatId);
146+ Q_EMIT chatDeleted(chatId);
147+ }
148+
149 // send signal with the action related message
150 MessageItem messageItem = getMessage(message.id());
151-
152- mDbManager.finishTransaction();
153-
154- Q_FOREACH (const Chat &chat, chats) {
155- Q_EMIT chatUpdated(chat.id());
156- }
157-
158 Q_EMIT messageAdded(messageItem);
159
160 qCDebug(TG_PLUGIN_PROFILING) << "onMessagesDeleteChatUsersAnswer - end:" << time.elapsed() << "ms";
161@@ -2593,6 +2670,14 @@
162 break;
163 }
164
165+ case Update::typeUpdateUserBlocked: {
166+ if (update.blocked()) {
167+ blockUser(update.userId());
168+ } else {
169+ unblockUser(update.userId());
170+ }
171+ }
172+
173 case Update::typeUpdateNotifySettings: {
174 NotifyPeer notifyPeer = update.peer();
175 PeerNotifySettings settings = update.notifySettings();
176@@ -6319,7 +6404,6 @@
177
178 bool Data::muteDialog(qint32 dialogId, bool muted) {
179 QSqlQuery query(mDbManager.database());
180-
181 query.prepare("UPDATE dialogs SET muted=:muted WHERE id=:id");
182 query.bindValue(":id", dialogId);
183 query.bindValue(":muted", muted);
184@@ -6334,7 +6418,6 @@
185
186 bool Data::muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted) {
187 QSqlQuery query(mDbManager.database());
188-
189 QString condition;
190 switch (peerType) {
191 case NotifyPeer::typeNotifyUsers:
192@@ -6350,7 +6433,7 @@
193 return false;
194 }
195
196- QString sql = QString("UPDATE dialogs SET muted=:muted").arg(condition);
197+ QString sql = QString("UPDATE dialogs SET muted=:muted").append(condition);
198 query.prepare(sql);
199 query.bindValue(":muted", muted);
200 if (!query.exec()) {
201@@ -6358,7 +6441,6 @@
202 << "for dialogs" << query.lastError() << query.lastQuery();
203 return false;
204 }
205-
206 return query.numRowsAffected() > 0;
207 }
208
209
210=== modified file 'qmlplugin/data.h'
211--- qmlplugin/data.h 2015-03-03 15:30:59 +0000
212+++ qmlplugin/data.h 2015-03-27 11:52:28 +0000
213@@ -191,7 +191,8 @@
214
215 void setMutingInProgress(qint64 requestId, qint32 peerId, bool muting);
216 QMap<qint64, qint32> mChatsToClearHistory;
217- QMap<qint32, qint32> mChatsToDelete;
218+ QMap<qint64, qint32> mChatsToDelete;
219+ QMap<qint64, qint32> mBlockRequests;
220
221 public:
222
223@@ -201,6 +202,8 @@
224
225 public Q_SLOTS:
226 void setSecretChatMessageTTL(qint32 chatId, qint32 ttlSeconds);
227+ void blockUser(qint32 id);
228+ void unblockUser(qint32 id);
229
230 protected:
231 void updateChats(const QList<Chat> &chats);
232@@ -221,6 +224,9 @@
233 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
234 void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName);
235 void dialogTitleUpdated(qint32 dialogId, const QString &title);
236+ void usersBlocked(QList<qint32> ids);
237+ void userBlocked(qint32 id);
238+ void userUnblocked(qint32 id);
239 void dialogMuted(qint32 dialogId, bool muted);
240 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
241
242@@ -359,6 +365,10 @@
243 void onMessagesGetFullChatAnswer(qint64 id, ChatFull chatFull, QList<Chat> chats, QList<User> users);
244 void onContactsImportContactsAnswer(qint64 id, QList<ImportedContact> importedContacts, QList<qint64> retryContacts, QList<User> users);
245 void onContactsGetContactsAnswer(qint64 requestId, bool modified, const QList<Contact> &contacts, const QList<User> &users);
246+ void putBlockedUsers(const QList<qint32> ids, const bool replace);
247+ void onGetBlockedContactsAnswer(qint64 requestId, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
248+ void onBlockContactAnswer(qint64 requestId, bool ok);
249+ void onUnblockContactsAnswer(qint64 requestId, bool ok);
250 void onMessagesGetHistoryAnswer(qint64 requestId, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users);
251 void onMessagesReadHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);
252 void onMessagesDeleteHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);
253
254=== modified file 'qmlplugin/dbmanager.cpp'
255--- qmlplugin/dbmanager.cpp 2015-03-23 10:47:25 +0000
256+++ qmlplugin/dbmanager.cpp 2015-03-27 11:52:28 +0000
257@@ -42,9 +42,10 @@
258 const qint32 VERSION_PROFILE_BIG_PHOTO = 11;
259 const qint32 VERSION_FORWARD_MESSAGES = 12;
260 const qint32 VERSION_MEDIA_DOCUMENTS = 13;
261+const qint32 VERSION_BLOCKED_USERS = 14;
262
263 // Update this line when creating new upgrade version.
264-const qint32 DATABASE_VERSION = VERSION_MEDIA_DOCUMENTS;
265+const qint32 DATABASE_VERSION = VERSION_BLOCKED_USERS;
266
267
268 DbManager::DbManager(QObject *parent) :
269@@ -169,6 +170,7 @@
270
271 queries << Schema::CREATE_THUMBNAILS;
272 queries << Schema::CREATE_USERS;
273+ queries << Schema::CREATE_BLOCKED_USERS;
274 queries << UpgradeSecretChats::CREATE_SECRET_CHATS;
275 queries << Schema::CREATE_DIALOGS;
276 queries << Schema::CREATE_CHATS;
277@@ -218,6 +220,7 @@
278 queries << Schema::DROP_CHATS;
279 queries << Schema::DROP_DIALOGS;
280 queries << UpgradeSecretChats::DROP_SECRET_CHATS;
281+ queries << Schema::DROP_BLOCKED_USERS;
282 queries << Schema::DROP_USERS;
283
284 bool result = executeSqlQueries(queries);
285@@ -310,6 +313,9 @@
286 if (!upgradeMediaDocuments()) break;
287 case VERSION_MEDIA_DOCUMENTS:
288 version = VERSION_MEDIA_DOCUMENTS;
289+ if (!upgradeBlockedUsers()) break;
290+ case VERSION_BLOCKED_USERS:
291+ version = VERSION_BLOCKED_USERS;
292
293 // Upgrade cases go here.
294 }
295@@ -509,6 +515,14 @@
296 return result;
297 }
298
299+bool DbManager::upgradeBlockedUsers() {
300+ qCDebug(LOG_DATABASE) << "Upgrading database: adding blocked users";
301+
302+ QStringList queries;
303+ queries << Schema::CREATE_BLOCKED_USERS;
304+ return executeSqlQueries(queries);
305+}
306+
307 bool DbManager::purgeButSecret() {
308 qCDebug(LOG_DATABASE) << "Purging database but secret chats data...";
309
310
311=== modified file 'qmlplugin/dbmanager.h'
312--- qmlplugin/dbmanager.h 2015-02-25 21:25:07 +0000
313+++ qmlplugin/dbmanager.h 2015-03-27 11:52:28 +0000
314@@ -67,6 +67,7 @@
315 bool upgradeProfilesBigPhotos();
316 bool upgradeForwardMessages();
317 bool upgradeMediaDocuments();
318+ bool upgradeBlockedUsers();
319
320 private:
321 QString mDatabasePath;
322
323=== modified file 'qmlplugin/dbschema.h'
324--- qmlplugin/dbschema.h 2015-03-10 15:32:48 +0000
325+++ qmlplugin/dbschema.h 2015-03-27 11:52:28 +0000
326@@ -259,6 +259,12 @@
327
328 const QString DROP_MESSAGE_ACTIONS("DROP TABLE IF EXISTS messageActions");
329
330+const QString CREATE_BLOCKED_USERS("CREATE TABLE blockedUsers(\n"
331+" uid INTEGER PRIMARY KEY\n"
332+")");
333+
334+const QString DROP_BLOCKED_USERS("DROP TABLE IF EXISTS blockedUsers");
335+
336 }
337
338 namespace MessageActionsRemovePhotoId {
339
340=== added file 'qmlplugin/models/blockedusersmodel.cpp'
341--- qmlplugin/models/blockedusersmodel.cpp 1970-01-01 00:00:00 +0000
342+++ qmlplugin/models/blockedusersmodel.cpp 2015-03-27 11:52:28 +0000
343@@ -0,0 +1,74 @@
344+/*
345+ * Copyright 2015 Canonical Ltd.
346+ *
347+ * This program is free software; you can redistribute it and/or modify
348+ * it under the terms of the GNU General Public License as published by
349+ * the Free Software Foundation; version 3.
350+ *
351+ * This program is distributed in the hope that it will be useful,
352+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
353+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
354+ * GNU General Public License for more details.
355+ *
356+ * You should have received a copy of the GNU General Public License
357+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
358+ */
359+
360+#include "blockedusersmodel.h"
361+
362+#include "types/tluser.h"
363+#include "types/tlinputpeer.h"
364+
365+BlockedUsersModel::BlockedUsersModel(QObject *parent) :
366+ Model(parent), mTelegramClient(NULL) {
367+}
368+
369+BlockedUsersModel::~BlockedUsersModel() {
370+ disconnect(mTelegramClient);
371+ mTelegramClient = NULL;
372+}
373+
374+void BlockedUsersModel::setup(TelegramClient *telegramClient) {
375+ Q_ASSERT(telegramClient != NULL);
376+
377+ if (mTelegramClient == NULL) {
378+ mTelegramClient = telegramClient;
379+ connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)),
380+ this, SLOT(refresh(QList<qint32>)));
381+ connect(mTelegramClient, SIGNAL(userBlocked(qint32)),
382+ this, SLOT(userBlocked(qint32)));
383+ connect(mTelegramClient, SIGNAL(userUnblocked(qint32)),
384+ this, SLOT(userUnblocked(qint32)));
385+ }
386+ refresh();
387+}
388+
389+void BlockedUsersModel::refresh(QList<qint32> ids) {
390+ if (mTelegramClient == NULL) return;
391+ mQueryString = QString(
392+ "SELECT id, type, "
393+ " (SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS photo, "
394+ " (firstName || \" \" || lastName) AS name, "
395+ " online, lastSeenOnline "
396+ "FROM users JOIN blockedUsers ON users.id = blockedUsers.uid");
397+ Model::refresh();
398+}
399+
400+void BlockedUsersModel::userBlocked(qint32 id) {
401+ refresh();
402+}
403+
404+void BlockedUsersModel::userUnblocked(qint32 id) {
405+ refresh();
406+}
407+
408+QHash<int, QByteArray> BlockedUsersModel::roleNames() const {
409+ QHash<int, QByteArray> roles;
410+ roles[IdRole] = "id";
411+ roles[TypeRole] = "type";
412+ roles[PhotoRole] = "photo";
413+ roles[NameRole] = "name";
414+ roles[OnlineRole] = "online";
415+ roles[LastSeenOnlineRole] = "lastSeenOnline";
416+ return roles;
417+}
418
419=== added file 'qmlplugin/models/blockedusersmodel.h'
420--- qmlplugin/models/blockedusersmodel.h 1970-01-01 00:00:00 +0000
421+++ qmlplugin/models/blockedusersmodel.h 2015-03-27 11:52:28 +0000
422@@ -0,0 +1,56 @@
423+/*
424+ * Copyright 2014 Canonical Ltd.
425+ *
426+ * This program is free software; you can redistribute it and/or modify
427+ * it under the terms of the GNU General Public License as published by
428+ * the Free Software Foundation; version 3.
429+ *
430+ * This program is distributed in the hope that it will be useful,
431+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
432+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
433+ * GNU General Public License for more details.
434+ *
435+ * You should have received a copy of the GNU General Public License
436+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
437+ */
438+
439+#ifndef BLOCKED_USERS_MODEL_H
440+#define BLOCKED_USERS_MODEL_H
441+
442+#include <QLoggingCategory>
443+
444+#include "model.h"
445+#include "telegramclient.h"
446+
447+class BlockedUsersModel : public Model
448+{
449+ Q_OBJECT
450+ Q_ENUMS(BlockedUsersRoles)
451+public:
452+
453+ enum BlockedUsersRoles {
454+ IdRole = Qt::UserRole,
455+ TypeRole,
456+ PhotoRole,
457+ NameRole,
458+ OnlineRole,
459+ LastSeenOnlineRole
460+ };
461+
462+ explicit BlockedUsersModel(QObject *parent = 0);
463+ ~BlockedUsersModel();
464+
465+ Q_INVOKABLE void setup(TelegramClient *telegramClient);
466+
467+public Q_SLOTS:
468+ void refresh(QList<qint32> ids = QList<qint32>());
469+ void userBlocked(qint32 id);
470+ void userUnblocked(qint32 id);
471+
472+private:
473+ TelegramClient *mTelegramClient;
474+
475+ QHash<qint32, QByteArray> roleNames() const;
476+};
477+
478+#endif // BLOCKED_USERS_MODEL_H
479
480=== modified file 'qmlplugin/models/dialogmodel.cpp'
481--- qmlplugin/models/dialogmodel.cpp 2015-02-04 22:29:48 +0000
482+++ qmlplugin/models/dialogmodel.cpp 2015-03-27 11:52:28 +0000
483@@ -25,6 +25,7 @@
484 mChatId(0),
485 mPeerId(0),
486 mPeerType((qint32) InputPeer::typeInputPeerContact),
487+ mAccessHash(0),
488 mWhoIsTyping(""),
489 mIsTyping(false),
490 mIsSecret(false),
491@@ -44,12 +45,13 @@
492 setChatId(0);
493 setPeerId(0);
494 setPeerType((qint32) InputPeer::typeInputPeerContact);
495+ setAccessHash(0);
496 setIsChat(false);
497 setIsTyping(false);
498 setIsSecret(false);
499 setState(0);
500- setTitle(QString());
501- setPhone(QString());
502+ setTitle("");
503+ setPhone("");
504 setTtl(0);
505 }
506
507@@ -76,9 +78,7 @@
508 // TODO karni: hook up live state
509 }
510
511- if (mTelegramClient != NULL) {
512- setChatId(chatId);
513- }
514+ setChatId(chatId);
515 }
516
517 void DialogModel::onMessageReceived(const MessageItem &message) {
518@@ -92,13 +92,10 @@
519 }
520
521 void DialogModel::setChatId(qint32 chatId) {
522- if (mChatId != chatId) {
523- mChatId = chatId;
524- if (chatId != 0) {
525- refreshDialogDetails(chatId);
526- }
527- Q_EMIT chatIdChanged(chatId);
528- }
529+ if (mChatId == chatId) return;
530+ mChatId = chatId;
531+ refreshDialogDetails(chatId);
532+ Q_EMIT chatIdChanged(chatId);
533 }
534
535 qint32 DialogModel::getPeerId() const {
536@@ -106,10 +103,9 @@
537 }
538
539 void DialogModel::setPeerId(qint32 peerId) {
540- if (mPeerId != peerId) {
541- mPeerId = peerId;
542- Q_EMIT peerIdChanged(peerId);
543- }
544+ if (mPeerId == peerId) return;
545+ mPeerId = peerId;
546+ Q_EMIT peerIdChanged(peerId);
547 }
548
549 qint32 DialogModel::getPeerType() const {
550@@ -117,10 +113,19 @@
551 }
552
553 void DialogModel::setPeerType(qint32 peerType) {
554- if (mPeerType != peerType) {
555- mPeerType = peerType;
556- Q_EMIT peerTypeChanged(peerType);
557- }
558+ if (mPeerType == peerType) return;
559+ mPeerType = peerType;
560+ Q_EMIT peerTypeChanged(peerType);
561+}
562+
563+qint64 DialogModel::getAccessHash() const {
564+ return mAccessHash;
565+}
566+
567+void DialogModel::setAccessHash(qint64 accessHash) {
568+ if (mAccessHash == accessHash) return;
569+ mAccessHash = accessHash;
570+ Q_EMIT accessHashChanged(accessHash);
571 }
572
573 bool DialogModel::getIsChat() const {
574@@ -128,10 +133,9 @@
575 }
576
577 void DialogModel::setIsChat(bool isChat) {
578- if (mIsChat != isChat) {
579- mIsChat = isChat;
580- Q_EMIT isChatChanged(isChat);
581- }
582+ if (mIsChat == isChat) return;
583+ mIsChat = isChat;
584+ Q_EMIT isChatChanged(isChat);
585 }
586
587 QString DialogModel::getWhoIsTyping() const {
588@@ -139,10 +143,9 @@
589 }
590
591 void DialogModel::setWhoIsTyping(QString whoIsTyping) {
592- if (mWhoIsTyping != whoIsTyping) {
593- mWhoIsTyping = whoIsTyping;
594- Q_EMIT whoIsTypingChanged(whoIsTyping);
595- }
596+ if (mWhoIsTyping == whoIsTyping) return;
597+ mWhoIsTyping = whoIsTyping;
598+ Q_EMIT whoIsTypingChanged(whoIsTyping);
599 }
600
601 bool DialogModel::getIsTyping() const {
602@@ -160,10 +163,9 @@
603 }
604
605 void DialogModel::setIsSecret(bool isSecret) {
606- if (mIsSecret != isSecret) {
607- mIsSecret = isSecret;
608- Q_EMIT isSecretChanged(isSecret);
609- }
610+ if (mIsSecret == isSecret) return;
611+ mIsSecret = isSecret;
612+ Q_EMIT isSecretChanged(isSecret);
613 }
614
615 qint32 DialogModel::getState() const {
616@@ -171,10 +173,9 @@
617 }
618
619 void DialogModel::setState(qint32 state) {
620- if (mState != state) {
621- mState = state;
622- Q_EMIT stateChanged(state);
623- }
624+ if (mState == state) return;
625+ mState = state;
626+ Q_EMIT stateChanged(state);
627 }
628
629 QString DialogModel::getTitle() const {
630@@ -182,10 +183,9 @@
631 }
632
633 void DialogModel::setTitle(const QString &title) {
634- if (mTitle != title) {
635- mTitle = title;
636- Q_EMIT titleChanged(title);
637- }
638+ if (mTitle == title) return;
639+ mTitle = title;
640+ Q_EMIT titleChanged(title);
641 }
642
643 QString DialogModel::getPhone() const {
644@@ -193,10 +193,9 @@
645 }
646
647 void DialogModel::setPhone(QString phone) {
648- if (mPhone != phone) {
649- mPhone = phone;
650- Q_EMIT phoneChanged(phone);
651- }
652+ if (mPhone == phone) return;
653+ mPhone = phone;
654+ Q_EMIT phoneChanged(phone);
655 }
656
657 qint32 DialogModel::getTtl() const {
658@@ -204,10 +203,9 @@
659 }
660
661 void DialogModel::setTtl(qint32 ttl) {
662- if (mTtl != ttl) {
663- mTtl = ttl;
664- Q_EMIT ttlChanged(ttl);
665- }
666+ if (mTtl == ttl) return;
667+ mTtl = ttl;
668+ Q_EMIT ttlChanged(ttl);
669 }
670
671 void DialogModel::refreshDialogDetails(qint32 chatId) {
672@@ -215,9 +213,12 @@
673 qCDebug(TG_PLUGIN_LOGIC) << "Querying dialog details" << chatId;
674
675 QSqlQuery query;
676- query.prepare(QString("SELECT id, isChat, name, thumbnail, members, userOnline, "
677- "lastSeenOnline, peerId, peerType, date, isSecret, state, ttl "
678- "FROM dialogsView WHERE id = %1").arg(QString::number(chatId)));
679+ query.prepare(QString("SELECT dialogsView.id, isChat, name, dialogsView.thumbnail, members, userOnline, "
680+ "dialogsView.lastSeenOnline, peerId, peerType, date, isSecret, state, ttl, "
681+ "coalesce(users.type, 0) as type, coalesce(users.accessHash, 0) as accessHash "
682+ "FROM dialogsView "
683+ " LEFT JOIN users ON dialogsView.id = users.id "
684+ "WHERE dialogsView.id = %1").arg(QString::number(chatId)));
685
686 // query.bindValue(":chatId", chatId); // no worky?
687
688@@ -243,14 +244,14 @@
689 }
690
691 setIsChat(false);
692-
693 setIsSecret(false);
694-
695 qint32 userType = query.value("type").toInt();
696 setPeerType(Tools::toInputPeerType((User::UserType) userType));
697-
698 setPeerId(chatId);
699-
700+ qint64 accessHash = query.value("accessHash").toLongLong();
701+ if (accessHash != 0) {
702+ setAccessHash(accessHash);
703+ }
704 setState(0);
705
706 QString firstName;
707@@ -276,24 +277,22 @@
708
709 bool isChat = query.value("isChat").toBool();
710 setIsChat(isChat);
711-
712 bool isSecret = query.value("isSecret").toBool();
713 setIsSecret(isSecret);
714-
715 if (isSecret) {
716 qint32 ttl = query.value("ttl").toInt();
717 setTtl(ttl);
718 }
719-
720 qint32 userType = query.value("peerType").toInt();
721 setPeerType(Tools::toInputPeerType((User::UserType) userType));
722-
723 qint32 peerId = query.value("peerId").toInt();
724- setPeerId(isSecret ? peerId : chatId); // *sigh*
725-
726+ setPeerId(isSecret ? peerId : chatId);
727+ qint64 accessHash = query.value("accessHash").toLongLong();
728+ if (accessHash != 0) {
729+ setAccessHash(accessHash);
730+ }
731 qint32 state = query.value("state").toInt();
732 setState(state);
733-
734 QString title = query.value("name").toString();
735 setTitle(title);
736
737
738=== modified file 'qmlplugin/models/dialogmodel.h'
739--- qmlplugin/models/dialogmodel.h 2015-02-04 19:01:38 +0000
740+++ qmlplugin/models/dialogmodel.h 2015-03-27 11:52:28 +0000
741@@ -32,6 +32,7 @@
742 Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged)
743 Q_PROPERTY(qint32 peerId READ getPeerId NOTIFY peerIdChanged)
744 Q_PROPERTY(qint32 peerType READ getPeerType NOTIFY peerTypeChanged)
745+ Q_PROPERTY(qint64 accessHash READ getAccessHash NOTIFY accessHashChanged)
746 Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged)
747 Q_PROPERTY(QString whoIsTyping READ getWhoIsTyping NOTIFY whoIsTypingChanged)
748 Q_PROPERTY(bool isTyping READ getIsTyping NOTIFY isTypingChanged)
749@@ -57,6 +58,9 @@
750 qint32 getPeerType() const;
751 void setPeerType(qint32 classType);
752
753+ qint64 getAccessHash() const;
754+ void setAccessHash(qint64 accessHash);
755+
756 bool getIsChat() const;
757 void setIsChat(bool isChat);
758
759@@ -95,6 +99,7 @@
760 void chatIdChanged(qint32 chatId);
761 void peerIdChanged(qint32 peerId);
762 void peerTypeChanged(qint32 peerType);
763+ void accessHashChanged(qint64 accessHash);
764 void peerChanged(qint32 peerId, qint32 peerType);
765 void isChatChanged(bool isChat);
766 void whoIsTypingChanged(QString who);
767@@ -111,6 +116,7 @@
768 qint32 mChatId;
769 qint32 mPeerId;
770 qint32 mPeerType;
771+ qint64 mAccessHash;
772 bool mIsChat;
773 bool mIsTyping;
774 QString mWhoIsTyping;
775
776=== modified file 'qmlplugin/models/groupmodel.cpp'
777--- qmlplugin/models/groupmodel.cpp 2015-02-16 18:07:13 +0000
778+++ qmlplugin/models/groupmodel.cpp 2015-03-27 11:52:28 +0000
779@@ -40,9 +40,7 @@
780 this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool)));
781 }
782
783- if (mTelegramClient != NULL) {
784- setChatId(chatId);
785- }
786+ setChatId(chatId);
787 }
788
789 qint32 GroupModel::getChatId() const {
790
791=== modified file 'qmlplugin/models/profilemodel.cpp'
792--- qmlplugin/models/profilemodel.cpp 2015-02-18 17:53:54 +0000
793+++ qmlplugin/models/profilemodel.cpp 2015-03-27 11:52:28 +0000
794@@ -1,220 +1,389 @@
795+/*
796+ * Copyright 2015 Canonical Ltd.
797+ *
798+ * This program is free software; you can redistribute it and/or modify
799+ * it under the terms of the GNU General Public License as published by
800+ * the Free Software Foundation; version 3.
801+ *
802+ * This program is distributed in the hope that it will be useful,
803+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
804+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
805+ * GNU General Public License for more details.
806+ *
807+ * You should have received a copy of the GNU General Public License
808+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
809+ */
810+
811 #include "profilemodel.h"
812-
813-Q_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL, "tg.models.profilemodel")
814-
815-ProfileModel::ProfileModel(QObject *parent) :
816- QObject(parent),
817- mTelegramClient(0),
818- mUserId(0),
819- mFirstName(""),
820- mLastName(""),
821- mThumbnail(""),
822- mBigPhoto(""),
823- mLastSeenOnline(0),
824- mOnline(false) {
825+#include "tools.h"
826+
827+ProfileModel::ProfileModel(QObject *parent) : QObject(parent),
828+ mTelegramClient(NULL), mDialogId(0), mUserId(0), mChatId(0), mIsSecret(true),
829+ mThumbnail(""), mPhoto(""), mTitle(""), mFirstName(""), mLastName(""),
830+ mPhone(""), mHasPhone(false), mLastSeen(0), mIsOnline(false),
831+ mIsMuted(false), mIsBlocked(false) {
832 }
833
834 ProfileModel::~ProfileModel() {
835+ disconnect(mTelegramClient);
836 mTelegramClient = 0;
837 }
838
839-void ProfileModel::reset() {
840- mTelegramClient = 0,
841- setUserId(0),
842- setFirstName("");
843- setLastName("");
844- setThumbnail("");
845- setBigPhoto("");
846- setLastSeenOnline(0);
847- setOnline(false);
848-}
849-
850-void ProfileModel::setup(TelegramClient *telegramClient, qint32 userId) {
851-
852- Q_ASSERT(telegramClient);
853-
854- if (!mTelegramClient) {
855+void ProfileModel::setup(TelegramClient *telegramClient, qint32 dialogId) {
856+ Q_ASSERT(telegramClient != NULL);
857+
858+ if (mTelegramClient == NULL) {
859 mTelegramClient = telegramClient;
860- connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)), SLOT(onContactNameUpdated(qint32,QString,QString)));
861- connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)), SLOT(onContactThumbnailUpdated(qint32,QString)));
862- connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)), SLOT(onContactBigPhotoUpdated(qint32,QString)));
863- connect(mTelegramClient, SIGNAL(contactStatusUpdated(qint32,bool,qint32)), SLOT(onContactStatusUpdated(qint32,bool,qint32)));
864- }
865-
866- if (mTelegramClient) {
867- setUserId(userId);
868- }
869-}
870-
871-void ProfileModel::refresh(qint32 userId) {
872-
873- if (userId != mUserId) {
874- return;
875- }
876-
877- QSqlQuery query;
878- query.prepare("SELECT firstName, lastName, phone, lastSeenOnline, online, "
879- "(SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS thumbnail, "
880- "(SELECT localPath FROM fileLocations WHERE rowid=bigPhoto) AS bigPhoto "
881- "FROM users "
882- "WHERE id=:id");
883- query.bindValue(":id", userId);
884- if (!query.exec()) {
885- qCCritical(TG_MODELS_PROFILEMODEL) << "Could not get profile data for user" << userId
886- << query.lastError() << query.lastQuery();
887- return;
888- }
889-
890- if (!query.next()) {
891- qCCritical(TG_MODELS_PROFILEMODEL) << "Could not find a register related to user" << userId;
892- return;
893- }
894-
895- setFirstName(query.value("firstName").toString());
896- setLastName(query.value("lastName").toString());
897- setPhone(query.value("phone").toString());
898- setThumbnail(query.value("thumbnail").toString());
899- setBigPhoto(query.value("bigPhoto").toString());
900- setLastSeenOnline(query.value("lastSeenOnline").toInt());
901- setOnline(query.value("online").toBool());
902-
903- Q_EMIT refreshed();
904-}
905-
906-void ProfileModel::onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName) {
907-
908- if (mUserId != userId) {
909- return;
910- }
911-
912- setFirstName(firstName);
913- setLastName(lastName);
914-}
915-
916-void ProfileModel::onContactThumbnailUpdated(qint32 userId, const QString &thumbnail) {
917-
918- if (mUserId != userId) {
919- return;
920- }
921- setThumbnail(thumbnail);
922-}
923-
924-void ProfileModel::onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto) {
925-
926- if (mUserId != userId) {
927- return;
928- }
929-
930- setBigPhoto(bigPhoto);
931-}
932-
933-void ProfileModel::onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline) {
934-
935- if (mUserId != userId) {
936- return;
937- }
938-
939- setOnline(online);
940- setLastSeenOnline(lastSeenOnline);
941-}
942-
943-qint32 ProfileModel::userId() const {
944+
945+ connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)),
946+ this, SLOT(contactNameUpdated(qint32,QString,QString)));
947+
948+ connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)),
949+ this, SLOT(thumbnailChanged(qint32,QString)));
950+ connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)),
951+ this, SLOT(photoChanged(qint32,QString)));
952+
953+ connect(mTelegramClient, SIGNAL(dialogMuted(qint32,bool)),
954+ this, SLOT(dialogMuted(qint32,bool)));
955+ connect(mTelegramClient, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)),
956+ this, SLOT(dialogsMuted(NotifyPeer::NotifyPeerType,bool)));
957+
958+ connect(mTelegramClient, SIGNAL(userBlocked(qint32)),
959+ this, SLOT(userBlocked(qint32)));
960+ connect(mTelegramClient, SIGNAL(userUnblocked(qint32)),
961+ this, SLOT(userUnblocked(qint32)));
962+ connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)),
963+ this, SLOT(usersBlocked(QList<qint32>)));
964+ }
965+
966+ setDialogId(dialogId);
967+}
968+
969+void ProfileModel::downloadPhoto() {
970+ qCDebug(TG_PLUGIN_LOGIC) << "downloading profile photo";
971+ mTelegramClient->downloadUserBigPhoto(mUserId);
972+}
973+
974+qint32 ProfileModel::getDialogId() const {
975+ return mDialogId;
976+}
977+
978+void ProfileModel::setDialogId(qint32 dialogId) {
979+ if (mDialogId == dialogId) return;
980+ mDialogId = dialogId;
981+ refreshProfile(dialogId);
982+ Q_EMIT dialogIdChanged(dialogId);
983+
984+ // TBD We'll probably want to call getFullUser and getFullChat (for chat members) here.
985+}
986+
987+qint32 ProfileModel::getUserId() const {
988 return mUserId;
989 }
990
991 void ProfileModel::setUserId(qint32 userId) {
992- if (mUserId != userId) {
993- mUserId = userId;
994- if (userId) {
995- refresh(userId);
996- }
997- Q_EMIT userIdChanged(userId);
998- }
999-}
1000-
1001-QString ProfileModel::firstName() const {
1002+ if (mUserId == userId) return;
1003+ mUserId = userId;
1004+ Q_EMIT userIdChanged(userId);
1005+}
1006+
1007+qint32 ProfileModel::getChatId() const {
1008+ return mChatId;
1009+}
1010+
1011+void ProfileModel::setChatId(qint32 chatId) {
1012+ if (mChatId == chatId) return;
1013+ mChatId = chatId;
1014+ Q_EMIT chatIdChanged(chatId);
1015+}
1016+
1017+void ProfileModel::setUserType(qint32 userType) {
1018+ if (mUserType == userType) return;
1019+ mUserType = userType;
1020+ Q_EMIT userTypeChanged(userType);
1021+
1022+ Q_EMIT existsChanged(getExists());
1023+}
1024+
1025+bool ProfileModel::getIsSecret() const {
1026+ return mIsSecret;
1027+}
1028+
1029+bool ProfileModel::getExists() const {
1030+ return ((User::UserType)mUserType) != User::typeUserDeleted;
1031+}
1032+
1033+void ProfileModel::setIsSecret(bool isSecret) {
1034+ if (mIsSecret == isSecret) return;
1035+ mIsSecret = isSecret;
1036+ Q_EMIT isSecretChanged(isSecret);
1037+}
1038+
1039+QString ProfileModel::getThumbnail() const {
1040+ return mThumbnail;
1041+}
1042+
1043+void ProfileModel::setThumbnail(const QString &thumbnail) {
1044+ if (mThumbnail == thumbnail) return;
1045+ mThumbnail = thumbnail;
1046+ Q_EMIT thumbnailChanged(thumbnail);
1047+}
1048+
1049+QString ProfileModel::getPhoto() const {
1050+ return mPhoto;
1051+}
1052+
1053+void ProfileModel::setPhoto(const QString &photo) {
1054+ if (mPhoto == photo) return;
1055+ mPhoto = photo;
1056+ Q_EMIT photoChanged(photo);
1057+}
1058+
1059+QString ProfileModel::getTitle() const {
1060+ return mTitle;
1061+}
1062+
1063+void ProfileModel::setTitle(const QString &title) {
1064+ if (mTitle == title) return;
1065+ mTitle = title;
1066+ Q_EMIT titleChanged(title);
1067+}
1068+
1069+QString ProfileModel::getFirstName() const {
1070 return mFirstName;
1071 }
1072
1073-void ProfileModel::setFirstName(const QString &firstName) {
1074- if (mFirstName != firstName) {
1075- mFirstName = firstName;
1076- Q_EMIT firstNameChanged(firstName);
1077- Q_EMIT fullNameChanged(fullName());
1078- }
1079-}
1080-
1081-QString ProfileModel::lastName() const {
1082+QString ProfileModel::getLastName() const {
1083 return mLastName;
1084 }
1085
1086-void ProfileModel::setLastName(const QString &lastName) {
1087- if (mLastName != lastName) {
1088- mLastName = lastName;
1089- Q_EMIT lastNameChanged(lastName);
1090- Q_EMIT fullNameChanged(fullName());
1091- }
1092-}
1093-
1094-QString ProfileModel::fullName() const {
1095- QString fullName = mFirstName;
1096- if (!mLastName.isEmpty()) {
1097- fullName += " " + mLastName;
1098- }
1099- return fullName;
1100-}
1101-
1102-QString ProfileModel::phone() const {
1103+QString ProfileModel::getPhone() const {
1104 return mPhone;
1105 }
1106
1107 void ProfileModel::setPhone(const QString &phone) {
1108- if (mPhone != phone) {
1109- mPhone = phone;
1110- Q_EMIT phoneChanged(phone);
1111- }
1112-}
1113-
1114-QString ProfileModel::thumbnail() const {
1115- return mThumbnail;
1116-}
1117-
1118-void ProfileModel::setThumbnail(const QString &thumbnail) {
1119- if (mThumbnail != thumbnail) {
1120- mThumbnail = thumbnail;
1121- Q_EMIT thumbnailChanged(thumbnail);
1122- }
1123-}
1124-
1125-QString ProfileModel::bigPhoto() const {
1126- return mBigPhoto;
1127-}
1128-
1129-void ProfileModel::setBigPhoto(const QString &bigPhoto) {
1130- if (mBigPhoto != bigPhoto) {
1131- mBigPhoto = bigPhoto;
1132- Q_EMIT bigPhotoChanged(bigPhoto);
1133- }
1134-}
1135-
1136-qint32 ProfileModel::lastSeenOnline() const {
1137- return mLastSeenOnline;
1138-}
1139-
1140-void ProfileModel::setLastSeenOnline(qint32 lastSeenOnline) {
1141- if (mLastSeenOnline != lastSeenOnline) {
1142- mLastSeenOnline = lastSeenOnline;
1143- Q_EMIT lastSeenOnlineChanged(lastSeenOnline);
1144- }
1145-}
1146-
1147-bool ProfileModel::online() const {
1148- return mOnline;
1149-}
1150-
1151-void ProfileModel::setOnline(bool online) {
1152- if (mOnline != online) {
1153- mOnline = online;
1154- Q_EMIT onlineChanged(online);
1155- }
1156+ if (mPhone == phone) return;
1157+ mPhone = phone;
1158+ mHasPhone = mPhone.length() > 0;
1159+ Q_EMIT phoneChanged(phone);
1160+ Q_EMIT hasPhoneChanged(mHasPhone);
1161+}
1162+
1163+bool ProfileModel::getHasPhone() const {
1164+ return mHasPhone;
1165+}
1166+
1167+qint32 ProfileModel::getLastSeen() const {
1168+ return mLastSeen;
1169+}
1170+
1171+void ProfileModel::setLastSeen(qint32 lastSeen) {
1172+ if (mLastSeen == lastSeen) return;
1173+ mLastSeen = lastSeen;
1174+ Q_EMIT lastSeenChanged(lastSeen);
1175+}
1176+
1177+bool ProfileModel::getIsOnline() const {
1178+ return mIsOnline;
1179+}
1180+
1181+void ProfileModel::setIsOnline(bool isOnline) {
1182+ if (mIsOnline == isOnline) return;
1183+ mIsOnline = isOnline;
1184+ Q_EMIT isOnlineChanged(isOnline);
1185+}
1186+
1187+bool ProfileModel::getIsMuted() const {
1188+ return mIsMuted;
1189+}
1190+
1191+void ProfileModel::setIsMuted(bool isMuted) {
1192+ if (mIsMuted == isMuted) return;
1193+ qCDebug(TG_PLUGIN_LOGIC) << "setIsMuted";
1194+ mIsMuted = isMuted;
1195+ Q_EMIT isMutedChanged(isMuted);
1196+}
1197+
1198+void ProfileModel::setIsBlocked(bool isBlocked) {
1199+ if (mIsBlocked == isBlocked) return;
1200+ qCDebug(TG_PLUGIN_LOGIC) << "setIsBlocked";
1201+ mIsBlocked = isBlocked;
1202+ Q_EMIT isBlockedChanged(isBlocked);
1203+}
1204+
1205+bool ProfileModel::getIsBlocked() const {
1206+ return mIsBlocked;
1207+}
1208+
1209+void ProfileModel::resetProfile() {
1210+ mDialogId = 0;
1211+ setChatId(0);
1212+ setUserId(0);
1213+
1214+ setThumbnail("");
1215+ setPhoto("");
1216+ setTitle("");
1217+ mFirstName = "";
1218+ mLastName = "";
1219+
1220+ setLastSeen(0);
1221+ setIsOnline(false);
1222+ setIsMuted(false);
1223+ setIsBlocked(false);
1224+}
1225+
1226+QString formatFullName(const QString &firstName, const QString &lastName) {
1227+ QString full(firstName);
1228+ if (full.length() > 0) {
1229+ full = full.append(" ");
1230+ }
1231+ return full.append(lastName);
1232+}
1233+
1234+void ProfileModel::refreshUserProfile() {
1235+ QSqlQuery query;
1236+ query.prepare(QString(
1237+ "SELECT "
1238+ " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = thumbnail) as thumbnail, "
1239+ " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = bigPhoto) AS photo, "
1240+ " users.id, phone, firstName, lastName, lastSeenOnline, online, "
1241+ " type, accessHash, "
1242+ " coalesce(dialogs.muted, 0) as muted, "
1243+ " coalesce(blockedUsers.uid, 0) as blocked "
1244+ "FROM users "
1245+ " LEFT JOIN dialogs ON users.id = dialogs.id "
1246+ " LEFT JOIN blockedUsers ON users.id = blockedUsers.uid "
1247+ "WHERE users.id = :id"));
1248+ query.bindValue(":id", mUserId);
1249+
1250+ if (!query.exec()) {
1251+ qCCritical(TG_PLUGIN_LOGIC) << "Failed to query user details!"
1252+ << query.lastError() << query.lastQuery();
1253+ resetProfile();
1254+ return;
1255+ } else if (query.next()) {
1256+ qint32 userType = query.value("type").toInt();
1257+ setUserType(userType);
1258+ mAccessHash = query.value("accessHash").toLongLong();
1259+
1260+ QString thumbnail = query.value("thumbnail").toString();
1261+ setThumbnail(thumbnail);
1262+ QString photo = query.value("photo").toString();
1263+ setPhoto(photo);
1264+ mFirstName = query.value("firstName").toString();
1265+ mLastName = query.value("lastName").toString();
1266+ QString title = formatFullName(mFirstName, mLastName);
1267+ setTitle(title);
1268+ QString phone = query.value("phone").toString();
1269+ setPhone(phone);
1270+ qint32 lastSeen = query.value("lastSeenOnline").toInt();
1271+ setLastSeen(lastSeen);
1272+ bool isOnline = query.value("online").toBool();
1273+ setIsOnline(isOnline);
1274+ bool isMuted = query.value("muted").toBool();
1275+ setIsMuted(isMuted);
1276+ bool isBlocked = query.value("blocked").toInt() != 0;
1277+ setIsBlocked(isBlocked);
1278+
1279+ /*
1280+ // TODO replace getBlockedContacts with getFullUser
1281+ InputUser::InputUserType inputUserType = Tools::toInputUserType(mUserType);
1282+ InputUser inputUser(inputUserType);
1283+ inputUser.setUserId(mUserId);
1284+ if (mAccessHash != 0) {
1285+ inputUser.setAccessHash(mAccessHash);
1286+ }
1287+ mTelegramClient->getFullUser(inputUser);
1288+ */
1289+ mTelegramClient->getBlockedContacts();
1290+ }
1291+}
1292+
1293+void ProfileModel::refreshGroupProfile() {
1294+// TODO: Merge groupmodel into this class.
1295+}
1296+
1297+void ProfileModel::refreshProfile(qint32 dialogId) {
1298+ if (mDialogId != dialogId) return;
1299+ qCDebug(TG_PLUGIN_LOGIC) << "Refreshing profile for dialog:" << dialogId;
1300+
1301+ QSqlQuery query;
1302+ query.prepare(QString("SELECT isChat, isSecret, peerId FROM dialogsView WHERE id = :id"));
1303+ query.bindValue(":id", dialogId);
1304+
1305+ if (!query.exec()) {
1306+ qCCritical(TG_PLUGIN_LOGIC) << "Failed to query profile type!"
1307+ << query.lastError() << query.lastQuery();
1308+ resetProfile();
1309+ return;
1310+ }
1311+
1312+ bool isChat = false;
1313+ if (query.next()) {
1314+ isChat = query.value("isChat").toBool();
1315+ if (isChat) {
1316+ setChatId(dialogId);
1317+ } else {
1318+ bool isSecret = query.value("isSecret").toBool();
1319+ setIsSecret(isSecret);
1320+ setUserId(isSecret ? query.value("peerId").toInt() : dialogId);
1321+ }
1322+ } else {
1323+ setUserId(dialogId);
1324+ }
1325+
1326+ if (isChat) {
1327+ refreshGroupProfile();
1328+ } else {
1329+ refreshUserProfile();
1330+ }
1331+}
1332+
1333+void ProfileModel::contactNameUpdated(qint32 userId, QString firstName, QString lastName) {
1334+ if (mUserId != userId) return;
1335+
1336+ mFirstName = firstName;
1337+ mLastName = lastName;
1338+ if (lastName.length() == 0) {
1339+ setTitle(firstName);
1340+ } else {
1341+ setTitle(firstName.append(" ").append(lastName));
1342+ }
1343+}
1344+
1345+void ProfileModel::thumbnailChanged(qint32 dialogId, QString thumbnail) {
1346+ if (mDialogId != dialogId) return;
1347+ setThumbnail(thumbnail);
1348+}
1349+
1350+void ProfileModel::photoChanged(qint32 dialogId, QString photo) {
1351+ if (mDialogId != dialogId) return;
1352+ setPhoto(photo);
1353+}
1354+
1355+void ProfileModel::dialogMuted(qint32 dialogId, bool muted) {
1356+ if (mDialogId != dialogId) return;
1357+ setIsMuted(muted);
1358+}
1359+
1360+void ProfileModel::dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted) {
1361+ if (notifyType == NotifyPeer::typeNotifyAll ||
1362+ notifyType == NotifyPeer::typeNotifyChats) {
1363+ setIsMuted(muted);
1364+ }
1365+}
1366+
1367+void ProfileModel::usersBlocked(QList<qint32> ids) {
1368+ bool isBlocked = ids.indexOf(mUserId) != -1;
1369+ setIsBlocked(isBlocked);
1370+}
1371+
1372+void ProfileModel::userBlocked(qint32 uid) {
1373+ if (mUserId != uid) return;
1374+ setIsBlocked(true);
1375+}
1376+
1377+void ProfileModel::userUnblocked(qint32 uid) {
1378+ if (mUserId != uid) return;
1379+ setIsBlocked(false);
1380 }
1381
1382=== modified file 'qmlplugin/models/profilemodel.h'
1383--- qmlplugin/models/profilemodel.h 2015-02-18 17:53:54 +0000
1384+++ qmlplugin/models/profilemodel.h 2015-03-27 11:52:28 +0000
1385@@ -1,84 +1,169 @@
1386-#ifndef PROFILEMODEL_H
1387-#define PROFILEMODEL_H
1388+/*
1389+ * Copyright 2015 Canonical Ltd.
1390+ *
1391+ * This program is free software; you can redistribute it and/or modify
1392+ * it under the terms of the GNU General Public License as published by
1393+ * the Free Software Foundation; version 3.
1394+ *
1395+ * This program is distributed in the hope that it will be useful,
1396+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
1397+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1398+ * GNU General Public License for more details.
1399+ *
1400+ * You should have received a copy of the GNU General Public License
1401+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
1402+ */
1403+
1404+#ifndef PROFILE_MODEL_H
1405+#define PROFILE_MODEL_H
1406
1407 #include <QObject>
1408-#include <QLoggingCategory>
1409+#include <QString>
1410+
1411 #include "telegramclient.h"
1412-
1413-
1414-Q_DECLARE_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL)
1415+#include "dbmanager.h"
1416
1417 class ProfileModel : public QObject
1418 {
1419 Q_OBJECT
1420- Q_PROPERTY(qint32 userId READ userId NOTIFY userIdChanged)
1421- Q_PROPERTY(QString firstName READ firstName NOTIFY firstNameChanged)
1422- Q_PROPERTY(QString lastName READ lastName NOTIFY lastNameChanged)
1423- Q_PROPERTY(QString fullName READ fullName NOTIFY fullNameChanged)
1424- Q_PROPERTY(QString phone READ phone NOTIFY phoneChanged)
1425- Q_PROPERTY(QString thumbnail READ thumbnail NOTIFY thumbnailChanged)
1426- Q_PROPERTY(QString bigPhoto READ bigPhoto NOTIFY bigPhotoChanged)
1427- Q_PROPERTY(qint32 lastSeenOnline READ lastSeenOnline NOTIFY lastSeenOnlineChanged)
1428- Q_PROPERTY(bool online READ online NOTIFY onlineChanged)
1429+ Q_PROPERTY(qint32 dialogId READ getDialogId WRITE setDialogId NOTIFY dialogIdChanged)
1430+ Q_PROPERTY(qint32 userId READ getUserId NOTIFY userIdChanged)
1431+ Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged)
1432+ Q_PROPERTY(bool isSecret READ getIsSecret NOTIFY isSecretChanged)
1433+ Q_PROPERTY(bool exists READ getExists NOTIFY existsChanged)
1434+
1435+ Q_PROPERTY(QString thumbnail READ getThumbnail NOTIFY thumbnailChanged)
1436+ Q_PROPERTY(QString photo READ getPhoto NOTIFY photoChanged)
1437+ Q_PROPERTY(QString title READ getTitle NOTIFY titleChanged)
1438+ Q_PROPERTY(QString firstName READ getFirstName)
1439+ Q_PROPERTY(QString lastName READ getLastName)
1440+ Q_PROPERTY(QString phone READ getPhone NOTIFY phoneChanged)
1441+ Q_PROPERTY(bool hasPhone READ getHasPhone NOTIFY phoneChanged)
1442+
1443+// Q_PROPERTY(QString memberCount READ getMemberCount NOTIFY memberCountChanged)
1444+// Q_PROPERTY(qint32 onlineCount READ getOnlineCount NOTIFY onlineCountChanged)
1445+
1446+ Q_PROPERTY(qint32 lastSeen READ getLastSeen NOTIFY lastSeenChanged)
1447+ Q_PROPERTY(bool isOnline READ getIsOnline NOTIFY isOnlineChanged)
1448+
1449+ Q_PROPERTY(bool isMuted READ getIsMuted NOTIFY isMutedChanged)
1450+ Q_PROPERTY(bool isBlocked READ getIsBlocked NOTIFY isBlockedChanged)
1451
1452 public:
1453 explicit ProfileModel(QObject *parent = 0);
1454 ~ProfileModel();
1455
1456- Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 userId);
1457- void reset();
1458-
1459- QString fullName() const;
1460-
1461- virtual qint32 userId() const;
1462- virtual void setUserId(qint32 userId);
1463- virtual QString firstName() const;
1464- virtual void setFirstName(const QString &firstName);
1465- virtual QString lastName() const;
1466- virtual void setLastName(const QString &lastName);
1467- virtual QString phone() const;
1468- virtual void setPhone(const QString &phone);
1469- virtual QString thumbnail() const;
1470- virtual void setThumbnail(const QString &thumbnail);
1471- virtual QString bigPhoto() const;
1472- virtual void setBigPhoto(const QString &bigPhoto);
1473- virtual qint32 lastSeenOnline() const;
1474- virtual void setLastSeenOnline(qint32 lastSeenOnline);
1475- virtual bool online() const;
1476- virtual void setOnline(bool online);
1477-
1478-Q_SIGNALS:
1479- void refreshed();
1480-
1481- void userIdChanged(qint32);
1482- void firstNameChanged(QString);
1483- void lastNameChanged(QString);
1484- void fullNameChanged(QString);
1485- void phoneChanged(QString);
1486- void thumbnailChanged(QString);
1487- void bigPhotoChanged(QString);
1488- void lastSeenOnlineChanged(qint32);
1489- void onlineChanged(bool);
1490-
1491-protected Q_SLOTS:
1492- void refresh(qint32 userId);
1493-
1494- void onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName);
1495- void onContactThumbnailUpdated(qint32 userId, const QString &thumbnail);
1496- void onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto);
1497- void onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline);
1498-
1499-protected:
1500- TelegramClient *mTelegramClient;
1501-
1502+ Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 dialogId);
1503+ Q_INVOKABLE void downloadPhoto();
1504+ void resetProfile();
1505+
1506+ void setDialogId(qint32 dialogId);
1507+ qint32 getDialogId() const;
1508+ qint32 getUserId() const;
1509+ qint32 getChatId() const;
1510+ bool getIsSecret() const;
1511+ bool getExists() const;
1512+
1513+ QString getThumbnail() const;
1514+ QString getPhoto() const;
1515+ QString getTitle() const;
1516+ QString getFirstName() const;
1517+ QString getLastName() const;
1518+ QString getPhone() const;
1519+ bool getHasPhone() const;
1520+
1521+// qint32 getMemberCount() const;
1522+// qint32 getOnlineCount() const;
1523+
1524+ qint32 getLastSeen() const;
1525+ bool getIsOnline() const;
1526+
1527+ bool getIsMuted() const;
1528+ bool getIsBlocked() const;
1529+
1530+public Q_SLOTS:
1531+ void refreshProfile(qint32 dialogId);
1532+
1533+ void contactNameUpdated(qint32 userId, QString firstName, QString lastName);
1534+ void thumbnailChanged(qint32 dialogId, QString thumbnail);
1535+ void photoChanged(qint32 dialogId, QString photo);
1536+ void dialogMuted(qint32 dialogId, bool muted);
1537+ void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
1538+ void usersBlocked(QList<qint32> ids);
1539+ void userBlocked(qint32 uid);
1540+ void userUnblocked(qint32 uid);
1541+
1542+Q_SIGNALS:
1543+ void profileDetailsRefreshed();
1544+
1545+private:
1546+ void setUserId(qint32 userId);
1547+ void setChatId(qint32 chatId);
1548+ void setUserType(qint32 type);
1549+ void setIsSecret(bool isSecret);
1550+
1551+ void setThumbnail(const QString &thumbnail);
1552+ void setPhoto(const QString &photo);
1553+ void setTitle(const QString &title);
1554+ void setPhone(const QString &phone);
1555+
1556+ void setLastSeen(qint32 lastSeen);
1557+ void setIsOnline(bool isOnline);
1558+
1559+ void setIsMuted(bool isMuted);
1560+ void setIsBlocked(bool isBlocked);
1561+
1562+ void refreshUserProfile();
1563+ void refreshGroupProfile();
1564+
1565+Q_SIGNALS:
1566+ void profileUpdated(qint32 dialogId);
1567+
1568+ void dialogIdChanged(qint32 dialogId);
1569+ void userIdChanged(qint32 userId);
1570+ void chatIdChanged(qint32 chatId);
1571+ void userTypeChanged(qint32 userType);
1572+ void isSecretChanged(bool isSecret);
1573+ void existsChanged(bool exists);
1574+
1575+ void thumbnailChanged(QString thumbnail);
1576+ void photoChanged(QString photo);
1577+ void titleChanged(QString title);
1578+ void phoneChanged(QString phone);
1579+ void hasPhoneChanged(bool hasPhone);
1580+
1581+ void lastSeenChanged(qint32 lastSeen);
1582+ void isOnlineChanged(bool isOnline);
1583+
1584+ void isMutedChanged(bool isMuted);
1585+ void isBlockedChanged(bool isBlocked);
1586+
1587+private:
1588+ TelegramClient* mTelegramClient;
1589+
1590+ qint32 mDialogId;
1591 qint32 mUserId;
1592+ qint32 mChatId;
1593+ qint32 mUserType;
1594+ qint64 mAccessHash;
1595+ bool mIsSecret;
1596+
1597+ QString mThumbnail;
1598+ QString mPhoto;
1599+ QString mTitle;
1600 QString mFirstName;
1601 QString mLastName;
1602 QString mPhone;
1603- QString mThumbnail;
1604- QString mBigPhoto;
1605- qint32 mLastSeenOnline;
1606- bool mOnline;
1607+ bool mHasPhone;
1608+
1609+// qint32 mMemberCount;
1610+// qint32 mOnlineCount;
1611+
1612+ qint32 mLastSeen;
1613+ bool mIsOnline;
1614+
1615+ bool mIsMuted;
1616+ bool mIsBlocked;
1617 };
1618
1619-#endif // PROFILEMODEL_H
1620+#endif
1621
1622=== modified file 'qmlplugin/rawapiclient.cpp'
1623--- qmlplugin/rawapiclient.cpp 2015-02-26 21:10:13 +0000
1624+++ qmlplugin/rawapiclient.cpp 2015-03-27 11:52:28 +0000
1625@@ -250,6 +250,18 @@
1626 Q_ARG(QList<InputContact>, contactsList), Q_ARG(bool, replace));
1627 }
1628
1629+void RawApiClient::getBlockedContacts() {
1630+ QMetaObject::invokeMethod(mTelegramService, "getBlockedContacts", Qt::QueuedConnection);
1631+}
1632+
1633+void RawApiClient::blockContact(TLInputPeer *peer) {
1634+ QMetaObject::invokeMethod(mTelegramService, "blockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer));
1635+}
1636+
1637+void RawApiClient::unblockContact(TLInputPeer *peer) {
1638+ QMetaObject::invokeMethod(mTelegramService, "unblockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer));
1639+}
1640+
1641 // Working with messages
1642 void RawApiClient::messagesSendMessage(TLInputPeer *peer, const QString &message) {
1643 QMetaObject::invokeMethod(mTelegramService, "messagesSendMessage", Qt::QueuedConnection,
1644@@ -313,7 +325,6 @@
1645 }
1646
1647 void RawApiClient::messagesCreateChat(const QVariantList &users, const QString &title) {
1648-
1649 QList<InputUser> groupUsers = toQList<InputUser>(users);
1650 QMetaObject::invokeMethod(mTelegramService, "messagesCreateChat", Qt::QueuedConnection,
1651 Q_ARG(QList<InputUser>, groupUsers), Q_ARG(QString, title));
1652
1653=== modified file 'qmlplugin/rawapiclient.h'
1654--- qmlplugin/rawapiclient.h 2015-02-26 21:10:13 +0000
1655+++ qmlplugin/rawapiclient.h 2015-03-27 11:52:28 +0000
1656@@ -98,9 +98,13 @@
1657 Q_INVOKABLE void accountRegisterDevice(const QString &token, const QString &appVersion = "", bool appSandbox = false);
1658 Q_INVOKABLE void accountUnregisterDevice(const QString &token);
1659 Q_INVOKABLE void accountUpdateProfile(const QString &firstName, const QString &lastName);
1660+
1661 // Working with contacts
1662 Q_INVOKABLE void contactsGetContacts();
1663 Q_INVOKABLE void contactsImportContacts(const QVariantList &contacts, bool replace = false);
1664+ Q_INVOKABLE void getBlockedContacts();
1665+ Q_INVOKABLE void blockContact(TLInputPeer *peer);
1666+ Q_INVOKABLE void unblockContact(TLInputPeer *peer);
1667
1668 // Working with messages
1669 Q_INVOKABLE void messagesSendMessage(TLInputPeer *peer, const QString &message);
1670@@ -116,7 +120,6 @@
1671 Q_INVOKABLE void messagesSetTyping(TLInputPeer *peer);
1672 Q_INVOKABLE void messagesSetEncryptedTyping(qint32 chatId, bool typing);
1673
1674-
1675 // Working with chats
1676 Q_INVOKABLE void messagesCreateChat(const QVariantList &users, const QString &title);
1677 Q_INVOKABLE void messagesGetFullChat(qint32 chatId);
1678
1679=== modified file 'qmlplugin/rawapiservice.cpp'
1680--- qmlplugin/rawapiservice.cpp 2015-03-02 21:17:11 +0000
1681+++ qmlplugin/rawapiservice.cpp 2015-03-27 11:52:28 +0000
1682@@ -83,6 +83,8 @@
1683
1684 // Working with contacts
1685 connect(mTelegramLib, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));
1686+ connect(mTelegramLib, SIGNAL(contactsBlockAnswer(qint64,bool)), this, SIGNAL(contactsBlockAnswer(qint64,bool)));
1687+ connect(mTelegramLib, SIGNAL(contactsUnblockAnswer(qint64,bool)), this, SIGNAL(contactsUnblockAnswer(qint64,bool)));
1688
1689 // Working with updates signal-slot
1690 connect(mTelegramLib, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)));
1691
1692=== modified file 'qmlplugin/rawapiservice.h'
1693--- qmlplugin/rawapiservice.h 2015-03-02 21:17:11 +0000
1694+++ qmlplugin/rawapiservice.h 2015-03-27 11:52:28 +0000
1695@@ -150,6 +150,8 @@
1696 // Working with blacklist
1697 void contactsBlockAnswer(qint64 id, bool ok);
1698 void contactsUnblockAnswer(qint64 id, bool ok);
1699+ void contactsBlockResult(qint64 id, bool ok);
1700+ void contactsUnblockResult(qint64 id, bool ok);
1701 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
1702
1703 // Working with messages
1704
1705=== modified file 'qmlplugin/telegramclient.cpp'
1706--- qmlplugin/telegramclient.cpp 2015-03-04 21:24:05 +0000
1707+++ qmlplugin/telegramclient.cpp 2015-03-27 11:52:28 +0000
1708@@ -59,6 +59,9 @@
1709 connect(mTelegramService, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)), Qt::QueuedConnection);
1710 connect(mTelegramService, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)), Qt::QueuedConnection);
1711 connect(mTelegramService, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)), Qt::QueuedConnection);
1712+ connect(mTelegramService, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>)));
1713+ connect(mTelegramService, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32)));
1714+ connect(mTelegramService, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32)));
1715 connect(mTelegramService, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)), Qt::QueuedConnection);
1716 connect(mTelegramService, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), Qt::QueuedConnection);
1717 connect(mTelegramService, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)), Qt::QueuedConnection);
1718
1719=== modified file 'qmlplugin/telegramclient.h'
1720--- qmlplugin/telegramclient.h 2015-03-04 21:10:13 +0000
1721+++ qmlplugin/telegramclient.h 2015-03-27 11:52:28 +0000
1722@@ -128,6 +128,9 @@
1723 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);
1724 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
1725 void dialogTitleUpdated(qint32 dialogId, const QString &title);
1726+ void usersBlocked(QList<qint32> ids);
1727+ void userBlocked(qint32 id);
1728+ void userUnblocked(qint32 id);
1729 void dialogMuted(qint32 dialogId, bool muted);
1730 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
1731 void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount);
1732
1733=== modified file 'qmlplugin/telegramplugin.cpp'
1734--- qmlplugin/telegramplugin.cpp 2015-02-18 17:53:54 +0000
1735+++ qmlplugin/telegramplugin.cpp 2015-03-27 11:52:28 +0000
1736@@ -49,8 +49,10 @@
1737 #include "models/messagesmodel.h"
1738 #include "models/contactsmodel.h"
1739 #include "models/contactsproxy.h"
1740+#include "models/profilemodel.h"
1741 #include "models/groupmodel.h"
1742 #include "models/groupmembersmodel.h"
1743+#include "models/blockedusersmodel.h"
1744 #include "models/dialogsmodel.h"
1745 #include "models/dialogsproxy.h"
1746 #include "models/sortproxymodel.h"
1747@@ -118,8 +120,10 @@
1748 qmlRegisterType<ContactsModel>(uri, 0, 1, "ContactsModel");
1749 qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel");
1750 qmlRegisterType<ContactsProxy>(uri, 0, 1, "ContactsProxy");
1751+ qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel");
1752 qmlRegisterType<GroupModel>(uri, 0, 1, "GroupModel");
1753 qmlRegisterType<GroupMembersModel>(uri, 0, 1, "GroupMembersModel");
1754+ qmlRegisterType<BlockedUsersModel>(uri, 0, 1, "BlockedUsersModel");
1755 qmlRegisterType<DialogItem>(uri, 0, 1, "DialogItem");
1756 qmlRegisterType<MessageItem>(uri, 0, 1, "MessageItem");
1757 qmlRegisterType<ContactItem>(uri, 0, 1, "ContactItem");
1758
1759=== modified file 'qmlplugin/telegramservice.cpp'
1760--- qmlplugin/telegramservice.cpp 2015-03-04 21:10:13 +0000
1761+++ qmlplugin/telegramservice.cpp 2015-03-27 11:52:28 +0000
1762@@ -46,6 +46,9 @@
1763 connect(&mData, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)));
1764 connect(&mData, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)));
1765 connect(&mData, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)));
1766+ connect(&mData, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>)));
1767+ connect(&mData, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32)));
1768+ connect(&mData, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32)));
1769 connect(&mData, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)));
1770 connect(&mData, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)));
1771 connect(&mData, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)));
1772@@ -291,6 +294,18 @@
1773 &mData,
1774 SLOT(onContactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));
1775 connect(mTelegramLib,
1776+ SIGNAL(contactsGetBlockedAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>)),
1777+ &mData,
1778+ SLOT(onGetBlockedContactsAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>)));
1779+ connect(mTelegramLib,
1780+ SIGNAL(contactsBlockAnswer(qint64,bool)),
1781+ &mData,
1782+ SLOT(onBlockContactAnswer(qint64,bool)));
1783+ connect(mTelegramLib,
1784+ SIGNAL(contactsUnblockAnswer(qint64,bool)),
1785+ &mData,
1786+ SLOT(onUnblockContactsAnswer(qint64,bool)));
1787+ connect(mTelegramLib,
1788 SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool)),
1789 &mData,
1790 SLOT(onAccountUpdateNotifySettingsAnswer(qint64,bool)));
1791@@ -409,6 +424,26 @@
1792 return RawApiService::contactsImportContacts(contacts);
1793 }
1794
1795+void TelegramService::getBlockedContacts() {
1796+ mTelegramLib->contactsGetBlocked(0, 200);
1797+}
1798+
1799+void TelegramService::blockContact(InputPeer peer) {
1800+ const ContactItem &contactItem = mData.getUser(peer.userId());
1801+ InputUser inputUser = Tools::toInputUser(contactItem);
1802+
1803+ qint64 requestId = mTelegramLib->contactsBlock(inputUser);
1804+ mData.mBlockRequests.insert(requestId, peer.userId());
1805+}
1806+
1807+void TelegramService::unblockContact(InputPeer peer) {
1808+ const ContactItem &contactItem = mData.getUser(peer.userId());
1809+ InputUser inputUser = Tools::toInputUser(contactItem);
1810+
1811+ qint64 requestId = mTelegramLib->contactsUnblock(inputUser);
1812+ mData.mBlockRequests.insert(requestId, peer.userId());
1813+}
1814+
1815 qint64 TelegramService::messagesReadHistory(InputPeer inputPeer, qint32 maxId, qint32 offset, bool readContents) {
1816
1817 // if peer is foreign, get access hash from db
1818
1819=== modified file 'qmlplugin/telegramservice.h'
1820--- qmlplugin/telegramservice.h 2015-03-04 21:24:05 +0000
1821+++ qmlplugin/telegramservice.h 2015-03-27 11:52:28 +0000
1822@@ -55,6 +55,11 @@
1823 qint64 uploadProfilePhoto(const QString &filePath, const QString &caption = "", double geoPointLat = 0, double geoPointLong = 0, double cropLeft = 0, double cropTop = 0, double cropWidth = 0);
1824 void getUser(qint32 userId);
1825 qint64 addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber);
1826+ void getBlockedContacts();
1827+ void getBlockedContactsAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
1828+ void blockContact(InputPeer peer);
1829+ void unblockContact(InputPeer peer);
1830+
1831 qint64 messagesReadHistory(InputPeer peer, qint32 maxId = 0, qint32 offset = 0, bool readContents = true);
1832 qint64 deleteChatHistory(InputPeer inputPeer, qint32 offset = 0, bool deleteChat = false);
1833 qint64 messagesSendMessage(InputPeer peer, const QString &message);
1834@@ -123,6 +128,9 @@
1835 void contactThumbnailUpdated(qint32 userId, const QString &thumbnail);
1836 void contactBigPhotoUpdated(qint32 userId, const QString &bigPhoto);
1837 void contactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline);
1838+ void usersBlocked(QList<qint32> ids);
1839+ void userBlocked(qint32 id);
1840+ void userUnblocked(qint32 id);
1841 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);
1842 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
1843 void dialogTitleUpdated(qint32 dialogId, const QString &title);

Subscribers

People subscribed via source and target branches

to all changes: