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
=== modified file 'lib/telegram.h'
--- lib/telegram.h 2015-03-03 21:38:35 +0000
+++ lib/telegram.h 2015-03-27 11:52:28 +0000
@@ -229,6 +229,7 @@
229 // Working with blacklist229 // Working with blacklist
230 void contactsBlockAnswer(qint64 id, bool ok);230 void contactsBlockAnswer(qint64 id, bool ok);
231 void contactsUnblockAnswer(qint64 id, bool ok);231 void contactsUnblockAnswer(qint64 id, bool ok);
232 void contactsBlockResult(qint64 id, bool ok);
232 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);233 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
233234
234 // Working with messages235 // Working with messages
235236
=== modified file 'lib/types/inputpeer.h'
--- lib/types/inputpeer.h 2014-10-03 10:34:51 +0000
+++ lib/types/inputpeer.h 2015-03-27 11:52:28 +0000
@@ -41,6 +41,9 @@
41 m_accessHash(0),41 m_accessHash(0),
42 m_classType(classType) {}42 m_classType(classType) {}
4343
44 qint32 id() {
45 return (m_classType == typeInputPeerChat) ? m_chatId : m_userId;
46 }
44 void setUserId(qint32 userId) {47 void setUserId(qint32 userId) {
45 m_userId = userId;48 m_userId = userId;
46 }49 }
4750
=== modified file 'qmlplugin/CMakeLists.txt'
--- qmlplugin/CMakeLists.txt 2015-02-18 17:53:54 +0000
+++ qmlplugin/CMakeLists.txt 2015-03-27 11:52:28 +0000
@@ -40,6 +40,10 @@
40 models/dialogmodel.cpp40 models/dialogmodel.cpp
41 models/groupmembersmodel.h41 models/groupmembersmodel.h
42 models/groupmembersmodel.cpp42 models/groupmembersmodel.cpp
43 models/profilemodel.h
44 models/profilemodel.cpp
45 models/blockedusersmodel.h
46 models/blockedusersmodel.cpp
43 models/messagesmodel.cpp47 models/messagesmodel.cpp
44 models/contactsmodel.cpp48 models/contactsmodel.cpp
45 models/dialogsmodel.cpp49 models/dialogsmodel.cpp
4650
=== modified file 'qmlplugin/data.cpp'
--- qmlplugin/data.cpp 2015-03-17 11:39:18 +0000
+++ qmlplugin/data.cpp 2015-03-27 11:52:28 +0000
@@ -864,6 +864,75 @@
864 qCDebug(TG_PLUGIN_PROFILING) << "onContactsGetContactsAnswer - elapsed time:" << time.elapsed() << "ms";864 qCDebug(TG_PLUGIN_PROFILING) << "onContactsGetContactsAnswer - elapsed time:" << time.elapsed() << "ms";
865}865}
866866
867void Data::putBlockedUsers(const QList<qint32> ids, const bool replace) {
868 if (ids.length() == 0) return;
869
870 QSqlQuery query;
871 if (replace) {
872 query.prepare("DELETE FROM blocked_users");
873 query.exec();
874 }
875 mDbManager.beginTransaction();
876 query.prepare("REPLACE INTO blockedUsers VALUES(:id)");
877 foreach (const qint32 &id, ids) {
878 query.bindValue(":id", id);
879 if (!query.exec()) {
880 mDbManager.rollbackTransaction();
881 return;
882 }
883 }
884 mDbManager.finishTransaction();
885}
886
887void Data::blockUser(qint32 id) {
888 QSqlQuery query;
889 query.prepare("REPLACE INTO blockedUsers VALUES(:id)");
890 query.bindValue(":id", id);
891 query.exec();
892 Q_EMIT userBlocked(id);
893}
894
895void Data::unblockUser(qint32 id) {
896 QSqlQuery query;
897 query.prepare("DELETE FROM blockedUsers WHERE uid = :id");
898 query.bindValue(":id", id);
899 query.exec();
900 Q_EMIT userUnblocked(id);
901}
902
903void Data::onGetBlockedContactsAnswer(qint64, qint32, QList<ContactBlocked> blocked, QList<User> users) {
904 qCDebug(TG_PLUGIN_LOGIC) << "onGetBlockedContactsAnswer";
905
906 mDbManager.beginTransaction();
907 Q_FOREACH (const User &user, users) {
908 if (!insertOrUpdateUser(user)) {
909 mDbManager.rollbackTransaction();
910 return;
911 }
912 }
913 QList<qint32> blockedUserIds;
914 Q_FOREACH (const ContactBlocked &contact, blocked) {
915 blockedUserIds.append(contact.userId());
916 }
917 putBlockedUsers(blockedUserIds, true);
918 mDbManager.finishTransaction();
919 Q_EMIT usersBlocked(blockedUserIds);
920}
921
922void Data::onBlockContactAnswer(qint64 requestId, bool ok) {
923 qint32 userId = mBlockRequests.take(requestId);
924 if (userId != 0 && ok) {
925 blockUser(userId);
926 }
927}
928
929void Data::onUnblockContactsAnswer(qint64 requestId, bool ok) {
930 qint32 userId = mBlockRequests.take(requestId);
931 if (userId != 0 && ok) {
932 unblockUser(userId);
933 }
934}
935
867void Data::onMessagesGetHistoryAnswer(qint64, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users) {936void Data::onMessagesGetHistoryAnswer(qint64, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users) {
868 QTime time;937 QTime time;
869 time.start();938 time.start();
@@ -954,7 +1023,9 @@
954 qint32 deleteChatId = mChatsToDelete.take(id);1023 qint32 deleteChatId = mChatsToDelete.take(id);
955 if (deleteChatId != 0) {1024 if (deleteChatId != 0) {
956 qCDebug(TG_PLUGIN_LOGIC) << "deleting chat:" << deleteChatId;1025 qCDebug(TG_PLUGIN_LOGIC) << "deleting chat:" << deleteChatId;
957 deleteDialog(deleteChatId);1026 TelegramService *service = static_cast<TelegramService *>(mServiceRef);
1027 qint32 id = service->deleteChatUser(deleteChatId, service->ourId());
1028 mChatsToDelete.insert(id, service->ourId());
958 }1029 }
9591030
960 clientState.setPts(pts);1031 clientState.setPts(pts);
@@ -1469,15 +1540,21 @@
1469 return;1540 return;
1470 }1541 }
14711542
1543 mDbManager.finishTransaction();
1544
1545 Q_FOREACH (const Chat &chat, chats) {
1546 Q_EMIT chatUpdated(chat.id());
1547 }
1548
1549 // handle chat deletion - after self has deleted the chat from UI
1550 qint32 chatId = mChatsToDelete.take(id);
1551 if (chatId != 0) {
1552 deleteChat(chatId);
1553 Q_EMIT chatDeleted(chatId);
1554 }
1555
1472 // send signal with the action related message1556 // send signal with the action related message
1473 MessageItem messageItem = getMessage(message.id());1557 MessageItem messageItem = getMessage(message.id());
1474
1475 mDbManager.finishTransaction();
1476
1477 Q_FOREACH (const Chat &chat, chats) {
1478 Q_EMIT chatUpdated(chat.id());
1479 }
1480
1481 Q_EMIT messageAdded(messageItem);1558 Q_EMIT messageAdded(messageItem);
14821559
1483 qCDebug(TG_PLUGIN_PROFILING) << "onMessagesDeleteChatUsersAnswer - end:" << time.elapsed() << "ms";1560 qCDebug(TG_PLUGIN_PROFILING) << "onMessagesDeleteChatUsersAnswer - end:" << time.elapsed() << "ms";
@@ -2593,6 +2670,14 @@
2593 break;2670 break;
2594 }2671 }
25952672
2673 case Update::typeUpdateUserBlocked: {
2674 if (update.blocked()) {
2675 blockUser(update.userId());
2676 } else {
2677 unblockUser(update.userId());
2678 }
2679 }
2680
2596 case Update::typeUpdateNotifySettings: {2681 case Update::typeUpdateNotifySettings: {
2597 NotifyPeer notifyPeer = update.peer();2682 NotifyPeer notifyPeer = update.peer();
2598 PeerNotifySettings settings = update.notifySettings();2683 PeerNotifySettings settings = update.notifySettings();
@@ -6319,7 +6404,6 @@
63196404
6320bool Data::muteDialog(qint32 dialogId, bool muted) {6405bool Data::muteDialog(qint32 dialogId, bool muted) {
6321 QSqlQuery query(mDbManager.database());6406 QSqlQuery query(mDbManager.database());
6322
6323 query.prepare("UPDATE dialogs SET muted=:muted WHERE id=:id");6407 query.prepare("UPDATE dialogs SET muted=:muted WHERE id=:id");
6324 query.bindValue(":id", dialogId);6408 query.bindValue(":id", dialogId);
6325 query.bindValue(":muted", muted);6409 query.bindValue(":muted", muted);
@@ -6334,7 +6418,6 @@
63346418
6335bool Data::muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted) {6419bool Data::muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted) {
6336 QSqlQuery query(mDbManager.database());6420 QSqlQuery query(mDbManager.database());
6337
6338 QString condition;6421 QString condition;
6339 switch (peerType) {6422 switch (peerType) {
6340 case NotifyPeer::typeNotifyUsers:6423 case NotifyPeer::typeNotifyUsers:
@@ -6350,7 +6433,7 @@
6350 return false;6433 return false;
6351 }6434 }
63526435
6353 QString sql = QString("UPDATE dialogs SET muted=:muted").arg(condition);6436 QString sql = QString("UPDATE dialogs SET muted=:muted").append(condition);
6354 query.prepare(sql);6437 query.prepare(sql);
6355 query.bindValue(":muted", muted);6438 query.bindValue(":muted", muted);
6356 if (!query.exec()) {6439 if (!query.exec()) {
@@ -6358,7 +6441,6 @@
6358 << "for dialogs" << query.lastError() << query.lastQuery();6441 << "for dialogs" << query.lastError() << query.lastQuery();
6359 return false;6442 return false;
6360 }6443 }
6361
6362 return query.numRowsAffected() > 0;6444 return query.numRowsAffected() > 0;
6363}6445}
63646446
63656447
=== modified file 'qmlplugin/data.h'
--- qmlplugin/data.h 2015-03-03 15:30:59 +0000
+++ qmlplugin/data.h 2015-03-27 11:52:28 +0000
@@ -191,7 +191,8 @@
191191
192 void setMutingInProgress(qint64 requestId, qint32 peerId, bool muting);192 void setMutingInProgress(qint64 requestId, qint32 peerId, bool muting);
193 QMap<qint64, qint32> mChatsToClearHistory;193 QMap<qint64, qint32> mChatsToClearHistory;
194 QMap<qint32, qint32> mChatsToDelete;194 QMap<qint64, qint32> mChatsToDelete;
195 QMap<qint64, qint32> mBlockRequests;
195196
196public:197public:
197198
@@ -201,6 +202,8 @@
201202
202public Q_SLOTS:203public Q_SLOTS:
203 void setSecretChatMessageTTL(qint32 chatId, qint32 ttlSeconds);204 void setSecretChatMessageTTL(qint32 chatId, qint32 ttlSeconds);
205 void blockUser(qint32 id);
206 void unblockUser(qint32 id);
204207
205protected:208protected:
206 void updateChats(const QList<Chat> &chats);209 void updateChats(const QList<Chat> &chats);
@@ -221,6 +224,9 @@
221 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);224 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
222 void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName);225 void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName);
223 void dialogTitleUpdated(qint32 dialogId, const QString &title);226 void dialogTitleUpdated(qint32 dialogId, const QString &title);
227 void usersBlocked(QList<qint32> ids);
228 void userBlocked(qint32 id);
229 void userUnblocked(qint32 id);
224 void dialogMuted(qint32 dialogId, bool muted);230 void dialogMuted(qint32 dialogId, bool muted);
225 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);231 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
226232
@@ -359,6 +365,10 @@
359 void onMessagesGetFullChatAnswer(qint64 id, ChatFull chatFull, QList<Chat> chats, QList<User> users);365 void onMessagesGetFullChatAnswer(qint64 id, ChatFull chatFull, QList<Chat> chats, QList<User> users);
360 void onContactsImportContactsAnswer(qint64 id, QList<ImportedContact> importedContacts, QList<qint64> retryContacts, QList<User> users);366 void onContactsImportContactsAnswer(qint64 id, QList<ImportedContact> importedContacts, QList<qint64> retryContacts, QList<User> users);
361 void onContactsGetContactsAnswer(qint64 requestId, bool modified, const QList<Contact> &contacts, const QList<User> &users);367 void onContactsGetContactsAnswer(qint64 requestId, bool modified, const QList<Contact> &contacts, const QList<User> &users);
368 void putBlockedUsers(const QList<qint32> ids, const bool replace);
369 void onGetBlockedContactsAnswer(qint64 requestId, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
370 void onBlockContactAnswer(qint64 requestId, bool ok);
371 void onUnblockContactsAnswer(qint64 requestId, bool ok);
362 void onMessagesGetHistoryAnswer(qint64 requestId, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users);372 void onMessagesGetHistoryAnswer(qint64 requestId, qint32 totalCount, const QList<Message> &messages, const QList<Chat> &chats, const QList<User> &users);
363 void onMessagesReadHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);373 void onMessagesReadHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);
364 void onMessagesDeleteHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);374 void onMessagesDeleteHistoryAnswer(qint64 id, qint32 pts, qint32 seq, qint32 offset);
365375
=== modified file 'qmlplugin/dbmanager.cpp'
--- qmlplugin/dbmanager.cpp 2015-03-23 10:47:25 +0000
+++ qmlplugin/dbmanager.cpp 2015-03-27 11:52:28 +0000
@@ -42,9 +42,10 @@
42const qint32 VERSION_PROFILE_BIG_PHOTO = 11;42const qint32 VERSION_PROFILE_BIG_PHOTO = 11;
43const qint32 VERSION_FORWARD_MESSAGES = 12;43const qint32 VERSION_FORWARD_MESSAGES = 12;
44const qint32 VERSION_MEDIA_DOCUMENTS = 13;44const qint32 VERSION_MEDIA_DOCUMENTS = 13;
45const qint32 VERSION_BLOCKED_USERS = 14;
4546
46// Update this line when creating new upgrade version.47// Update this line when creating new upgrade version.
47const qint32 DATABASE_VERSION = VERSION_MEDIA_DOCUMENTS;48const qint32 DATABASE_VERSION = VERSION_BLOCKED_USERS;
4849
4950
50DbManager::DbManager(QObject *parent) :51DbManager::DbManager(QObject *parent) :
@@ -169,6 +170,7 @@
169170
170 queries << Schema::CREATE_THUMBNAILS;171 queries << Schema::CREATE_THUMBNAILS;
171 queries << Schema::CREATE_USERS;172 queries << Schema::CREATE_USERS;
173 queries << Schema::CREATE_BLOCKED_USERS;
172 queries << UpgradeSecretChats::CREATE_SECRET_CHATS;174 queries << UpgradeSecretChats::CREATE_SECRET_CHATS;
173 queries << Schema::CREATE_DIALOGS;175 queries << Schema::CREATE_DIALOGS;
174 queries << Schema::CREATE_CHATS;176 queries << Schema::CREATE_CHATS;
@@ -218,6 +220,7 @@
218 queries << Schema::DROP_CHATS;220 queries << Schema::DROP_CHATS;
219 queries << Schema::DROP_DIALOGS;221 queries << Schema::DROP_DIALOGS;
220 queries << UpgradeSecretChats::DROP_SECRET_CHATS;222 queries << UpgradeSecretChats::DROP_SECRET_CHATS;
223 queries << Schema::DROP_BLOCKED_USERS;
221 queries << Schema::DROP_USERS;224 queries << Schema::DROP_USERS;
222225
223 bool result = executeSqlQueries(queries);226 bool result = executeSqlQueries(queries);
@@ -310,6 +313,9 @@
310 if (!upgradeMediaDocuments()) break;313 if (!upgradeMediaDocuments()) break;
311 case VERSION_MEDIA_DOCUMENTS:314 case VERSION_MEDIA_DOCUMENTS:
312 version = VERSION_MEDIA_DOCUMENTS;315 version = VERSION_MEDIA_DOCUMENTS;
316 if (!upgradeBlockedUsers()) break;
317 case VERSION_BLOCKED_USERS:
318 version = VERSION_BLOCKED_USERS;
313319
314 // Upgrade cases go here.320 // Upgrade cases go here.
315 }321 }
@@ -509,6 +515,14 @@
509 return result;515 return result;
510}516}
511517
518bool DbManager::upgradeBlockedUsers() {
519 qCDebug(LOG_DATABASE) << "Upgrading database: adding blocked users";
520
521 QStringList queries;
522 queries << Schema::CREATE_BLOCKED_USERS;
523 return executeSqlQueries(queries);
524}
525
512bool DbManager::purgeButSecret() {526bool DbManager::purgeButSecret() {
513 qCDebug(LOG_DATABASE) << "Purging database but secret chats data...";527 qCDebug(LOG_DATABASE) << "Purging database but secret chats data...";
514528
515529
=== modified file 'qmlplugin/dbmanager.h'
--- qmlplugin/dbmanager.h 2015-02-25 21:25:07 +0000
+++ qmlplugin/dbmanager.h 2015-03-27 11:52:28 +0000
@@ -67,6 +67,7 @@
67 bool upgradeProfilesBigPhotos();67 bool upgradeProfilesBigPhotos();
68 bool upgradeForwardMessages();68 bool upgradeForwardMessages();
69 bool upgradeMediaDocuments();69 bool upgradeMediaDocuments();
70 bool upgradeBlockedUsers();
7071
71private:72private:
72 QString mDatabasePath;73 QString mDatabasePath;
7374
=== modified file 'qmlplugin/dbschema.h'
--- qmlplugin/dbschema.h 2015-03-10 15:32:48 +0000
+++ qmlplugin/dbschema.h 2015-03-27 11:52:28 +0000
@@ -259,6 +259,12 @@
259259
260const QString DROP_MESSAGE_ACTIONS("DROP TABLE IF EXISTS messageActions");260const QString DROP_MESSAGE_ACTIONS("DROP TABLE IF EXISTS messageActions");
261261
262const QString CREATE_BLOCKED_USERS("CREATE TABLE blockedUsers(\n"
263" uid INTEGER PRIMARY KEY\n"
264")");
265
266const QString DROP_BLOCKED_USERS("DROP TABLE IF EXISTS blockedUsers");
267
262}268}
263269
264namespace MessageActionsRemovePhotoId {270namespace MessageActionsRemovePhotoId {
265271
=== added file 'qmlplugin/models/blockedusersmodel.cpp'
--- qmlplugin/models/blockedusersmodel.cpp 1970-01-01 00:00:00 +0000
+++ qmlplugin/models/blockedusersmodel.cpp 2015-03-27 11:52:28 +0000
@@ -0,0 +1,74 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "blockedusersmodel.h"
18
19#include "types/tluser.h"
20#include "types/tlinputpeer.h"
21
22BlockedUsersModel::BlockedUsersModel(QObject *parent) :
23 Model(parent), mTelegramClient(NULL) {
24}
25
26BlockedUsersModel::~BlockedUsersModel() {
27 disconnect(mTelegramClient);
28 mTelegramClient = NULL;
29}
30
31void BlockedUsersModel::setup(TelegramClient *telegramClient) {
32 Q_ASSERT(telegramClient != NULL);
33
34 if (mTelegramClient == NULL) {
35 mTelegramClient = telegramClient;
36 connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)),
37 this, SLOT(refresh(QList<qint32>)));
38 connect(mTelegramClient, SIGNAL(userBlocked(qint32)),
39 this, SLOT(userBlocked(qint32)));
40 connect(mTelegramClient, SIGNAL(userUnblocked(qint32)),
41 this, SLOT(userUnblocked(qint32)));
42 }
43 refresh();
44}
45
46void BlockedUsersModel::refresh(QList<qint32> ids) {
47 if (mTelegramClient == NULL) return;
48 mQueryString = QString(
49 "SELECT id, type, "
50 " (SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS photo, "
51 " (firstName || \" \" || lastName) AS name, "
52 " online, lastSeenOnline "
53 "FROM users JOIN blockedUsers ON users.id = blockedUsers.uid");
54 Model::refresh();
55}
56
57void BlockedUsersModel::userBlocked(qint32 id) {
58 refresh();
59}
60
61void BlockedUsersModel::userUnblocked(qint32 id) {
62 refresh();
63}
64
65QHash<int, QByteArray> BlockedUsersModel::roleNames() const {
66 QHash<int, QByteArray> roles;
67 roles[IdRole] = "id";
68 roles[TypeRole] = "type";
69 roles[PhotoRole] = "photo";
70 roles[NameRole] = "name";
71 roles[OnlineRole] = "online";
72 roles[LastSeenOnlineRole] = "lastSeenOnline";
73 return roles;
74}
075
=== added file 'qmlplugin/models/blockedusersmodel.h'
--- qmlplugin/models/blockedusersmodel.h 1970-01-01 00:00:00 +0000
+++ qmlplugin/models/blockedusersmodel.h 2015-03-27 11:52:28 +0000
@@ -0,0 +1,56 @@
1/*
2 * Copyright 2014 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef BLOCKED_USERS_MODEL_H
18#define BLOCKED_USERS_MODEL_H
19
20#include <QLoggingCategory>
21
22#include "model.h"
23#include "telegramclient.h"
24
25class BlockedUsersModel : public Model
26{
27 Q_OBJECT
28 Q_ENUMS(BlockedUsersRoles)
29public:
30
31 enum BlockedUsersRoles {
32 IdRole = Qt::UserRole,
33 TypeRole,
34 PhotoRole,
35 NameRole,
36 OnlineRole,
37 LastSeenOnlineRole
38 };
39
40 explicit BlockedUsersModel(QObject *parent = 0);
41 ~BlockedUsersModel();
42
43 Q_INVOKABLE void setup(TelegramClient *telegramClient);
44
45public Q_SLOTS:
46 void refresh(QList<qint32> ids = QList<qint32>());
47 void userBlocked(qint32 id);
48 void userUnblocked(qint32 id);
49
50private:
51 TelegramClient *mTelegramClient;
52
53 QHash<qint32, QByteArray> roleNames() const;
54};
55
56#endif // BLOCKED_USERS_MODEL_H
057
=== modified file 'qmlplugin/models/dialogmodel.cpp'
--- qmlplugin/models/dialogmodel.cpp 2015-02-04 22:29:48 +0000
+++ qmlplugin/models/dialogmodel.cpp 2015-03-27 11:52:28 +0000
@@ -25,6 +25,7 @@
25 mChatId(0),25 mChatId(0),
26 mPeerId(0),26 mPeerId(0),
27 mPeerType((qint32) InputPeer::typeInputPeerContact),27 mPeerType((qint32) InputPeer::typeInputPeerContact),
28 mAccessHash(0),
28 mWhoIsTyping(""),29 mWhoIsTyping(""),
29 mIsTyping(false),30 mIsTyping(false),
30 mIsSecret(false),31 mIsSecret(false),
@@ -44,12 +45,13 @@
44 setChatId(0);45 setChatId(0);
45 setPeerId(0);46 setPeerId(0);
46 setPeerType((qint32) InputPeer::typeInputPeerContact);47 setPeerType((qint32) InputPeer::typeInputPeerContact);
48 setAccessHash(0);
47 setIsChat(false);49 setIsChat(false);
48 setIsTyping(false);50 setIsTyping(false);
49 setIsSecret(false);51 setIsSecret(false);
50 setState(0);52 setState(0);
51 setTitle(QString());53 setTitle("");
52 setPhone(QString());54 setPhone("");
53 setTtl(0);55 setTtl(0);
54}56}
5557
@@ -76,9 +78,7 @@
76 // TODO karni: hook up live state78 // TODO karni: hook up live state
77 }79 }
7880
79 if (mTelegramClient != NULL) {81 setChatId(chatId);
80 setChatId(chatId);
81 }
82}82}
8383
84void DialogModel::onMessageReceived(const MessageItem &message) {84void DialogModel::onMessageReceived(const MessageItem &message) {
@@ -92,13 +92,10 @@
92}92}
9393
94void DialogModel::setChatId(qint32 chatId) {94void DialogModel::setChatId(qint32 chatId) {
95 if (mChatId != chatId) {95 if (mChatId == chatId) return;
96 mChatId = chatId;96 mChatId = chatId;
97 if (chatId != 0) {97 refreshDialogDetails(chatId);
98 refreshDialogDetails(chatId);98 Q_EMIT chatIdChanged(chatId);
99 }
100 Q_EMIT chatIdChanged(chatId);
101 }
102}99}
103100
104qint32 DialogModel::getPeerId() const {101qint32 DialogModel::getPeerId() const {
@@ -106,10 +103,9 @@
106}103}
107104
108void DialogModel::setPeerId(qint32 peerId) {105void DialogModel::setPeerId(qint32 peerId) {
109 if (mPeerId != peerId) {106 if (mPeerId == peerId) return;
110 mPeerId = peerId;107 mPeerId = peerId;
111 Q_EMIT peerIdChanged(peerId);108 Q_EMIT peerIdChanged(peerId);
112 }
113}109}
114110
115qint32 DialogModel::getPeerType() const {111qint32 DialogModel::getPeerType() const {
@@ -117,10 +113,19 @@
117}113}
118114
119void DialogModel::setPeerType(qint32 peerType) {115void DialogModel::setPeerType(qint32 peerType) {
120 if (mPeerType != peerType) {116 if (mPeerType == peerType) return;
121 mPeerType = peerType;117 mPeerType = peerType;
122 Q_EMIT peerTypeChanged(peerType);118 Q_EMIT peerTypeChanged(peerType);
123 }119}
120
121qint64 DialogModel::getAccessHash() const {
122 return mAccessHash;
123}
124
125void DialogModel::setAccessHash(qint64 accessHash) {
126 if (mAccessHash == accessHash) return;
127 mAccessHash = accessHash;
128 Q_EMIT accessHashChanged(accessHash);
124}129}
125130
126bool DialogModel::getIsChat() const {131bool DialogModel::getIsChat() const {
@@ -128,10 +133,9 @@
128}133}
129134
130void DialogModel::setIsChat(bool isChat) {135void DialogModel::setIsChat(bool isChat) {
131 if (mIsChat != isChat) {136 if (mIsChat == isChat) return;
132 mIsChat = isChat;137 mIsChat = isChat;
133 Q_EMIT isChatChanged(isChat);138 Q_EMIT isChatChanged(isChat);
134 }
135}139}
136140
137QString DialogModel::getWhoIsTyping() const {141QString DialogModel::getWhoIsTyping() const {
@@ -139,10 +143,9 @@
139}143}
140144
141void DialogModel::setWhoIsTyping(QString whoIsTyping) {145void DialogModel::setWhoIsTyping(QString whoIsTyping) {
142 if (mWhoIsTyping != whoIsTyping) {146 if (mWhoIsTyping == whoIsTyping) return;
143 mWhoIsTyping = whoIsTyping;147 mWhoIsTyping = whoIsTyping;
144 Q_EMIT whoIsTypingChanged(whoIsTyping);148 Q_EMIT whoIsTypingChanged(whoIsTyping);
145 }
146}149}
147150
148bool DialogModel::getIsTyping() const {151bool DialogModel::getIsTyping() const {
@@ -160,10 +163,9 @@
160}163}
161164
162void DialogModel::setIsSecret(bool isSecret) {165void DialogModel::setIsSecret(bool isSecret) {
163 if (mIsSecret != isSecret) {166 if (mIsSecret == isSecret) return;
164 mIsSecret = isSecret;167 mIsSecret = isSecret;
165 Q_EMIT isSecretChanged(isSecret);168 Q_EMIT isSecretChanged(isSecret);
166 }
167}169}
168170
169qint32 DialogModel::getState() const {171qint32 DialogModel::getState() const {
@@ -171,10 +173,9 @@
171}173}
172174
173void DialogModel::setState(qint32 state) {175void DialogModel::setState(qint32 state) {
174 if (mState != state) {176 if (mState == state) return;
175 mState = state;177 mState = state;
176 Q_EMIT stateChanged(state);178 Q_EMIT stateChanged(state);
177 }
178}179}
179180
180QString DialogModel::getTitle() const {181QString DialogModel::getTitle() const {
@@ -182,10 +183,9 @@
182}183}
183184
184void DialogModel::setTitle(const QString &title) {185void DialogModel::setTitle(const QString &title) {
185 if (mTitle != title) {186 if (mTitle == title) return;
186 mTitle = title;187 mTitle = title;
187 Q_EMIT titleChanged(title);188 Q_EMIT titleChanged(title);
188 }
189}189}
190190
191QString DialogModel::getPhone() const {191QString DialogModel::getPhone() const {
@@ -193,10 +193,9 @@
193}193}
194194
195void DialogModel::setPhone(QString phone) {195void DialogModel::setPhone(QString phone) {
196 if (mPhone != phone) {196 if (mPhone == phone) return;
197 mPhone = phone;197 mPhone = phone;
198 Q_EMIT phoneChanged(phone);198 Q_EMIT phoneChanged(phone);
199 }
200}199}
201200
202qint32 DialogModel::getTtl() const {201qint32 DialogModel::getTtl() const {
@@ -204,10 +203,9 @@
204}203}
205204
206void DialogModel::setTtl(qint32 ttl) {205void DialogModel::setTtl(qint32 ttl) {
207 if (mTtl != ttl) {206 if (mTtl == ttl) return;
208 mTtl = ttl;207 mTtl = ttl;
209 Q_EMIT ttlChanged(ttl);208 Q_EMIT ttlChanged(ttl);
210 }
211}209}
212210
213void DialogModel::refreshDialogDetails(qint32 chatId) {211void DialogModel::refreshDialogDetails(qint32 chatId) {
@@ -215,9 +213,12 @@
215 qCDebug(TG_PLUGIN_LOGIC) << "Querying dialog details" << chatId;213 qCDebug(TG_PLUGIN_LOGIC) << "Querying dialog details" << chatId;
216214
217 QSqlQuery query;215 QSqlQuery query;
218 query.prepare(QString("SELECT id, isChat, name, thumbnail, members, userOnline, "216 query.prepare(QString("SELECT dialogsView.id, isChat, name, dialogsView.thumbnail, members, userOnline, "
219 "lastSeenOnline, peerId, peerType, date, isSecret, state, ttl "217 "dialogsView.lastSeenOnline, peerId, peerType, date, isSecret, state, ttl, "
220 "FROM dialogsView WHERE id = %1").arg(QString::number(chatId)));218 "coalesce(users.type, 0) as type, coalesce(users.accessHash, 0) as accessHash "
219 "FROM dialogsView "
220 " LEFT JOIN users ON dialogsView.id = users.id "
221 "WHERE dialogsView.id = %1").arg(QString::number(chatId)));
221222
222 // query.bindValue(":chatId", chatId); // no worky?223 // query.bindValue(":chatId", chatId); // no worky?
223224
@@ -243,14 +244,14 @@
243 }244 }
244245
245 setIsChat(false);246 setIsChat(false);
246
247 setIsSecret(false);247 setIsSecret(false);
248
249 qint32 userType = query.value("type").toInt();248 qint32 userType = query.value("type").toInt();
250 setPeerType(Tools::toInputPeerType((User::UserType) userType));249 setPeerType(Tools::toInputPeerType((User::UserType) userType));
251
252 setPeerId(chatId);250 setPeerId(chatId);
253251 qint64 accessHash = query.value("accessHash").toLongLong();
252 if (accessHash != 0) {
253 setAccessHash(accessHash);
254 }
254 setState(0);255 setState(0);
255256
256 QString firstName;257 QString firstName;
@@ -276,24 +277,22 @@
276277
277 bool isChat = query.value("isChat").toBool();278 bool isChat = query.value("isChat").toBool();
278 setIsChat(isChat);279 setIsChat(isChat);
279
280 bool isSecret = query.value("isSecret").toBool();280 bool isSecret = query.value("isSecret").toBool();
281 setIsSecret(isSecret);281 setIsSecret(isSecret);
282
283 if (isSecret) {282 if (isSecret) {
284 qint32 ttl = query.value("ttl").toInt();283 qint32 ttl = query.value("ttl").toInt();
285 setTtl(ttl);284 setTtl(ttl);
286 }285 }
287
288 qint32 userType = query.value("peerType").toInt();286 qint32 userType = query.value("peerType").toInt();
289 setPeerType(Tools::toInputPeerType((User::UserType) userType));287 setPeerType(Tools::toInputPeerType((User::UserType) userType));
290
291 qint32 peerId = query.value("peerId").toInt();288 qint32 peerId = query.value("peerId").toInt();
292 setPeerId(isSecret ? peerId : chatId); // *sigh*289 setPeerId(isSecret ? peerId : chatId);
293290 qint64 accessHash = query.value("accessHash").toLongLong();
291 if (accessHash != 0) {
292 setAccessHash(accessHash);
293 }
294 qint32 state = query.value("state").toInt();294 qint32 state = query.value("state").toInt();
295 setState(state);295 setState(state);
296
297 QString title = query.value("name").toString();296 QString title = query.value("name").toString();
298 setTitle(title);297 setTitle(title);
299298
300299
=== modified file 'qmlplugin/models/dialogmodel.h'
--- qmlplugin/models/dialogmodel.h 2015-02-04 19:01:38 +0000
+++ qmlplugin/models/dialogmodel.h 2015-03-27 11:52:28 +0000
@@ -32,6 +32,7 @@
32 Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged)32 Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged)
33 Q_PROPERTY(qint32 peerId READ getPeerId NOTIFY peerIdChanged)33 Q_PROPERTY(qint32 peerId READ getPeerId NOTIFY peerIdChanged)
34 Q_PROPERTY(qint32 peerType READ getPeerType NOTIFY peerTypeChanged)34 Q_PROPERTY(qint32 peerType READ getPeerType NOTIFY peerTypeChanged)
35 Q_PROPERTY(qint64 accessHash READ getAccessHash NOTIFY accessHashChanged)
35 Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged)36 Q_PROPERTY(bool isChat READ getIsChat NOTIFY isChatChanged)
36 Q_PROPERTY(QString whoIsTyping READ getWhoIsTyping NOTIFY whoIsTypingChanged)37 Q_PROPERTY(QString whoIsTyping READ getWhoIsTyping NOTIFY whoIsTypingChanged)
37 Q_PROPERTY(bool isTyping READ getIsTyping NOTIFY isTypingChanged)38 Q_PROPERTY(bool isTyping READ getIsTyping NOTIFY isTypingChanged)
@@ -57,6 +58,9 @@
57 qint32 getPeerType() const;58 qint32 getPeerType() const;
58 void setPeerType(qint32 classType);59 void setPeerType(qint32 classType);
5960
61 qint64 getAccessHash() const;
62 void setAccessHash(qint64 accessHash);
63
60 bool getIsChat() const;64 bool getIsChat() const;
61 void setIsChat(bool isChat);65 void setIsChat(bool isChat);
6266
@@ -95,6 +99,7 @@
95 void chatIdChanged(qint32 chatId);99 void chatIdChanged(qint32 chatId);
96 void peerIdChanged(qint32 peerId);100 void peerIdChanged(qint32 peerId);
97 void peerTypeChanged(qint32 peerType);101 void peerTypeChanged(qint32 peerType);
102 void accessHashChanged(qint64 accessHash);
98 void peerChanged(qint32 peerId, qint32 peerType);103 void peerChanged(qint32 peerId, qint32 peerType);
99 void isChatChanged(bool isChat);104 void isChatChanged(bool isChat);
100 void whoIsTypingChanged(QString who);105 void whoIsTypingChanged(QString who);
@@ -111,6 +116,7 @@
111 qint32 mChatId;116 qint32 mChatId;
112 qint32 mPeerId;117 qint32 mPeerId;
113 qint32 mPeerType;118 qint32 mPeerType;
119 qint64 mAccessHash;
114 bool mIsChat;120 bool mIsChat;
115 bool mIsTyping;121 bool mIsTyping;
116 QString mWhoIsTyping;122 QString mWhoIsTyping;
117123
=== modified file 'qmlplugin/models/groupmodel.cpp'
--- qmlplugin/models/groupmodel.cpp 2015-02-16 18:07:13 +0000
+++ qmlplugin/models/groupmodel.cpp 2015-03-27 11:52:28 +0000
@@ -40,9 +40,7 @@
40 this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool)));40 this, SLOT(chatsMuted(NotifyPeer::NotifyPeerType,bool)));
41 }41 }
4242
43 if (mTelegramClient != NULL) {43 setChatId(chatId);
44 setChatId(chatId);
45 }
46}44}
4745
48qint32 GroupModel::getChatId() const {46qint32 GroupModel::getChatId() const {
4947
=== modified file 'qmlplugin/models/profilemodel.cpp'
--- qmlplugin/models/profilemodel.cpp 2015-02-18 17:53:54 +0000
+++ qmlplugin/models/profilemodel.cpp 2015-03-27 11:52:28 +0000
@@ -1,220 +1,389 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
1#include "profilemodel.h"17#include "profilemodel.h"
218#include "tools.h"
3Q_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL, "tg.models.profilemodel")19
420ProfileModel::ProfileModel(QObject *parent) : QObject(parent),
5ProfileModel::ProfileModel(QObject *parent) :21 mTelegramClient(NULL), mDialogId(0), mUserId(0), mChatId(0), mIsSecret(true),
6 QObject(parent),22 mThumbnail(""), mPhoto(""), mTitle(""), mFirstName(""), mLastName(""),
7 mTelegramClient(0),23 mPhone(""), mHasPhone(false), mLastSeen(0), mIsOnline(false),
8 mUserId(0),24 mIsMuted(false), mIsBlocked(false) {
9 mFirstName(""),
10 mLastName(""),
11 mThumbnail(""),
12 mBigPhoto(""),
13 mLastSeenOnline(0),
14 mOnline(false) {
15}25}
1626
17ProfileModel::~ProfileModel() {27ProfileModel::~ProfileModel() {
28 disconnect(mTelegramClient);
18 mTelegramClient = 0;29 mTelegramClient = 0;
19}30}
2031
21void ProfileModel::reset() {32void ProfileModel::setup(TelegramClient *telegramClient, qint32 dialogId) {
22 mTelegramClient = 0,33 Q_ASSERT(telegramClient != NULL);
23 setUserId(0),34
24 setFirstName("");35 if (mTelegramClient == NULL) {
25 setLastName("");
26 setThumbnail("");
27 setBigPhoto("");
28 setLastSeenOnline(0);
29 setOnline(false);
30}
31
32void ProfileModel::setup(TelegramClient *telegramClient, qint32 userId) {
33
34 Q_ASSERT(telegramClient);
35
36 if (!mTelegramClient) {
37 mTelegramClient = telegramClient;36 mTelegramClient = telegramClient;
38 connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)), SLOT(onContactNameUpdated(qint32,QString,QString)));37
39 connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)), SLOT(onContactThumbnailUpdated(qint32,QString)));38 connect(mTelegramClient, SIGNAL(contactNameUpdated(qint32,QString,QString)),
40 connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)), SLOT(onContactBigPhotoUpdated(qint32,QString)));39 this, SLOT(contactNameUpdated(qint32,QString,QString)));
41 connect(mTelegramClient, SIGNAL(contactStatusUpdated(qint32,bool,qint32)), SLOT(onContactStatusUpdated(qint32,bool,qint32)));40
42 }41 connect(mTelegramClient, SIGNAL(contactThumbnailUpdated(qint32,QString)),
4342 this, SLOT(thumbnailChanged(qint32,QString)));
44 if (mTelegramClient) {43 connect(mTelegramClient, SIGNAL(contactBigPhotoUpdated(qint32,QString)),
45 setUserId(userId);44 this, SLOT(photoChanged(qint32,QString)));
46 }45
47}46 connect(mTelegramClient, SIGNAL(dialogMuted(qint32,bool)),
4847 this, SLOT(dialogMuted(qint32,bool)));
49void ProfileModel::refresh(qint32 userId) {48 connect(mTelegramClient, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)),
5049 this, SLOT(dialogsMuted(NotifyPeer::NotifyPeerType,bool)));
51 if (userId != mUserId) {50
52 return;51 connect(mTelegramClient, SIGNAL(userBlocked(qint32)),
53 }52 this, SLOT(userBlocked(qint32)));
5453 connect(mTelegramClient, SIGNAL(userUnblocked(qint32)),
55 QSqlQuery query;54 this, SLOT(userUnblocked(qint32)));
56 query.prepare("SELECT firstName, lastName, phone, lastSeenOnline, online, "55 connect(mTelegramClient, SIGNAL(usersBlocked(QList<qint32>)),
57 "(SELECT localPath FROM fileLocations WHERE rowid=thumbnail) AS thumbnail, "56 this, SLOT(usersBlocked(QList<qint32>)));
58 "(SELECT localPath FROM fileLocations WHERE rowid=bigPhoto) AS bigPhoto "57 }
59 "FROM users "58
60 "WHERE id=:id");59 setDialogId(dialogId);
61 query.bindValue(":id", userId);60}
62 if (!query.exec()) {61
63 qCCritical(TG_MODELS_PROFILEMODEL) << "Could not get profile data for user" << userId62void ProfileModel::downloadPhoto() {
64 << query.lastError() << query.lastQuery();63 qCDebug(TG_PLUGIN_LOGIC) << "downloading profile photo";
65 return;64 mTelegramClient->downloadUserBigPhoto(mUserId);
66 }65}
6766
68 if (!query.next()) {67qint32 ProfileModel::getDialogId() const {
69 qCCritical(TG_MODELS_PROFILEMODEL) << "Could not find a register related to user" << userId;68 return mDialogId;
70 return;69}
71 }70
7271void ProfileModel::setDialogId(qint32 dialogId) {
73 setFirstName(query.value("firstName").toString());72 if (mDialogId == dialogId) return;
74 setLastName(query.value("lastName").toString());73 mDialogId = dialogId;
75 setPhone(query.value("phone").toString());74 refreshProfile(dialogId);
76 setThumbnail(query.value("thumbnail").toString());75 Q_EMIT dialogIdChanged(dialogId);
77 setBigPhoto(query.value("bigPhoto").toString());76
78 setLastSeenOnline(query.value("lastSeenOnline").toInt());77 // TBD We'll probably want to call getFullUser and getFullChat (for chat members) here.
79 setOnline(query.value("online").toBool());78}
8079
81 Q_EMIT refreshed();80qint32 ProfileModel::getUserId() const {
82}
83
84void ProfileModel::onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName) {
85
86 if (mUserId != userId) {
87 return;
88 }
89
90 setFirstName(firstName);
91 setLastName(lastName);
92}
93
94void ProfileModel::onContactThumbnailUpdated(qint32 userId, const QString &thumbnail) {
95
96 if (mUserId != userId) {
97 return;
98 }
99 setThumbnail(thumbnail);
100}
101
102void ProfileModel::onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto) {
103
104 if (mUserId != userId) {
105 return;
106 }
107
108 setBigPhoto(bigPhoto);
109}
110
111void ProfileModel::onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline) {
112
113 if (mUserId != userId) {
114 return;
115 }
116
117 setOnline(online);
118 setLastSeenOnline(lastSeenOnline);
119}
120
121qint32 ProfileModel::userId() const {
122 return mUserId;81 return mUserId;
123}82}
12483
125void ProfileModel::setUserId(qint32 userId) {84void ProfileModel::setUserId(qint32 userId) {
126 if (mUserId != userId) {85 if (mUserId == userId) return;
127 mUserId = userId;86 mUserId = userId;
128 if (userId) {87 Q_EMIT userIdChanged(userId);
129 refresh(userId);88}
130 }89
131 Q_EMIT userIdChanged(userId);90qint32 ProfileModel::getChatId() const {
132 }91 return mChatId;
133}92}
13493
135QString ProfileModel::firstName() const {94void ProfileModel::setChatId(qint32 chatId) {
95 if (mChatId == chatId) return;
96 mChatId = chatId;
97 Q_EMIT chatIdChanged(chatId);
98}
99
100void ProfileModel::setUserType(qint32 userType) {
101 if (mUserType == userType) return;
102 mUserType = userType;
103 Q_EMIT userTypeChanged(userType);
104
105 Q_EMIT existsChanged(getExists());
106}
107
108bool ProfileModel::getIsSecret() const {
109 return mIsSecret;
110}
111
112bool ProfileModel::getExists() const {
113 return ((User::UserType)mUserType) != User::typeUserDeleted;
114}
115
116void ProfileModel::setIsSecret(bool isSecret) {
117 if (mIsSecret == isSecret) return;
118 mIsSecret = isSecret;
119 Q_EMIT isSecretChanged(isSecret);
120}
121
122QString ProfileModel::getThumbnail() const {
123 return mThumbnail;
124}
125
126void ProfileModel::setThumbnail(const QString &thumbnail) {
127 if (mThumbnail == thumbnail) return;
128 mThumbnail = thumbnail;
129 Q_EMIT thumbnailChanged(thumbnail);
130}
131
132QString ProfileModel::getPhoto() const {
133 return mPhoto;
134}
135
136void ProfileModel::setPhoto(const QString &photo) {
137 if (mPhoto == photo) return;
138 mPhoto = photo;
139 Q_EMIT photoChanged(photo);
140}
141
142QString ProfileModel::getTitle() const {
143 return mTitle;
144}
145
146void ProfileModel::setTitle(const QString &title) {
147 if (mTitle == title) return;
148 mTitle = title;
149 Q_EMIT titleChanged(title);
150}
151
152QString ProfileModel::getFirstName() const {
136 return mFirstName;153 return mFirstName;
137}154}
138155
139void ProfileModel::setFirstName(const QString &firstName) {156QString ProfileModel::getLastName() const {
140 if (mFirstName != firstName) {
141 mFirstName = firstName;
142 Q_EMIT firstNameChanged(firstName);
143 Q_EMIT fullNameChanged(fullName());
144 }
145}
146
147QString ProfileModel::lastName() const {
148 return mLastName;157 return mLastName;
149}158}
150159
151void ProfileModel::setLastName(const QString &lastName) {160QString ProfileModel::getPhone() const {
152 if (mLastName != lastName) {
153 mLastName = lastName;
154 Q_EMIT lastNameChanged(lastName);
155 Q_EMIT fullNameChanged(fullName());
156 }
157}
158
159QString ProfileModel::fullName() const {
160 QString fullName = mFirstName;
161 if (!mLastName.isEmpty()) {
162 fullName += " " + mLastName;
163 }
164 return fullName;
165}
166
167QString ProfileModel::phone() const {
168 return mPhone;161 return mPhone;
169}162}
170163
171void ProfileModel::setPhone(const QString &phone) {164void ProfileModel::setPhone(const QString &phone) {
172 if (mPhone != phone) {165 if (mPhone == phone) return;
173 mPhone = phone;166 mPhone = phone;
174 Q_EMIT phoneChanged(phone);167 mHasPhone = mPhone.length() > 0;
175 }168 Q_EMIT phoneChanged(phone);
176}169 Q_EMIT hasPhoneChanged(mHasPhone);
177170}
178QString ProfileModel::thumbnail() const {171
179 return mThumbnail;172bool ProfileModel::getHasPhone() const {
180}173 return mHasPhone;
181174}
182void ProfileModel::setThumbnail(const QString &thumbnail) {175
183 if (mThumbnail != thumbnail) {176qint32 ProfileModel::getLastSeen() const {
184 mThumbnail = thumbnail;177 return mLastSeen;
185 Q_EMIT thumbnailChanged(thumbnail);178}
186 }179
187}180void ProfileModel::setLastSeen(qint32 lastSeen) {
188181 if (mLastSeen == lastSeen) return;
189QString ProfileModel::bigPhoto() const {182 mLastSeen = lastSeen;
190 return mBigPhoto;183 Q_EMIT lastSeenChanged(lastSeen);
191}184}
192185
193void ProfileModel::setBigPhoto(const QString &bigPhoto) {186bool ProfileModel::getIsOnline() const {
194 if (mBigPhoto != bigPhoto) {187 return mIsOnline;
195 mBigPhoto = bigPhoto;188}
196 Q_EMIT bigPhotoChanged(bigPhoto);189
197 }190void ProfileModel::setIsOnline(bool isOnline) {
198}191 if (mIsOnline == isOnline) return;
199192 mIsOnline = isOnline;
200qint32 ProfileModel::lastSeenOnline() const {193 Q_EMIT isOnlineChanged(isOnline);
201 return mLastSeenOnline;194}
202}195
203196bool ProfileModel::getIsMuted() const {
204void ProfileModel::setLastSeenOnline(qint32 lastSeenOnline) {197 return mIsMuted;
205 if (mLastSeenOnline != lastSeenOnline) {198}
206 mLastSeenOnline = lastSeenOnline;199
207 Q_EMIT lastSeenOnlineChanged(lastSeenOnline);200void ProfileModel::setIsMuted(bool isMuted) {
208 }201 if (mIsMuted == isMuted) return;
209}202 qCDebug(TG_PLUGIN_LOGIC) << "setIsMuted";
210203 mIsMuted = isMuted;
211bool ProfileModel::online() const {204 Q_EMIT isMutedChanged(isMuted);
212 return mOnline;205}
213}206
214207void ProfileModel::setIsBlocked(bool isBlocked) {
215void ProfileModel::setOnline(bool online) {208 if (mIsBlocked == isBlocked) return;
216 if (mOnline != online) {209 qCDebug(TG_PLUGIN_LOGIC) << "setIsBlocked";
217 mOnline = online;210 mIsBlocked = isBlocked;
218 Q_EMIT onlineChanged(online);211 Q_EMIT isBlockedChanged(isBlocked);
219 }212}
213
214bool ProfileModel::getIsBlocked() const {
215 return mIsBlocked;
216}
217
218void ProfileModel::resetProfile() {
219 mDialogId = 0;
220 setChatId(0);
221 setUserId(0);
222
223 setThumbnail("");
224 setPhoto("");
225 setTitle("");
226 mFirstName = "";
227 mLastName = "";
228
229 setLastSeen(0);
230 setIsOnline(false);
231 setIsMuted(false);
232 setIsBlocked(false);
233}
234
235QString formatFullName(const QString &firstName, const QString &lastName) {
236 QString full(firstName);
237 if (full.length() > 0) {
238 full = full.append(" ");
239 }
240 return full.append(lastName);
241}
242
243void ProfileModel::refreshUserProfile() {
244 QSqlQuery query;
245 query.prepare(QString(
246 "SELECT "
247 " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = thumbnail) as thumbnail, "
248 " (SELECT localPath FROM fileLocations WHERE fileLocations.rowid = bigPhoto) AS photo, "
249 " users.id, phone, firstName, lastName, lastSeenOnline, online, "
250 " type, accessHash, "
251 " coalesce(dialogs.muted, 0) as muted, "
252 " coalesce(blockedUsers.uid, 0) as blocked "
253 "FROM users "
254 " LEFT JOIN dialogs ON users.id = dialogs.id "
255 " LEFT JOIN blockedUsers ON users.id = blockedUsers.uid "
256 "WHERE users.id = :id"));
257 query.bindValue(":id", mUserId);
258
259 if (!query.exec()) {
260 qCCritical(TG_PLUGIN_LOGIC) << "Failed to query user details!"
261 << query.lastError() << query.lastQuery();
262 resetProfile();
263 return;
264 } else if (query.next()) {
265 qint32 userType = query.value("type").toInt();
266 setUserType(userType);
267 mAccessHash = query.value("accessHash").toLongLong();
268
269 QString thumbnail = query.value("thumbnail").toString();
270 setThumbnail(thumbnail);
271 QString photo = query.value("photo").toString();
272 setPhoto(photo);
273 mFirstName = query.value("firstName").toString();
274 mLastName = query.value("lastName").toString();
275 QString title = formatFullName(mFirstName, mLastName);
276 setTitle(title);
277 QString phone = query.value("phone").toString();
278 setPhone(phone);
279 qint32 lastSeen = query.value("lastSeenOnline").toInt();
280 setLastSeen(lastSeen);
281 bool isOnline = query.value("online").toBool();
282 setIsOnline(isOnline);
283 bool isMuted = query.value("muted").toBool();
284 setIsMuted(isMuted);
285 bool isBlocked = query.value("blocked").toInt() != 0;
286 setIsBlocked(isBlocked);
287
288 /*
289 // TODO replace getBlockedContacts with getFullUser
290 InputUser::InputUserType inputUserType = Tools::toInputUserType(mUserType);
291 InputUser inputUser(inputUserType);
292 inputUser.setUserId(mUserId);
293 if (mAccessHash != 0) {
294 inputUser.setAccessHash(mAccessHash);
295 }
296 mTelegramClient->getFullUser(inputUser);
297 */
298 mTelegramClient->getBlockedContacts();
299 }
300}
301
302void ProfileModel::refreshGroupProfile() {
303// TODO: Merge groupmodel into this class.
304}
305
306void ProfileModel::refreshProfile(qint32 dialogId) {
307 if (mDialogId != dialogId) return;
308 qCDebug(TG_PLUGIN_LOGIC) << "Refreshing profile for dialog:" << dialogId;
309
310 QSqlQuery query;
311 query.prepare(QString("SELECT isChat, isSecret, peerId FROM dialogsView WHERE id = :id"));
312 query.bindValue(":id", dialogId);
313
314 if (!query.exec()) {
315 qCCritical(TG_PLUGIN_LOGIC) << "Failed to query profile type!"
316 << query.lastError() << query.lastQuery();
317 resetProfile();
318 return;
319 }
320
321 bool isChat = false;
322 if (query.next()) {
323 isChat = query.value("isChat").toBool();
324 if (isChat) {
325 setChatId(dialogId);
326 } else {
327 bool isSecret = query.value("isSecret").toBool();
328 setIsSecret(isSecret);
329 setUserId(isSecret ? query.value("peerId").toInt() : dialogId);
330 }
331 } else {
332 setUserId(dialogId);
333 }
334
335 if (isChat) {
336 refreshGroupProfile();
337 } else {
338 refreshUserProfile();
339 }
340}
341
342void ProfileModel::contactNameUpdated(qint32 userId, QString firstName, QString lastName) {
343 if (mUserId != userId) return;
344
345 mFirstName = firstName;
346 mLastName = lastName;
347 if (lastName.length() == 0) {
348 setTitle(firstName);
349 } else {
350 setTitle(firstName.append(" ").append(lastName));
351 }
352}
353
354void ProfileModel::thumbnailChanged(qint32 dialogId, QString thumbnail) {
355 if (mDialogId != dialogId) return;
356 setThumbnail(thumbnail);
357}
358
359void ProfileModel::photoChanged(qint32 dialogId, QString photo) {
360 if (mDialogId != dialogId) return;
361 setPhoto(photo);
362}
363
364void ProfileModel::dialogMuted(qint32 dialogId, bool muted) {
365 if (mDialogId != dialogId) return;
366 setIsMuted(muted);
367}
368
369void ProfileModel::dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted) {
370 if (notifyType == NotifyPeer::typeNotifyAll ||
371 notifyType == NotifyPeer::typeNotifyChats) {
372 setIsMuted(muted);
373 }
374}
375
376void ProfileModel::usersBlocked(QList<qint32> ids) {
377 bool isBlocked = ids.indexOf(mUserId) != -1;
378 setIsBlocked(isBlocked);
379}
380
381void ProfileModel::userBlocked(qint32 uid) {
382 if (mUserId != uid) return;
383 setIsBlocked(true);
384}
385
386void ProfileModel::userUnblocked(qint32 uid) {
387 if (mUserId != uid) return;
388 setIsBlocked(false);
220}389}
221390
=== modified file 'qmlplugin/models/profilemodel.h'
--- qmlplugin/models/profilemodel.h 2015-02-18 17:53:54 +0000
+++ qmlplugin/models/profilemodel.h 2015-03-27 11:52:28 +0000
@@ -1,84 +1,169 @@
1#ifndef PROFILEMODEL_H1/*
2#define PROFILEMODEL_H2 * Copyright 2015 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef PROFILE_MODEL_H
18#define PROFILE_MODEL_H
319
4#include <QObject>20#include <QObject>
5#include <QLoggingCategory>21#include <QString>
22
6#include "telegramclient.h"23#include "telegramclient.h"
724#include "dbmanager.h"
8
9Q_DECLARE_LOGGING_CATEGORY(TG_MODELS_PROFILEMODEL)
1025
11class ProfileModel : public QObject26class ProfileModel : public QObject
12{27{
13 Q_OBJECT28 Q_OBJECT
14 Q_PROPERTY(qint32 userId READ userId NOTIFY userIdChanged)29 Q_PROPERTY(qint32 dialogId READ getDialogId WRITE setDialogId NOTIFY dialogIdChanged)
15 Q_PROPERTY(QString firstName READ firstName NOTIFY firstNameChanged)30 Q_PROPERTY(qint32 userId READ getUserId NOTIFY userIdChanged)
16 Q_PROPERTY(QString lastName READ lastName NOTIFY lastNameChanged)31 Q_PROPERTY(qint32 chatId READ getChatId NOTIFY chatIdChanged)
17 Q_PROPERTY(QString fullName READ fullName NOTIFY fullNameChanged)32 Q_PROPERTY(bool isSecret READ getIsSecret NOTIFY isSecretChanged)
18 Q_PROPERTY(QString phone READ phone NOTIFY phoneChanged)33 Q_PROPERTY(bool exists READ getExists NOTIFY existsChanged)
19 Q_PROPERTY(QString thumbnail READ thumbnail NOTIFY thumbnailChanged)34
20 Q_PROPERTY(QString bigPhoto READ bigPhoto NOTIFY bigPhotoChanged)35 Q_PROPERTY(QString thumbnail READ getThumbnail NOTIFY thumbnailChanged)
21 Q_PROPERTY(qint32 lastSeenOnline READ lastSeenOnline NOTIFY lastSeenOnlineChanged)36 Q_PROPERTY(QString photo READ getPhoto NOTIFY photoChanged)
22 Q_PROPERTY(bool online READ online NOTIFY onlineChanged)37 Q_PROPERTY(QString title READ getTitle NOTIFY titleChanged)
38 Q_PROPERTY(QString firstName READ getFirstName)
39 Q_PROPERTY(QString lastName READ getLastName)
40 Q_PROPERTY(QString phone READ getPhone NOTIFY phoneChanged)
41 Q_PROPERTY(bool hasPhone READ getHasPhone NOTIFY phoneChanged)
42
43// Q_PROPERTY(QString memberCount READ getMemberCount NOTIFY memberCountChanged)
44// Q_PROPERTY(qint32 onlineCount READ getOnlineCount NOTIFY onlineCountChanged)
45
46 Q_PROPERTY(qint32 lastSeen READ getLastSeen NOTIFY lastSeenChanged)
47 Q_PROPERTY(bool isOnline READ getIsOnline NOTIFY isOnlineChanged)
48
49 Q_PROPERTY(bool isMuted READ getIsMuted NOTIFY isMutedChanged)
50 Q_PROPERTY(bool isBlocked READ getIsBlocked NOTIFY isBlockedChanged)
2351
24public:52public:
25 explicit ProfileModel(QObject *parent = 0);53 explicit ProfileModel(QObject *parent = 0);
26 ~ProfileModel();54 ~ProfileModel();
2755
28 Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 userId);56 Q_INVOKABLE void setup(TelegramClient *telegramClient, qint32 dialogId);
29 void reset();57 Q_INVOKABLE void downloadPhoto();
3058 void resetProfile();
31 QString fullName() const;59
3260 void setDialogId(qint32 dialogId);
33 virtual qint32 userId() const;61 qint32 getDialogId() const;
34 virtual void setUserId(qint32 userId);62 qint32 getUserId() const;
35 virtual QString firstName() const;63 qint32 getChatId() const;
36 virtual void setFirstName(const QString &firstName);64 bool getIsSecret() const;
37 virtual QString lastName() const;65 bool getExists() const;
38 virtual void setLastName(const QString &lastName);66
39 virtual QString phone() const;67 QString getThumbnail() const;
40 virtual void setPhone(const QString &phone);68 QString getPhoto() const;
41 virtual QString thumbnail() const;69 QString getTitle() const;
42 virtual void setThumbnail(const QString &thumbnail);70 QString getFirstName() const;
43 virtual QString bigPhoto() const;71 QString getLastName() const;
44 virtual void setBigPhoto(const QString &bigPhoto);72 QString getPhone() const;
45 virtual qint32 lastSeenOnline() const;73 bool getHasPhone() const;
46 virtual void setLastSeenOnline(qint32 lastSeenOnline);74
47 virtual bool online() const;75// qint32 getMemberCount() const;
48 virtual void setOnline(bool online);76// qint32 getOnlineCount() const;
4977
50Q_SIGNALS:78 qint32 getLastSeen() const;
51 void refreshed();79 bool getIsOnline() const;
5280
53 void userIdChanged(qint32);81 bool getIsMuted() const;
54 void firstNameChanged(QString);82 bool getIsBlocked() const;
55 void lastNameChanged(QString);83
56 void fullNameChanged(QString);84public Q_SLOTS:
57 void phoneChanged(QString);85 void refreshProfile(qint32 dialogId);
58 void thumbnailChanged(QString);86
59 void bigPhotoChanged(QString);87 void contactNameUpdated(qint32 userId, QString firstName, QString lastName);
60 void lastSeenOnlineChanged(qint32);88 void thumbnailChanged(qint32 dialogId, QString thumbnail);
61 void onlineChanged(bool);89 void photoChanged(qint32 dialogId, QString photo);
6290 void dialogMuted(qint32 dialogId, bool muted);
63protected Q_SLOTS:91 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
64 void refresh(qint32 userId);92 void usersBlocked(QList<qint32> ids);
6593 void userBlocked(qint32 uid);
66 void onContactNameUpdated(qint32 userId, const QString &firstName, const QString &lastName);94 void userUnblocked(qint32 uid);
67 void onContactThumbnailUpdated(qint32 userId, const QString &thumbnail);95
68 void onContactBigPhotoUpdated(qint32 userId, const QString &bigPhoto);96Q_SIGNALS:
69 void onContactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline);97 void profileDetailsRefreshed();
7098
71protected:99private:
72 TelegramClient *mTelegramClient;100 void setUserId(qint32 userId);
73101 void setChatId(qint32 chatId);
102 void setUserType(qint32 type);
103 void setIsSecret(bool isSecret);
104
105 void setThumbnail(const QString &thumbnail);
106 void setPhoto(const QString &photo);
107 void setTitle(const QString &title);
108 void setPhone(const QString &phone);
109
110 void setLastSeen(qint32 lastSeen);
111 void setIsOnline(bool isOnline);
112
113 void setIsMuted(bool isMuted);
114 void setIsBlocked(bool isBlocked);
115
116 void refreshUserProfile();
117 void refreshGroupProfile();
118
119Q_SIGNALS:
120 void profileUpdated(qint32 dialogId);
121
122 void dialogIdChanged(qint32 dialogId);
123 void userIdChanged(qint32 userId);
124 void chatIdChanged(qint32 chatId);
125 void userTypeChanged(qint32 userType);
126 void isSecretChanged(bool isSecret);
127 void existsChanged(bool exists);
128
129 void thumbnailChanged(QString thumbnail);
130 void photoChanged(QString photo);
131 void titleChanged(QString title);
132 void phoneChanged(QString phone);
133 void hasPhoneChanged(bool hasPhone);
134
135 void lastSeenChanged(qint32 lastSeen);
136 void isOnlineChanged(bool isOnline);
137
138 void isMutedChanged(bool isMuted);
139 void isBlockedChanged(bool isBlocked);
140
141private:
142 TelegramClient* mTelegramClient;
143
144 qint32 mDialogId;
74 qint32 mUserId;145 qint32 mUserId;
146 qint32 mChatId;
147 qint32 mUserType;
148 qint64 mAccessHash;
149 bool mIsSecret;
150
151 QString mThumbnail;
152 QString mPhoto;
153 QString mTitle;
75 QString mFirstName;154 QString mFirstName;
76 QString mLastName;155 QString mLastName;
77 QString mPhone;156 QString mPhone;
78 QString mThumbnail;157 bool mHasPhone;
79 QString mBigPhoto;158
80 qint32 mLastSeenOnline;159// qint32 mMemberCount;
81 bool mOnline;160// qint32 mOnlineCount;
161
162 qint32 mLastSeen;
163 bool mIsOnline;
164
165 bool mIsMuted;
166 bool mIsBlocked;
82};167};
83168
84#endif // PROFILEMODEL_H169#endif
85170
=== modified file 'qmlplugin/rawapiclient.cpp'
--- qmlplugin/rawapiclient.cpp 2015-02-26 21:10:13 +0000
+++ qmlplugin/rawapiclient.cpp 2015-03-27 11:52:28 +0000
@@ -250,6 +250,18 @@
250 Q_ARG(QList<InputContact>, contactsList), Q_ARG(bool, replace));250 Q_ARG(QList<InputContact>, contactsList), Q_ARG(bool, replace));
251}251}
252252
253void RawApiClient::getBlockedContacts() {
254 QMetaObject::invokeMethod(mTelegramService, "getBlockedContacts", Qt::QueuedConnection);
255}
256
257void RawApiClient::blockContact(TLInputPeer *peer) {
258 QMetaObject::invokeMethod(mTelegramService, "blockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer));
259}
260
261void RawApiClient::unblockContact(TLInputPeer *peer) {
262 QMetaObject::invokeMethod(mTelegramService, "unblockContact", Qt::QueuedConnection, Q_ARG(InputPeer, *peer));
263}
264
253// Working with messages265// Working with messages
254void RawApiClient::messagesSendMessage(TLInputPeer *peer, const QString &message) {266void RawApiClient::messagesSendMessage(TLInputPeer *peer, const QString &message) {
255 QMetaObject::invokeMethod(mTelegramService, "messagesSendMessage", Qt::QueuedConnection,267 QMetaObject::invokeMethod(mTelegramService, "messagesSendMessage", Qt::QueuedConnection,
@@ -313,7 +325,6 @@
313}325}
314326
315void RawApiClient::messagesCreateChat(const QVariantList &users, const QString &title) {327void RawApiClient::messagesCreateChat(const QVariantList &users, const QString &title) {
316
317 QList<InputUser> groupUsers = toQList<InputUser>(users);328 QList<InputUser> groupUsers = toQList<InputUser>(users);
318 QMetaObject::invokeMethod(mTelegramService, "messagesCreateChat", Qt::QueuedConnection,329 QMetaObject::invokeMethod(mTelegramService, "messagesCreateChat", Qt::QueuedConnection,
319 Q_ARG(QList<InputUser>, groupUsers), Q_ARG(QString, title));330 Q_ARG(QList<InputUser>, groupUsers), Q_ARG(QString, title));
320331
=== modified file 'qmlplugin/rawapiclient.h'
--- qmlplugin/rawapiclient.h 2015-02-26 21:10:13 +0000
+++ qmlplugin/rawapiclient.h 2015-03-27 11:52:28 +0000
@@ -98,9 +98,13 @@
98 Q_INVOKABLE void accountRegisterDevice(const QString &token, const QString &appVersion = "", bool appSandbox = false);98 Q_INVOKABLE void accountRegisterDevice(const QString &token, const QString &appVersion = "", bool appSandbox = false);
99 Q_INVOKABLE void accountUnregisterDevice(const QString &token);99 Q_INVOKABLE void accountUnregisterDevice(const QString &token);
100 Q_INVOKABLE void accountUpdateProfile(const QString &firstName, const QString &lastName);100 Q_INVOKABLE void accountUpdateProfile(const QString &firstName, const QString &lastName);
101
101 // Working with contacts102 // Working with contacts
102 Q_INVOKABLE void contactsGetContacts();103 Q_INVOKABLE void contactsGetContacts();
103 Q_INVOKABLE void contactsImportContacts(const QVariantList &contacts, bool replace = false);104 Q_INVOKABLE void contactsImportContacts(const QVariantList &contacts, bool replace = false);
105 Q_INVOKABLE void getBlockedContacts();
106 Q_INVOKABLE void blockContact(TLInputPeer *peer);
107 Q_INVOKABLE void unblockContact(TLInputPeer *peer);
104108
105 // Working with messages109 // Working with messages
106 Q_INVOKABLE void messagesSendMessage(TLInputPeer *peer, const QString &message);110 Q_INVOKABLE void messagesSendMessage(TLInputPeer *peer, const QString &message);
@@ -116,7 +120,6 @@
116 Q_INVOKABLE void messagesSetTyping(TLInputPeer *peer);120 Q_INVOKABLE void messagesSetTyping(TLInputPeer *peer);
117 Q_INVOKABLE void messagesSetEncryptedTyping(qint32 chatId, bool typing);121 Q_INVOKABLE void messagesSetEncryptedTyping(qint32 chatId, bool typing);
118122
119
120 // Working with chats123 // Working with chats
121 Q_INVOKABLE void messagesCreateChat(const QVariantList &users, const QString &title);124 Q_INVOKABLE void messagesCreateChat(const QVariantList &users, const QString &title);
122 Q_INVOKABLE void messagesGetFullChat(qint32 chatId);125 Q_INVOKABLE void messagesGetFullChat(qint32 chatId);
123126
=== modified file 'qmlplugin/rawapiservice.cpp'
--- qmlplugin/rawapiservice.cpp 2015-03-02 21:17:11 +0000
+++ qmlplugin/rawapiservice.cpp 2015-03-27 11:52:28 +0000
@@ -83,6 +83,8 @@
8383
84 // Working with contacts84 // Working with contacts
85 connect(mTelegramLib, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));85 connect(mTelegramLib, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)), this, SIGNAL(contactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));
86 connect(mTelegramLib, SIGNAL(contactsBlockAnswer(qint64,bool)), this, SIGNAL(contactsBlockAnswer(qint64,bool)));
87 connect(mTelegramLib, SIGNAL(contactsUnblockAnswer(qint64,bool)), this, SIGNAL(contactsUnblockAnswer(qint64,bool)));
8688
87 // Working with updates signal-slot89 // Working with updates signal-slot
88 connect(mTelegramLib, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)));90 connect(mTelegramLib, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)), this, SIGNAL(updatesGetStateAnswer(qint64,qint32,qint32,qint32,qint32,qint32)));
8991
=== modified file 'qmlplugin/rawapiservice.h'
--- qmlplugin/rawapiservice.h 2015-03-02 21:17:11 +0000
+++ qmlplugin/rawapiservice.h 2015-03-27 11:52:28 +0000
@@ -150,6 +150,8 @@
150 // Working with blacklist150 // Working with blacklist
151 void contactsBlockAnswer(qint64 id, bool ok);151 void contactsBlockAnswer(qint64 id, bool ok);
152 void contactsUnblockAnswer(qint64 id, bool ok);152 void contactsUnblockAnswer(qint64 id, bool ok);
153 void contactsBlockResult(qint64 id, bool ok);
154 void contactsUnblockResult(qint64 id, bool ok);
153 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);155 void contactsGetBlockedAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
154156
155 // Working with messages157 // Working with messages
156158
=== modified file 'qmlplugin/telegramclient.cpp'
--- qmlplugin/telegramclient.cpp 2015-03-04 21:24:05 +0000
+++ qmlplugin/telegramclient.cpp 2015-03-27 11:52:28 +0000
@@ -59,6 +59,9 @@
59 connect(mTelegramService, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)), Qt::QueuedConnection);59 connect(mTelegramService, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)), Qt::QueuedConnection);
60 connect(mTelegramService, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)), Qt::QueuedConnection);60 connect(mTelegramService, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)), Qt::QueuedConnection);
61 connect(mTelegramService, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)), Qt::QueuedConnection);61 connect(mTelegramService, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)), Qt::QueuedConnection);
62 connect(mTelegramService, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>)));
63 connect(mTelegramService, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32)));
64 connect(mTelegramService, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32)));
62 connect(mTelegramService, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)), Qt::QueuedConnection);65 connect(mTelegramService, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)), Qt::QueuedConnection);
63 connect(mTelegramService, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), Qt::QueuedConnection);66 connect(mTelegramService, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), Qt::QueuedConnection);
64 connect(mTelegramService, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)), Qt::QueuedConnection);67 connect(mTelegramService, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)), Qt::QueuedConnection);
6568
=== modified file 'qmlplugin/telegramclient.h'
--- qmlplugin/telegramclient.h 2015-03-04 21:10:13 +0000
+++ qmlplugin/telegramclient.h 2015-03-27 11:52:28 +0000
@@ -128,6 +128,9 @@
128 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);128 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);
129 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);129 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
130 void dialogTitleUpdated(qint32 dialogId, const QString &title);130 void dialogTitleUpdated(qint32 dialogId, const QString &title);
131 void usersBlocked(QList<qint32> ids);
132 void userBlocked(qint32 id);
133 void userUnblocked(qint32 id);
131 void dialogMuted(qint32 dialogId, bool muted);134 void dialogMuted(qint32 dialogId, bool muted);
132 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);135 void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted);
133 void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount);136 void messagesAdded(const QList<MessageItem> &messages, qint32 totalCount);
134137
=== modified file 'qmlplugin/telegramplugin.cpp'
--- qmlplugin/telegramplugin.cpp 2015-02-18 17:53:54 +0000
+++ qmlplugin/telegramplugin.cpp 2015-03-27 11:52:28 +0000
@@ -49,8 +49,10 @@
49#include "models/messagesmodel.h"49#include "models/messagesmodel.h"
50#include "models/contactsmodel.h"50#include "models/contactsmodel.h"
51#include "models/contactsproxy.h"51#include "models/contactsproxy.h"
52#include "models/profilemodel.h"
52#include "models/groupmodel.h"53#include "models/groupmodel.h"
53#include "models/groupmembersmodel.h"54#include "models/groupmembersmodel.h"
55#include "models/blockedusersmodel.h"
54#include "models/dialogsmodel.h"56#include "models/dialogsmodel.h"
55#include "models/dialogsproxy.h"57#include "models/dialogsproxy.h"
56#include "models/sortproxymodel.h"58#include "models/sortproxymodel.h"
@@ -118,8 +120,10 @@
118 qmlRegisterType<ContactsModel>(uri, 0, 1, "ContactsModel");120 qmlRegisterType<ContactsModel>(uri, 0, 1, "ContactsModel");
119 qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel");121 qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel");
120 qmlRegisterType<ContactsProxy>(uri, 0, 1, "ContactsProxy");122 qmlRegisterType<ContactsProxy>(uri, 0, 1, "ContactsProxy");
123 qmlRegisterType<ProfileModel>(uri, 0, 1, "ProfileModel");
121 qmlRegisterType<GroupModel>(uri, 0, 1, "GroupModel");124 qmlRegisterType<GroupModel>(uri, 0, 1, "GroupModel");
122 qmlRegisterType<GroupMembersModel>(uri, 0, 1, "GroupMembersModel");125 qmlRegisterType<GroupMembersModel>(uri, 0, 1, "GroupMembersModel");
126 qmlRegisterType<BlockedUsersModel>(uri, 0, 1, "BlockedUsersModel");
123 qmlRegisterType<DialogItem>(uri, 0, 1, "DialogItem");127 qmlRegisterType<DialogItem>(uri, 0, 1, "DialogItem");
124 qmlRegisterType<MessageItem>(uri, 0, 1, "MessageItem");128 qmlRegisterType<MessageItem>(uri, 0, 1, "MessageItem");
125 qmlRegisterType<ContactItem>(uri, 0, 1, "ContactItem");129 qmlRegisterType<ContactItem>(uri, 0, 1, "ContactItem");
126130
=== modified file 'qmlplugin/telegramservice.cpp'
--- qmlplugin/telegramservice.cpp 2015-03-04 21:10:13 +0000
+++ qmlplugin/telegramservice.cpp 2015-03-27 11:52:28 +0000
@@ -46,6 +46,9 @@
46 connect(&mData, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)));46 connect(&mData, SIGNAL(chatBigPhotoUpdated(qint32,QString)), SIGNAL(chatBigPhotoUpdated(qint32,QString)));
47 connect(&mData, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)));47 connect(&mData, SIGNAL(dialogThumbnailUpdated(qint32,QString)), SIGNAL(dialogThumbnailUpdated(qint32,QString)));
48 connect(&mData, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)));48 connect(&mData, SIGNAL(dialogTitleUpdated(qint32,QString)), SIGNAL(dialogTitleUpdated(qint32,QString)));
49 connect(&mData, SIGNAL(usersBlocked(QList<qint32>)), SIGNAL(usersBlocked(QList<qint32>)));
50 connect(&mData, SIGNAL(userBlocked(qint32)), SIGNAL(userBlocked(qint32)));
51 connect(&mData, SIGNAL(userUnblocked(qint32)), SIGNAL(userUnblocked(qint32)));
49 connect(&mData, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)));52 connect(&mData, SIGNAL(dialogMuted(qint32,bool)), SIGNAL(dialogMuted(qint32,bool)));
50 connect(&mData, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)));53 connect(&mData, SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)), SIGNAL(dialogsMuted(NotifyPeer::NotifyPeerType,bool)));
51 connect(&mData, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)));54 connect(&mData, SIGNAL(messageAdded(MessageItem)), SIGNAL(messageAdded(MessageItem)));
@@ -291,6 +294,18 @@
291 &mData,294 &mData,
292 SLOT(onContactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));295 SLOT(onContactsImportContactsAnswer(qint64,QList<ImportedContact>,QList<qint64>,QList<User>)));
293 connect(mTelegramLib,296 connect(mTelegramLib,
297 SIGNAL(contactsGetBlockedAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>)),
298 &mData,
299 SLOT(onGetBlockedContactsAnswer(qint64,qint32,QList<ContactBlocked>,QList<User>)));
300 connect(mTelegramLib,
301 SIGNAL(contactsBlockAnswer(qint64,bool)),
302 &mData,
303 SLOT(onBlockContactAnswer(qint64,bool)));
304 connect(mTelegramLib,
305 SIGNAL(contactsUnblockAnswer(qint64,bool)),
306 &mData,
307 SLOT(onUnblockContactsAnswer(qint64,bool)));
308 connect(mTelegramLib,
294 SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool)),309 SIGNAL(accountUpdateNotifySettingsAnswer(qint64,bool)),
295 &mData,310 &mData,
296 SLOT(onAccountUpdateNotifySettingsAnswer(qint64,bool)));311 SLOT(onAccountUpdateNotifySettingsAnswer(qint64,bool)));
@@ -409,6 +424,26 @@
409 return RawApiService::contactsImportContacts(contacts);424 return RawApiService::contactsImportContacts(contacts);
410}425}
411426
427void TelegramService::getBlockedContacts() {
428 mTelegramLib->contactsGetBlocked(0, 200);
429}
430
431void TelegramService::blockContact(InputPeer peer) {
432 const ContactItem &contactItem = mData.getUser(peer.userId());
433 InputUser inputUser = Tools::toInputUser(contactItem);
434
435 qint64 requestId = mTelegramLib->contactsBlock(inputUser);
436 mData.mBlockRequests.insert(requestId, peer.userId());
437}
438
439void TelegramService::unblockContact(InputPeer peer) {
440 const ContactItem &contactItem = mData.getUser(peer.userId());
441 InputUser inputUser = Tools::toInputUser(contactItem);
442
443 qint64 requestId = mTelegramLib->contactsUnblock(inputUser);
444 mData.mBlockRequests.insert(requestId, peer.userId());
445}
446
412qint64 TelegramService::messagesReadHistory(InputPeer inputPeer, qint32 maxId, qint32 offset, bool readContents) {447qint64 TelegramService::messagesReadHistory(InputPeer inputPeer, qint32 maxId, qint32 offset, bool readContents) {
413448
414 // if peer is foreign, get access hash from db449 // if peer is foreign, get access hash from db
415450
=== modified file 'qmlplugin/telegramservice.h'
--- qmlplugin/telegramservice.h 2015-03-04 21:24:05 +0000
+++ qmlplugin/telegramservice.h 2015-03-27 11:52:28 +0000
@@ -55,6 +55,11 @@
55 qint64 uploadProfilePhoto(const QString &filePath, const QString &caption = "", double geoPointLat = 0, double geoPointLong = 0, double cropLeft = 0, double cropTop = 0, double cropWidth = 0);55 qint64 uploadProfilePhoto(const QString &filePath, const QString &caption = "", double geoPointLat = 0, double geoPointLong = 0, double cropLeft = 0, double cropTop = 0, double cropWidth = 0);
56 void getUser(qint32 userId);56 void getUser(qint32 userId);
57 qint64 addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber);57 qint64 addContact(const QString &firstName, const QString &lastName, const QString &phoneNumber);
58 void getBlockedContacts();
59 void getBlockedContactsAnswer(qint64 id, qint32 sliceCount, QList<ContactBlocked> blocked, QList<User> users);
60 void blockContact(InputPeer peer);
61 void unblockContact(InputPeer peer);
62
58 qint64 messagesReadHistory(InputPeer peer, qint32 maxId = 0, qint32 offset = 0, bool readContents = true);63 qint64 messagesReadHistory(InputPeer peer, qint32 maxId = 0, qint32 offset = 0, bool readContents = true);
59 qint64 deleteChatHistory(InputPeer inputPeer, qint32 offset = 0, bool deleteChat = false);64 qint64 deleteChatHistory(InputPeer inputPeer, qint32 offset = 0, bool deleteChat = false);
60 qint64 messagesSendMessage(InputPeer peer, const QString &message);65 qint64 messagesSendMessage(InputPeer peer, const QString &message);
@@ -123,6 +128,9 @@
123 void contactThumbnailUpdated(qint32 userId, const QString &thumbnail);128 void contactThumbnailUpdated(qint32 userId, const QString &thumbnail);
124 void contactBigPhotoUpdated(qint32 userId, const QString &bigPhoto);129 void contactBigPhotoUpdated(qint32 userId, const QString &bigPhoto);
125 void contactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline);130 void contactStatusUpdated(qint32 userId, bool online, qint32 lastSeenOnline);
131 void usersBlocked(QList<qint32> ids);
132 void userBlocked(qint32 id);
133 void userUnblocked(qint32 id);
126 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);134 void chatBigPhotoUpdated(qint32 chatId, const QString &bigPhoto);
127 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);135 void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail);
128 void dialogTitleUpdated(qint32 dialogId, const QString &title);136 void dialogTitleUpdated(qint32 dialogId, const QString &title);

Subscribers

People subscribed via source and target branches

to all changes: