Merge lp:~libqtelegram-team/telegram-app/dev-secret-media-nosave into lp:telegram-app/trunk
- dev-secret-media-nosave
- Merge into trunk
Proposed by
Michał Karnicki
Status: | Superseded |
---|---|
Proposed branch: | lp:~libqtelegram-team/telegram-app/dev-secret-media-nosave |
Merge into: | lp:telegram-app/trunk |
Diff against target: |
714 lines (+216/-32) 15 files modified
lib/core/settings.cpp (+17/-9) lib/secret/decrypter.cpp (+1/-2) lib/secret/secretchatmessage.h (+4/-0) lib/telegram.cpp (+7/-3) lib/types/message.h (+9/-0) qmlplugin/data.cpp (+137/-17) qmlplugin/data.h (+9/-0) qmlplugin/models/messageitem.cpp (+3/-0) qmlplugin/models/messageitem.h (+2/-0) qmlplugin/models/messagesmodel.cpp (+4/-0) qmlplugin/models/messagesmodel.h (+1/-0) qmlplugin/models/messagesview.cpp (+4/-1) qmlplugin/telegramservice.cpp (+16/-0) qmlplugin/telegramservice.h (+1/-0) qmlplugin/types/tlmessage.h (+1/-0) |
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/dev-secret-media-nosave |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Roberto Mier Escandon (community) | Needs Resubmitting | ||
Review via email: mp+249860@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-02-18.
Commit message
Description of the change
Surfaced TTL on MessageItem in messages model.
Tested by creating:
1) secret chat from Ubuntu and
2) secret chat from Android and
for each of those
a) sent self destruct message (in and out)
b) sent regular message, then sent a self destruct msg (regular message stays, self destruct destroys)
To post a comment you must log in.
Revision history for this message
Roberto Mier Escandon (rmescandon) wrote : | # |
review:
Needs Resubmitting
Unmerged revisions
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'lib/core/settings.cpp' |
2 | --- lib/core/settings.cpp 2015-02-04 15:57:51 +0000 |
3 | +++ lib/core/settings.cpp 2015-02-17 13:31:13 +0000 |
4 | @@ -219,13 +219,17 @@ |
5 | secretChat->setState((SecretChat::State)settings.value(ST_STATE, 0).toInt()); |
6 | |
7 | QByteArray base64Sk = settings.value(ST_SHARED_KEY).toByteArray(); |
8 | - QByteArray parsedSk = QByteArray::fromBase64(base64Sk); |
9 | - memcpy(secretChat->sharedKey(), parsedSk.data(), SHARED_KEY_LENGTH); |
10 | + if (!base64Sk.isEmpty()) { |
11 | + QByteArray parsedSk = QByteArray::fromBase64(base64Sk); |
12 | + memcpy(secretChat->sharedKey(), parsedSk.data(), SHARED_KEY_LENGTH); |
13 | + } |
14 | |
15 | QByteArray base64Mk = settings.value(ST_MY_KEY).toByteArray(); |
16 | - QByteArray parsedMk = QByteArray::fromBase64(base64Mk); |
17 | - BIGNUM *myKey = Utils::bytesToBignum(parsedMk); |
18 | - secretChat->setMyKey(myKey); |
19 | + if (!base64Mk.isEmpty()) { |
20 | + QByteArray parsedMk = QByteArray::fromBase64(base64Mk); |
21 | + BIGNUM *myKey = Utils::bytesToBignum(parsedMk); |
22 | + secretChat->setMyKey(myKey); |
23 | + } |
24 | |
25 | secretChat->setLayer(settings.value(ST_LAYER, 0).toInt()); |
26 | secretChat->setInSeqNo(settings.value(ST_IN_SEQ_NO, 0).toInt()); |
27 | @@ -263,11 +267,15 @@ |
28 | settings.setValue(ST_STATE, secretChat->state()); |
29 | |
30 | BIGNUM *myKey = secretChat->myKey(); |
31 | - QByteArray myKeyToSave = Utils::bignumToBytes(myKey); |
32 | - settings.setValue(ST_MY_KEY, myKeyToSave.toBase64()); |
33 | + if (myKey) { |
34 | + QByteArray myKeyToSave = Utils::bignumToBytes(myKey); |
35 | + settings.setValue(ST_MY_KEY, myKeyToSave.toBase64()); |
36 | + } |
37 | |
38 | - QByteArray sharedKeyToSave((char *)secretChat->sharedKey(), SHARED_KEY_LENGTH); |
39 | - settings.setValue(ST_SHARED_KEY, sharedKeyToSave.toBase64()); |
40 | + if (secretChat->sharedKey()) { |
41 | + QByteArray sharedKeyToSave((char *)secretChat->sharedKey(), SHARED_KEY_LENGTH); |
42 | + settings.setValue(ST_SHARED_KEY, sharedKeyToSave.toBase64()); |
43 | + } |
44 | |
45 | settings.setValue(ST_LAYER, secretChat->layer()); |
46 | settings.setValue(ST_IN_SEQ_NO, secretChat->inSeqNo()); |
47 | |
48 | === modified file 'lib/secret/decrypter.cpp' |
49 | --- lib/secret/decrypter.cpp 2015-01-28 15:50:32 +0000 |
50 | +++ lib/secret/decrypter.cpp 2015-02-17 13:31:13 +0000 |
51 | @@ -103,7 +103,6 @@ |
52 | deflatedOutSeqNo = receivedOutSeqNoParam / 2; |
53 | qint32 deflatedInSeqNo = receivedInSeqNoParam / 2; |
54 | |
55 | - |
56 | if (deflatedOutSeqNo != mSecretChat->inSeqNo()) { |
57 | if (deflatedOutSeqNo < mSecretChat->inSeqNo()) { |
58 | qCWarning(TG_LIB_SECRET) << "Received out_seq_no (" << deflatedOutSeqNo |
59 | @@ -111,7 +110,7 @@ |
60 | processMessage = false; |
61 | } else if (deflatedOutSeqNo > mSecretChat->inSeqNo()) { |
62 | qCWarning(TG_LIB_SECRET) << "Found gap since received out_seq_no (" << deflatedOutSeqNo |
63 | - << ") is greter than expected (" << mSecretChat->inSeqNo() |
64 | + << ") is greater than expected (" << mSecretChat->inSeqNo() |
65 | << "). Requesting intermediate messages to fill the gap"; |
66 | processMessage = false; |
67 | // set gap flag to true, to store the incoming message into a gap waiting queue until solving the gap |
68 | |
69 | === modified file 'lib/secret/secretchatmessage.h' |
70 | --- lib/secret/secretchatmessage.h 2015-01-23 15:34:54 +0000 |
71 | +++ lib/secret/secretchatmessage.h 2015-02-17 13:31:13 +0000 |
72 | @@ -9,15 +9,18 @@ |
73 | public: |
74 | explicit SecretChatMessage() : |
75 | mChatId(0), |
76 | + mTtl(0), |
77 | mDate(0), |
78 | mDecryptedMessage(DecryptedMessage::typeDecryptedMessage_level8), |
79 | mAttachment(EncryptedFile::typeEncryptedFileEmpty) {} |
80 | |
81 | qint32 chatId() const { return mChatId; } |
82 | + qint32 ttl() const { return mTtl; } |
83 | qint32 date() const { return mDate; } |
84 | DecryptedMessage decryptedMessage() const { return mDecryptedMessage; } |
85 | EncryptedFile attachment() const { return mAttachment; } |
86 | void setChatId(qint32 chatId) { mChatId = chatId; } |
87 | + void setTtl(qint32 ttl) { mTtl = ttl; } |
88 | void setDate(qint32 date) { mDate = date; } |
89 | void setDecryptedMessage(const DecryptedMessage &decryptedMessage) { mDecryptedMessage = decryptedMessage; } |
90 | void setAttachment(const EncryptedFile &attachment) { mAttachment = attachment; } |
91 | @@ -29,6 +32,7 @@ |
92 | |
93 | private: |
94 | qint32 mChatId; |
95 | + qint32 mTtl; |
96 | qint32 mDate; |
97 | DecryptedMessage mDecryptedMessage; |
98 | EncryptedFile mAttachment; |
99 | |
100 | === modified file 'lib/telegram.cpp' |
101 | --- lib/telegram.cpp 2015-02-12 15:30:59 +0000 |
102 | +++ lib/telegram.cpp 2015-02-17 13:31:13 +0000 |
103 | @@ -628,11 +628,14 @@ |
104 | DecryptedMessage decrypted = mDecrypter.decryptEncryptedData(encrypted.randomId(), encrypted.bytes()); |
105 | secretChatMessage.setDecryptedMessage(decrypted); |
106 | |
107 | - EncryptedFile attachment = encrypted.file(); |
108 | // if having a not 0 randomId, the decrypted message is valid |
109 | if (decrypted.randomId()) { |
110 | + |
111 | + EncryptedFile attachment = encrypted.file(); |
112 | + |
113 | //if attachment, check keyFingerprint |
114 | if (attachment.classType() != EncryptedFile::typeEncryptedFileEmpty) { |
115 | + |
116 | qint32 receivedKeyFingerprint = attachment.keyFingerprint(); |
117 | const QByteArray &key = decrypted.media().key(); |
118 | const QByteArray &iv = decrypted.media().iv(); |
119 | @@ -648,10 +651,10 @@ |
120 | |
121 | secretChatMessage.setAttachment(attachment); |
122 | } |
123 | + |
124 | + mSecretState.save(); |
125 | } |
126 | |
127 | - mSecretState.save(); |
128 | - |
129 | return secretChatMessage; |
130 | } |
131 | |
132 | @@ -661,6 +664,7 @@ |
133 | EncryptedMessage encrypted = update.encryptedMessage(); |
134 | |
135 | SecretChatMessage secretChatMessage = toSecretChatMessage(encrypted); |
136 | + |
137 | // if having a not 0 randomId, the decrypted message is valid |
138 | if (secretChatMessage.decryptedMessage().randomId()) { |
139 | mSecretState.save(); |
140 | |
141 | === modified file 'lib/types/message.h' |
142 | --- lib/types/message.h 2015-01-28 08:01:23 +0000 |
143 | +++ lib/types/message.h 2015-02-17 13:31:13 +0000 |
144 | @@ -47,6 +47,7 @@ |
145 | |
146 | Message() : |
147 | m_id(0), |
148 | + m_ttl(0), |
149 | m_toId(Peer::typePeerUser), |
150 | m_unread(false), |
151 | m_action(MessageAction::typeMessageActionEmpty), |
152 | @@ -62,6 +63,7 @@ |
153 | |
154 | Message(MessageType classType) : |
155 | m_id(0), |
156 | + m_ttl(0), |
157 | m_toId(Peer::typePeerUser), |
158 | m_unread(false), |
159 | m_action(MessageAction::typeMessageActionEmpty), |
160 | @@ -80,6 +82,12 @@ |
161 | qint32 id() const { |
162 | return m_id; |
163 | } |
164 | + void setTtl(qint32 ttl) { |
165 | + m_ttl = ttl; |
166 | + } |
167 | + qint32 ttl() const { |
168 | + return m_ttl; |
169 | + } |
170 | void setFromId(qint32 fromId) { |
171 | m_fromId = fromId; |
172 | } |
173 | @@ -149,6 +157,7 @@ |
174 | |
175 | private: |
176 | qint32 m_id; |
177 | + qint32 m_ttl; |
178 | Peer m_toId; |
179 | bool m_unread; |
180 | MessageAction m_action; |
181 | |
182 | === modified file 'qmlplugin/data.cpp' |
183 | --- qmlplugin/data.cpp 2015-02-11 11:52:21 +0000 |
184 | +++ qmlplugin/data.cpp 2015-02-17 13:31:13 +0000 |
185 | @@ -89,10 +89,11 @@ |
186 | |
187 | qCDebug(TG_PLUGIN_LOGIC) << "onUpdatesGetStateAnswer"; |
188 | |
189 | + TelegramService *service = static_cast<TelegramService *>(mServiceRef); |
190 | + |
191 | UpdatesState clientState = getState(); |
192 | |
193 | if ( (clientState.seq() > 0 && clientState.seq() < seq) || (seq == 1 && clientState.pts() < pts) ){ |
194 | - TelegramService *service = static_cast<TelegramService *>(mServiceRef); |
195 | service->updatesGetDifference(clientState.pts(), clientState.date(), clientState.qts()); |
196 | } |
197 | |
198 | @@ -501,6 +502,9 @@ |
199 | } |
200 | Q_EMIT dialogThumbnailUpdated(id, filePath); |
201 | Q_EMIT contactThumbnailUpdated(id, filePath); |
202 | + |
203 | + notifySecretChatsThumbnailUpdated(id, filePath); |
204 | + |
205 | break; |
206 | } |
207 | case IncomingFile::ChatThumbnail: { |
208 | @@ -635,6 +639,9 @@ |
209 | |
210 | Q_FOREACH (const User &user, users) { |
211 | |
212 | + // check previous username before update user db register |
213 | + bool changedUsername = hasChangedUsername(user); |
214 | + |
215 | if (!insertOrUpdateUser(user)) { |
216 | mDbManager.rollbackTransaction(); |
217 | qCCritical(TG_PLUGIN_LOGIC) << "Error adding new contact to local database"; |
218 | @@ -654,6 +661,13 @@ |
219 | contactItems.append(contactItem); |
220 | } |
221 | |
222 | + |
223 | + if (changedUsername) { |
224 | + QString completeName = user.firstName() + " " + user.lastName(); |
225 | + Q_EMIT dialogTitleUpdated(user.id(), completeName); |
226 | + notifySecretChatsTitleUpdated(user.id(), completeName); |
227 | + } |
228 | + |
229 | Q_EMIT userInfo(contactItem); |
230 | } |
231 | |
232 | @@ -2094,6 +2108,26 @@ |
233 | Q_EMIT chatUpdated(update.chatId()); |
234 | } |
235 | |
236 | +void Data::processUpdateUserName(const Update &update) { |
237 | + qint32 userId = update.userId(); |
238 | + QString firstName = update.firstName(); |
239 | + QString lastName = update.lastName(); |
240 | + if (updateUserName(userId, firstName, lastName)) { |
241 | + Q_EMIT contactNameUpdated(userId, firstName, lastName); |
242 | + |
243 | + QString completeName = firstName + " " + lastName; |
244 | + Q_EMIT dialogTitleUpdated(userId, completeName); |
245 | + notifySecretChatsTitleUpdated(userId, completeName); |
246 | + } |
247 | +} |
248 | + |
249 | +void Data::processUpdateUserPhoto(const Update &update) { |
250 | + qint32 userId = update.userId(); |
251 | + const FileLocation &photoToDownload = update.photo().photoSmall(); |
252 | + bool isUserPhoto = true; |
253 | + getProfilePhotoFileFromServer(photoToDownload, userId, isUserPhoto); |
254 | +} |
255 | + |
256 | bool Data::processUpdate(const Update &update, const QList<User> &users, const QList<Chat> &chats) { |
257 | // FIXME Users and Chats code blocks repeated in onUpdatesGetDifferenceAnswer. |
258 | mDbManager.beginTransaction(); |
259 | @@ -2103,6 +2137,8 @@ |
260 | qCCritical(TG_PLUGIN_LOGIC) << "Error updating user in database while processing an update"; |
261 | return false; |
262 | } |
263 | + // request user photo if it has changed |
264 | + getProfilePhotoFileFromServer(user.photo().photoSmall(), user.id(), true); |
265 | } |
266 | Q_FOREACH (const Chat &chat, chats) { |
267 | if (!insertOrUpdateChat(chat)) { |
268 | @@ -2155,6 +2191,12 @@ |
269 | Q_EMIT userTyping(update.chatId()); |
270 | break; |
271 | } |
272 | + case Update::typeUpdateUserName: |
273 | + processUpdateUserName(update); |
274 | + break; |
275 | + case Update::typeUpdateUserPhoto: |
276 | + processUpdateUserPhoto(update); |
277 | + break; |
278 | case Update::typeUpdateNewMessage: { |
279 | |
280 | Message message = update.message(); |
281 | @@ -2289,9 +2331,6 @@ |
282 | } |
283 | break; |
284 | } |
285 | - |
286 | -// case Update::typeUpdateUserTyping: { ModelsManager::instance()->dialogsModel().setIsTyping(update.userId(), update.userId()); break; } |
287 | -// case Update::typeUpdateChatUserTyping: { ModelsManager::instance()->dialogsModel().setIsTyping(update.chatId(), update.userId()); break; } |
288 | } |
289 | |
290 | // FIXME for those other updates that don't call it yet: |
291 | @@ -2314,6 +2353,20 @@ |
292 | } |
293 | } |
294 | |
295 | +void Data::notifySecretChatsThumbnailUpdated(qint32 userId, const QString &filePath) { |
296 | + QList<qint32> userSecretChats = getUserSecretChats(userId); |
297 | + Q_FOREACH (qint32 secretChatId, userSecretChats) { |
298 | + Q_EMIT dialogThumbnailUpdated(secretChatId, filePath); |
299 | + } |
300 | +} |
301 | + |
302 | +void Data::notifySecretChatsTitleUpdated(qint32 userId, const QString &title) { |
303 | + QList<qint32> userSecretChats = getUserSecretChats(userId); |
304 | + Q_FOREACH (qint32 secretChatId, userSecretChats) { |
305 | + Q_EMIT dialogTitleUpdated(secretChatId, title); |
306 | + } |
307 | +} |
308 | + |
309 | bool Data::getProfilePhotoFileFromServer(const FileLocation &photoToDownload, qint32 id, bool isUser) { |
310 | |
311 | if (photoToDownload.classType() != FileLocation::typeFileLocationUnavailable) { |
312 | @@ -2322,7 +2375,7 @@ |
313 | // received ones. In that case don't download cos it's the same file |
314 | QSqlQuery query(mDbManager.database()); |
315 | |
316 | - QString queryString("SELECT dcId, localId, secret, volumeId FROM fileLocations,%1 " |
317 | + QString queryString("SELECT localPath, dcId, localId, secret, volumeId FROM fileLocations,%1 " |
318 | "WHERE %1.thumbnail=fileLocations.rowid AND %1.id=:id"); |
319 | if (isUser) { |
320 | queryString = queryString.arg("users"); |
321 | @@ -2337,17 +2390,21 @@ |
322 | return false; |
323 | } |
324 | |
325 | + // Don't download if server location data is same as db and local path is not empty |
326 | if (query.next()) { |
327 | - qint32 dcId = query.value("dcId").toInt(); |
328 | - qint32 localId = query.value("localId").toInt(); |
329 | - qint64 secret = query.value("secret").toLongLong(); |
330 | - qint64 volumeId = query.value("volumeId").toLongLong(); |
331 | + QString localPath = query.value("localPath").toString(); |
332 | + if (!localPath.isEmpty()) { |
333 | + qint32 dcId = query.value("dcId").toInt(); |
334 | + qint32 localId = query.value("localId").toInt(); |
335 | + qint64 secret = query.value("secret").toLongLong(); |
336 | + qint64 volumeId = query.value("volumeId").toLongLong(); |
337 | |
338 | - if (dcId == photoToDownload.dcId() && |
339 | - localId == photoToDownload.localId() && |
340 | - secret == photoToDownload.secret() && |
341 | - volumeId == photoToDownload.volumeId()) { |
342 | - return false; |
343 | + if (dcId == photoToDownload.dcId() && |
344 | + localId == photoToDownload.localId() && |
345 | + secret == photoToDownload.secret() && |
346 | + volumeId == photoToDownload.volumeId()) { |
347 | + return false; |
348 | + } |
349 | } |
350 | } |
351 | |
352 | @@ -3075,7 +3132,7 @@ |
353 | |
354 | QSqlQuery query(mDbManager.database()); |
355 | |
356 | - query.prepare("SELECT dialogId, fromId, toId, toIsChat, out, sent, unread, date, text, mediaType, " |
357 | + query.prepare("SELECT dialogId, fromId, toId, toIsChat, out, sent, unread, date, ttl, text, mediaType, " |
358 | "(SELECT localPath FROM fileLocations, photoSizes WHERE fileLocations.rowid=fileLocationId AND " |
359 | "photoId=mediaId AND (type='s' OR type='m') ORDER BY size DESC LIMIT 1) AS photoSmall, " |
360 | "(SELECT localPath FROM fileLocations, photoSizes WHERE fileLocations.rowid=fileLocationId AND " |
361 | @@ -3112,6 +3169,7 @@ |
362 | bool out = query.value("out").toBool(); |
363 | bool sent = query.value("sent").toBool(); |
364 | bool unread = query.value("unread").toBool(); |
365 | + qint32 ttl = query.value("ttl").toInt(); |
366 | qint32 date = query.value("date").toInt(); |
367 | QString text = query.value("text").toString(); |
368 | qint32 mediaType = query.value("mediaType").toInt(); |
369 | @@ -3144,6 +3202,7 @@ |
370 | messageItem.setOut(out); |
371 | messageItem.setSent(sent); |
372 | messageItem.setUnread(unread); |
373 | + messageItem.setTtl(ttl); |
374 | messageItem.setDate(date); |
375 | messageItem.setMessage(text); |
376 | MessageMedia media((MessageMedia::MessageMediaType)mediaType); |
377 | @@ -3988,8 +4047,8 @@ |
378 | } |
379 | } |
380 | |
381 | - query.prepare("INSERT INTO messages (id, dialogId, randomId, fromId, toId, toIsChat, out, unread, date, text, mediaType, mediaId, sent) " |
382 | - "VALUES (:id, :dialogId, :randomId, :fromId, :toId, :toIsChat, :out, :unread, :date, :text, :mediaType, :mediaId, :sent)"); |
383 | + query.prepare("INSERT INTO messages (id, dialogId, randomId, fromId, toId, toIsChat, out, unread, date, ttl, text, mediaType, mediaId, sent) " |
384 | + "VALUES (:id, :dialogId, :randomId, :fromId, :toId, :toIsChat, :out, :unread, :date, :ttl, :text, :mediaType, :mediaId, :sent)"); |
385 | query.bindValue(":id", message.id()); |
386 | query.bindValue(":dialogId", dialogId); |
387 | query.bindValue(":randomId", randomId); |
388 | @@ -3999,6 +4058,7 @@ |
389 | query.bindValue(":out", message.out()); |
390 | query.bindValue(":unread", message.unread()); |
391 | query.bindValue(":date", message.date()); |
392 | + query.bindValue(":ttl", message.ttl()); |
393 | query.bindValue(":text", message.message()); |
394 | query.bindValue(":mediaType", mediaType); |
395 | query.bindValue(":mediaId", mediaId); |
396 | @@ -4436,6 +4496,26 @@ |
397 | return result; |
398 | } |
399 | |
400 | +QList<qint32> Data::getUserSecretChats(qint32 userId) { |
401 | + |
402 | + QList<qint32> secretChats; |
403 | + |
404 | + QSqlQuery query(mDbManager.database()); |
405 | + |
406 | + query.prepare("SELECT id FROM secretChats WHERE peerId=:userId"); |
407 | + query.bindValue(":userId", userId); |
408 | + if (!query.exec()) { |
409 | + qCCritical(TG_PLUGIN_LOGIC) << "Could not get user secret chats" << query.lastQuery() << query.lastError(); |
410 | + return secretChats; |
411 | + } |
412 | + |
413 | + while (query.next()) { |
414 | + secretChats << query.value("id").toInt(); |
415 | + } |
416 | + |
417 | + return secretChats; |
418 | +} |
419 | + |
420 | bool Data::isContact(qint32 userId) { |
421 | |
422 | QSqlQuery query(mDbManager.database()); |
423 | @@ -4448,6 +4528,7 @@ |
424 | if (!updateUser(user)) { |
425 | return insertUser(user); |
426 | } |
427 | + |
428 | return true; |
429 | } |
430 | |
431 | @@ -4502,6 +4583,23 @@ |
432 | return query.numRowsAffected() > 0; |
433 | } |
434 | |
435 | +bool Data::updateUserName(qint32 userId, const QString &firstName, const QString &lastName) { |
436 | + |
437 | + QSqlQuery query(mDbManager.database()); |
438 | + query.prepare("UPDATE users SET firstName=:firstName, lastName=:lastName WHERE id=:id"); |
439 | + query.bindValue(":firstName", firstName); |
440 | + query.bindValue(":lastName", lastName); |
441 | + query.bindValue(":id", userId); |
442 | + |
443 | + if (!query.exec()) { |
444 | + qCCritical(TG_PLUGIN_LOGIC) << "Could not update user name for userId" << userId |
445 | + << query.lastError() << query.lastQuery(); |
446 | + return false; |
447 | + } |
448 | + |
449 | + return query.numRowsAffected() > 0; |
450 | +} |
451 | + |
452 | bool Data::updateUserIsContact(qint32 userId, bool isContact, bool hasPhone) { |
453 | |
454 | qint32 type = User::typeUserContact; |
455 | @@ -4555,6 +4653,28 @@ |
456 | return true; |
457 | } |
458 | |
459 | +bool Data::hasChangedUsername(const User &user) { |
460 | + |
461 | + QSqlQuery query(mDbManager.database()); |
462 | + |
463 | + query.prepare("SELECT firstName, lastName FROM users WHERE id=:id"); |
464 | + query.bindValue(":id", user.id()); |
465 | + if (!query.exec()) { |
466 | + qCCritical(TG_PLUGIN_LOGIC) << "Could not check if name has changed for user" << user.id() |
467 | + << query.lastError() << query.lastQuery(); |
468 | + return false; |
469 | + } |
470 | + |
471 | + if (query.next()) { |
472 | + QString firstName = query.value("firstName").toString(); |
473 | + QString lastName = query.value("lastName").toString(); |
474 | + |
475 | + return user.firstName() != firstName || user.lastName() != lastName; |
476 | + } |
477 | + |
478 | + return false; |
479 | +} |
480 | + |
481 | // CHATs operations |
482 | DialogItem Data::getChat(qint32 id) { |
483 | DialogItem dialog; |
484 | |
485 | === modified file 'qmlplugin/data.h' |
486 | --- qmlplugin/data.h 2015-02-04 22:36:12 +0000 |
487 | +++ qmlplugin/data.h 2015-02-17 13:31:13 +0000 |
488 | @@ -72,10 +72,13 @@ |
489 | bool insertOrUpdateUser(const User &user); |
490 | bool insertUser(const User &user); |
491 | bool updateUser(const User &user); |
492 | + bool updateUserName(qint32 userId, const QString &firstName, const QString &lastName); |
493 | bool updateUserIsContact(qint32 userId, bool isContact, bool hasPhone); |
494 | bool deleteUsers(); |
495 | + bool hasChangedUsername(const User &user); |
496 | ContactItem getUser(qint32 id); |
497 | QList<ContactItem> getUsers(); |
498 | + QList<qint32> getUserSecretChats(qint32 userId); |
499 | |
500 | // contacts operations |
501 | bool isContact(qint32 userId); |
502 | @@ -191,6 +194,7 @@ |
503 | void chatUpdated(const qint32 chatId); |
504 | void contactThumbnailUpdated(qint32 userId, const QString &thumbnail); |
505 | void dialogThumbnailUpdated(qint32 dialogId, const QString &thumbnail); |
506 | + void contactNameUpdated(qint32 userId, const QString &firstName, const QString lastName); |
507 | void dialogTitleUpdated(qint32 dialogId, const QString &title); |
508 | void dialogMuted(qint32 dialogId, bool muted); |
509 | void dialogsMuted(NotifyPeer::NotifyPeerType notifyType, bool muted); |
510 | @@ -287,8 +291,13 @@ |
511 | // process notifications to update db and models |
512 | void updateChatParticipantsFromUpdate(const Update &update); |
513 | bool processUpdate(const Update &update, const QList<User> &users = QList<User>(), const QList<Chat> &chats = QList<Chat>()); |
514 | + void processUpdateUserName(const Update &update); |
515 | + void processUpdateUserPhoto(const Update &update); |
516 | bool needUpdateDifference(qint32 seq, UpdatesState clientState); |
517 | |
518 | + void notifySecretChatsThumbnailUpdated(qint32 userId, const QString &filePath); |
519 | + void notifySecretChatsTitleUpdated(qint32 userId, const QString &title); |
520 | + |
521 | // settings |
522 | bool muteDialog(qint32 dialogId, bool muted); |
523 | bool muteDialogs(NotifyPeer::NotifyPeerType peerType, bool muted); |
524 | |
525 | === modified file 'qmlplugin/models/messageitem.cpp' |
526 | --- qmlplugin/models/messageitem.cpp 2015-01-13 17:29:41 +0000 |
527 | +++ qmlplugin/models/messageitem.cpp 2015-02-17 13:31:13 +0000 |
528 | @@ -37,6 +37,7 @@ |
529 | setToId(*tlMessage->toId()); |
530 | setOut(tlMessage->out()); |
531 | setUnread(tlMessage->unread()); |
532 | + setTtl(messageItem.ttl()); |
533 | setDate(tlMessage->date()); |
534 | setMessage(tlMessage->message()); |
535 | setMedia(*tlMessage->media()); |
536 | @@ -76,6 +77,7 @@ |
537 | setToId(msg.toId()); |
538 | setOut(msg.out()); |
539 | setUnread(msg.unread()); |
540 | + setTtl(msg.ttl()); |
541 | setDate(msg.date()); |
542 | setMessage(msg.message()); |
543 | setMedia(msg.media()); |
544 | @@ -262,6 +264,7 @@ |
545 | qCDebug(TG_PLUGIN_LOGIC) << "OUT" << out(); |
546 | qCDebug(TG_PLUGIN_LOGIC) << "UNREAD" << unread(); |
547 | qCDebug(TG_PLUGIN_LOGIC) << "DATE" << date(); |
548 | + qCDebug(TG_PLUGIN_LOGIC) << "TTL" << ttl(); |
549 | qCDebug(TG_PLUGIN_LOGIC) << "TEXT" << text(); |
550 | qCDebug(TG_PLUGIN_LOGIC) << "MEDIA" << media()->classType(); |
551 | qCDebug(TG_PLUGIN_LOGIC) << "THUMBNAIL" << mThumbnail; |
552 | |
553 | === modified file 'qmlplugin/models/messageitem.h' |
554 | --- qmlplugin/models/messageitem.h 2014-12-12 08:18:18 +0000 |
555 | +++ qmlplugin/models/messageitem.h 2015-02-17 13:31:13 +0000 |
556 | @@ -33,6 +33,7 @@ |
557 | Q_PROPERTY(qint32 fromUserType READ fromUserType NOTIFY fromUserTypeChanged) |
558 | Q_PROPERTY(qint32 toId READ toId NOTIFY toIdChanged) |
559 | Q_PROPERTY(bool toIsChat READ toIsChat NOTIFY toIsChatChanged) |
560 | + Q_PROPERTY(qint32 ttl READ ttl NOTIFY ttlChanged) |
561 | Q_PROPERTY(QString text READ text NOTIFY textChanged) |
562 | Q_PROPERTY(qint32 mediaType READ mediaType NOTIFY mediaTypeChanged) |
563 | Q_PROPERTY(QString thumbnail READ thumbnail NOTIFY thumbnailChanged) |
564 | @@ -105,6 +106,7 @@ |
565 | void fromUserTypeChanged(qint32); |
566 | void toIdChanged(qint32); |
567 | void toIsChatChanged(bool); |
568 | + void ttlChanged(qint32); |
569 | void textChanged(QString); |
570 | void mediaTypeChanged(qint32); |
571 | void thumbnailChanged(QString); |
572 | |
573 | === modified file 'qmlplugin/models/messagesmodel.cpp' |
574 | --- qmlplugin/models/messagesmodel.cpp 2015-02-04 21:49:12 +0000 |
575 | +++ qmlplugin/models/messagesmodel.cpp 2015-02-17 13:31:13 +0000 |
576 | @@ -296,6 +296,7 @@ |
577 | roles[UnreadRole] = "unread"; |
578 | roles[SectionDateRole] = "sectionDate"; |
579 | roles[DateRole] = "date"; |
580 | + roles[TtlRole] = "ttl"; |
581 | roles[TextRole] = "text"; |
582 | roles[MediaTypeRole] = "mediaType"; |
583 | roles[PhotoRole] = "photo"; |
584 | @@ -375,6 +376,9 @@ |
585 | case DateRole: |
586 | return message.date(); |
587 | break; |
588 | + case TtlRole: |
589 | + return message.ttl(); |
590 | + break; |
591 | case TextRole: |
592 | result = message.text(); |
593 | break; |
594 | |
595 | === modified file 'qmlplugin/models/messagesmodel.h' |
596 | --- qmlplugin/models/messagesmodel.h 2015-02-04 09:37:32 +0000 |
597 | +++ qmlplugin/models/messagesmodel.h 2015-02-17 13:31:13 +0000 |
598 | @@ -47,6 +47,7 @@ |
599 | SentRole, |
600 | SectionDateRole, |
601 | DateRole, |
602 | + TtlRole, |
603 | TextRole, |
604 | MediaTypeRole, |
605 | PhotoRole, |
606 | |
607 | === modified file 'qmlplugin/models/messagesview.cpp' |
608 | --- qmlplugin/models/messagesview.cpp 2015-01-07 11:02:41 +0000 |
609 | +++ qmlplugin/models/messagesview.cpp 2015-02-17 13:31:13 +0000 |
610 | @@ -39,6 +39,7 @@ |
611 | " out,\n" |
612 | " sent,\n" |
613 | " unread,\n" |
614 | + " ttl,\n" |
615 | " date,\n" |
616 | " text,\n" |
617 | " mediaType,\n" |
618 | @@ -79,7 +80,7 @@ |
619 | |
620 | QList<MessageItem> messages; |
621 | |
622 | - mQuery.prepare(QString("SELECT id, fromId, toId, toIsChat, out, unread, sent, date, text, mediaType, fromFirstName, " |
623 | + mQuery.prepare(QString("SELECT id, fromId, toId, toIsChat, out, unread, sent, date, ttl, text, mediaType, fromFirstName, " |
624 | "fromLastName, fromPhone, fromThumbnail, fromUserType, photoSmall, photoBigLocal, photoBigRemote, " |
625 | "video, actionType, actionTitle, actionUser " |
626 | "FROM messagesView_%1 LIMIT %2 OFFSET %3") |
627 | @@ -105,6 +106,7 @@ |
628 | bool unread = mQuery.value("unread").toBool(); |
629 | bool sent = mQuery.value("sent").toBool(); |
630 | qint32 date = mQuery.value("date").toInt(); |
631 | + qint32 ttl = mQuery.value("ttl").toInt(); |
632 | QString text = mQuery.value("text").toString(); |
633 | qint32 mediaType = mQuery.value("mediaType").toInt(); |
634 | QString photoSmall = mQuery.value("photoSmall").toString(); |
635 | @@ -132,6 +134,7 @@ |
636 | message.setUnread(unread); |
637 | message.setSent(sent); |
638 | message.setDate(date); |
639 | + message.setTtl(ttl); |
640 | message.setMessage(text); |
641 | MessageMedia media((MessageMedia::MessageMediaType)mediaType); |
642 | message.setMedia(media); |
643 | |
644 | === modified file 'qmlplugin/telegramservice.cpp' |
645 | --- qmlplugin/telegramservice.cpp 2015-02-06 10:19:34 +0000 |
646 | +++ qmlplugin/telegramservice.cpp 2015-02-17 13:31:13 +0000 |
647 | @@ -152,6 +152,7 @@ |
648 | void TelegramService::onWoken() { |
649 | mTelegramLib->updatesGetState(); |
650 | mSelfDestructTimer.start(); |
651 | + updateUserProfiles(); |
652 | Q_EMIT woken(); |
653 | } |
654 | |
655 | @@ -191,6 +192,10 @@ |
656 | SIGNAL(openChat())); |
657 | |
658 | connect(mTelegramLib, |
659 | + SIGNAL(usersGetUsersAnswer(qint64,QList<User>)), |
660 | + &mData, |
661 | + SLOT(onUsersGetUsersAnswer(qint64,QList<User>))); |
662 | + connect(mTelegramLib, |
663 | SIGNAL(messagesGetDialogsAnswer(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>)), |
664 | &mData, |
665 | SLOT(onMessagesGetDialogsAnswer(qint64,qint32,QList<Dialog>,QList<Message>,QList<Chat>,QList<User>))); |
666 | @@ -338,6 +343,7 @@ |
667 | SLOT(onUpdateSecretChatMessage(SecretChatMessage,qint32))); |
668 | |
669 | mTelegramLib->updatesGetState(); |
670 | + updateUserProfiles(); |
671 | } |
672 | |
673 | void TelegramService::onAuthLoggedOut() { |
674 | @@ -622,6 +628,16 @@ |
675 | return mTelegramLib->accountUpdateNotifySettings(inputNotifyPeer, settings); |
676 | } |
677 | |
678 | +void TelegramService::updateUserProfiles() { |
679 | + // Get all the users info to update db when started up |
680 | + QList<ContactItem> contacts = mData.getUsers(); |
681 | + QList<InputUser> inputUsers; |
682 | + Q_FOREACH (const ContactItem &contact, contacts) { |
683 | + inputUsers << Tools::toInputUser(contact); |
684 | + } |
685 | + mTelegramLib->usersGetUsers(inputUsers); |
686 | +} |
687 | + |
688 | qint64 TelegramService::createSecretChat(qint32 userId) { |
689 | ContactItem user = mData.getUser(userId); |
690 | InputUser inputUser = Tools::toInputUser(user); |
691 | |
692 | === modified file 'qmlplugin/telegramservice.h' |
693 | --- qmlplugin/telegramservice.h 2015-02-03 19:23:45 +0000 |
694 | +++ qmlplugin/telegramservice.h 2015-02-17 13:31:13 +0000 |
695 | @@ -156,6 +156,7 @@ |
696 | |
697 | QString copyToDownloadsPath(const QString &file); |
698 | qint64 updateMuteUntilSetting(qint32 peerId, qint32 muteUntil); |
699 | + void updateUserProfiles(); |
700 | |
701 | private Q_SLOTS: |
702 | void onMessagesAddChatUserAnswer(qint64 id, const Message &message, const QList<Chat> &chats, const QList<User> &users, const QList<ContactsLink> &links, qint32 pts, qint32 seq); |
703 | |
704 | === modified file 'qmlplugin/types/tlmessage.h' |
705 | --- qmlplugin/types/tlmessage.h 2014-08-18 18:49:11 +0000 |
706 | +++ qmlplugin/types/tlmessage.h 2015-02-17 13:31:13 +0000 |
707 | @@ -68,6 +68,7 @@ |
708 | setFromId(s->fromId()); |
709 | setOut(s->out()); |
710 | setDate(s->date()); |
711 | + setTtl(s->ttl()); |
712 | setMedia(s->media()); |
713 | setFwdDate(s->fwdDate()); |
714 | setFwdFromId(s->fwdFromId()); |
Are you trying to land this to trunk ??!!