Merge lp:~phablet-team/history-service/wait_for_self_not_pending into lp:history-service/staging

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Tiago Salem Herrmann
Approved revision: 240
Merged at revision: 257
Proposed branch: lp:~phablet-team/history-service/wait_for_self_not_pending
Merge into: lp:history-service/staging
Prerequisite: lp:~phablet-team/history-service/improve_participant_changes_notification
Diff against target: 230 lines (+79/-19)
5 files modified
daemon/historydaemon.cpp (+45/-15)
daemon/historydaemon.h (+6/-1)
plugins/sqlite/sqlitehistoryplugin.cpp (+20/-3)
plugins/sqlite/sqlitehistoryplugin.h (+4/-0)
src/plugin.h (+4/-0)
To merge this branch: bzr merge lp:~phablet-team/history-service/wait_for_self_not_pending
Reviewer Review Type Date Requested Status
Tiago Salem Herrmann (community) Approve
Review via email: mp+316149@code.launchpad.net

This proposal supersedes a proposal from 2017-01-30.

Commit message

Only start saving information events about contacts joining and leaving after the self contact is in the local list of participants.

Description of the change

Only start saving information events about contacts joining and leaving after the self contact is in the local list of participants.

To post a comment you must log in.
239. By Tiago Salem Herrmann

merge parent branch

240. By Tiago Salem Herrmann

merge parent branch

Revision history for this message
Tiago Salem Herrmann (tiagosh) wrote :

looks good. thanks.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'daemon/historydaemon.cpp'
--- daemon/historydaemon.cpp 2017-02-21 15:18:24 +0000
+++ daemon/historydaemon.cpp 2017-02-21 15:18:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013-2016 Canonical, Ltd.2 * Copyright (C) 2013-2017 Canonical, Ltd.
3 *3 *
4 * Authors:4 * Authors:
5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
@@ -315,6 +315,31 @@
315 return thread;315 return thread;
316}316}
317317
318QString HistoryDaemon::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags, bool create)
319{
320 if (!mBackend) {
321 return QString::null;
322 }
323
324 QString threadId = mBackend->threadIdForProperties(accountId,
325 type,
326 properties,
327 matchFlags);
328 if (threadId.isEmpty() && create) {
329 QVariantMap thread = mBackend->createThreadForProperties(accountId, type, properties);
330 if (!thread.isEmpty()) {
331 if (properties.contains("Requested") && properties[History::FieldChatType].toInt() == History::ChatTypeRoom) {
332 QVariantMap map = thread[History::FieldChatRoomInfo].toMap();
333 map["Requested"] = properties["Requested"];
334 thread[History::FieldChatRoomInfo] = map;
335 }
336 mDBus.notifyThreadsAdded(QList<QVariantMap>() << thread);
337 threadId = thread[History::FieldThreadId].toString();
338 }
339 }
340 return threadId;
341}
342
318QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties)343QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties)
319{344{
320 if (!mBackend) {345 if (!mBackend) {
@@ -408,7 +433,9 @@
408 threads[hash] = thread;433 threads[hash] = thread;
409434
410 // set the participants field in the event435 // set the participants field in the event
411 savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];436 if (type == History::EventTypeVoice) {
437 savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];
438 }
412439
413440
414 // check if the event was a new one or a modification to an existing one441 // check if the event was a new one or a modification to an existing one
@@ -709,6 +736,8 @@
709 bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0;736 bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0;
710 bool hasMembersAdded = groupMembersAdded.size() > 0;737 bool hasMembersAdded = groupMembersAdded.size() > 0;
711 bool hasMembersRemoved = groupMembersRemoved.size() > 0;738 bool hasMembersRemoved = groupMembersRemoved.size() > 0;
739 Tp::ContactPtr selfContact = channel->connection()->selfContact();
740 bool selfContactIsPending = channel->groupRemotePendingContacts(true).contains(selfContact);
712741
713 if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) {742 if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) {
714 properties = propertiesFromChannel(channel);743 properties = propertiesFromChannel(channel);
@@ -717,7 +746,7 @@
717 properties,746 properties,
718 matchFlagsForChannel(channel),747 matchFlagsForChannel(channel),
719 false);748 false);
720 if (!thread.isEmpty()) {749 if (!thread.isEmpty() && !selfContactIsPending) {
721 QList<QVariantMap> added;750 QList<QVariantMap> added;
722 QList<QVariantMap> removed;751 QList<QVariantMap> removed;
723 QList<QVariantMap> modified;752 QList<QVariantMap> modified;
@@ -785,7 +814,7 @@
785 }814 }
786 }815 }
787816
788 updateRoomParticipants(channel, true);817 updateRoomParticipants(channel, !selfContactIsPending);
789}818}
790819
791void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify)820void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify)
@@ -988,19 +1017,20 @@
988 return;1017 return;
989 }1018 }
9901019
991 QVariantMap thread = threadForProperties(textChannel->property(History::FieldAccountId).toString(),1020 QString accountId = textChannel->property(History::FieldAccountId).toString();
992 History::EventTypeText,1021 QString threadId = threadIdForProperties(accountId,
993 properties,1022 History::EventTypeText,
994 matchFlagsForChannel(textChannel),1023 properties,
995 true);1024 matchFlagsForChannel(textChannel),
1025 true);
996 int count = 1;1026 int count = 1;
997 QList<QVariantMap> attachments;1027 QList<QVariantMap> attachments;
998 History::MessageType type = History::MessageTypeText;1028 History::MessageType type = History::MessageTypeText;
999 QString subject;1029 QString subject;
10001030
1001 if (message.hasNonTextContent()) {1031 if (message.hasNonTextContent()) {
1002 QString normalizedAccountId = QString(QCryptographicHash::hash(thread[History::FieldAccountId].toString().toLatin1(), QCryptographicHash::Md5).toHex());1032 QString normalizedAccountId = QString(QCryptographicHash::hash(accountId.toLatin1(), QCryptographicHash::Md5).toHex());
1003 QString normalizedThreadId = QString(QCryptographicHash::hash(thread[History::FieldThreadId].toString().toLatin1(), QCryptographicHash::Md5).toHex());1033 QString normalizedThreadId = QString(QCryptographicHash::hash(threadId.toLatin1(), QCryptographicHash::Md5).toHex());
1004 QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex());1034 QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex());
1005 QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);1035 QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
10061036
@@ -1033,8 +1063,8 @@
1033 file.close();1063 file.close();
10341064
1035 QVariantMap attachment;1065 QVariantMap attachment;
1036 attachment[History::FieldAccountId] = thread[History::FieldAccountId];1066 attachment[History::FieldAccountId] = accountId;
1037 attachment[History::FieldThreadId] = thread[History::FieldThreadId];1067 attachment[History::FieldThreadId] = threadId;
1038 attachment[History::FieldEventId] = eventId;1068 attachment[History::FieldEventId] = eventId;
1039 attachment[History::FieldAttachmentId] = part["identifier"].variant();1069 attachment[History::FieldAttachmentId] = part["identifier"].variant();
1040 attachment[History::FieldContentType] = part["content-type"].variant();1070 attachment[History::FieldContentType] = part["content-type"].variant();
@@ -1046,8 +1076,8 @@
10461076
1047 QVariantMap event;1077 QVariantMap event;
1048 event[History::FieldType] = History::EventTypeText;1078 event[History::FieldType] = History::EventTypeText;
1049 event[History::FieldAccountId] = thread[History::FieldAccountId];1079 event[History::FieldAccountId] = accountId;
1050 event[History::FieldThreadId] = thread[History::FieldThreadId];1080 event[History::FieldThreadId] = threadId;
1051 event[History::FieldEventId] = eventId;1081 event[History::FieldEventId] = eventId;
1052 event[History::FieldSenderId] = senderId;1082 event[History::FieldSenderId] = senderId;
1053 event[History::FieldTimestamp] = message.received().toString("yyyy-MM-ddTHH:mm:ss.zzz");1083 event[History::FieldTimestamp] = message.received().toString("yyyy-MM-ddTHH:mm:ss.zzz");
10541084
=== modified file 'daemon/historydaemon.h'
--- daemon/historydaemon.h 2017-02-21 15:18:24 +0000
+++ daemon/historydaemon.h 2017-02-21 15:18:24 +0000
@@ -1,5 +1,5 @@
1/*1/*
2 * Copyright (C) 2013-2016 Canonical, Ltd.2 * Copyright (C) 2013-2017 Canonical, Ltd.
3 *3 *
4 * Authors:4 * Authors:
5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>5 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
@@ -48,6 +48,11 @@
48 const QVariantMap &properties,48 const QVariantMap &properties,
49 History::MatchFlags matchFlags = History::MatchCaseSensitive,49 History::MatchFlags matchFlags = History::MatchCaseSensitive,
50 bool create = true);50 bool create = true);
51 QString threadIdForProperties(const QString &accountId,
52 History::EventType type,
53 const QVariantMap &properties,
54 History::MatchFlags matchFlags = History::MatchCaseSensitive,
55 bool create = true);
51 QString queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties);56 QString queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties);
52 QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter);57 QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter);
53 QVariantMap getSingleThread(int type, const QString &accountId, const QString &threadId, const QVariantMap &properties);58 QVariantMap getSingleThread(int type, const QString &accountId, const QString &threadId, const QVariantMap &properties);
5459
=== modified file 'plugins/sqlite/sqlitehistoryplugin.cpp'
--- plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:18:24 +0000
+++ plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:18:24 +0000
@@ -315,8 +315,6 @@
315 return QVariantMap();315 return QVariantMap();
316 }316 }
317317
318 QSqlQuery query(SQLiteDatabase::instance()->database());
319
320 History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();318 History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
321319
322 if (chatType == History::ChatTypeRoom) {320 if (chatType == History::ChatTypeRoom) {
@@ -332,6 +330,24 @@
332 return threadForParticipants(accountId, type, participants.identifiers(), matchFlags);330 return threadForParticipants(accountId, type, participants.identifiers(), matchFlags);
333}331}
334332
333QString SQLiteHistoryPlugin::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags)
334{
335 if (properties.isEmpty()) {
336 return QString::null;
337 }
338
339 // if chat type is room, just get the threadId directly
340 History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
341 if (chatType == History::ChatTypeRoom) {
342 QString threadId = properties[History::FieldThreadId].toString();
343 return threadId;
344 }
345
346 // if chat type is anything else, fallback to returning the threadId from the participants list
347 History::Participants participants = History::Participants::fromVariant(properties[History::FieldParticipantIds]);
348 return threadForParticipants(accountId, type, participants.identifiers(), matchFlags)[History::FieldThreadId].toString();
349}
350
335QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId,351QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId,
336 History::EventType type,352 History::EventType type,
337 const QStringList &participants,353 const QStringList &participants,
@@ -1320,7 +1336,8 @@
1320 QString queryText;1336 QString queryText;
1321 switch (type) {1337 switch (type) {
1322 case History::EventTypeText:1338 case History::EventTypeText:
1323 participantsField = participantsField.arg("text_events", QString::number(type));1339 // for text events we don't need the participants at all
1340 participantsField = "\"\" as participants";
1324 queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, "1341 queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, "
1325 "message, messageType, messageStatus, readTimestamp, subject, informationType FROM text_events %2 %3").arg(participantsField, modifiedCondition, order);1342 "message, messageType, messageStatus, readTimestamp, subject, informationType FROM text_events %2 %3").arg(participantsField, modifiedCondition, order);
1326 break;1343 break;
13271344
=== modified file 'plugins/sqlite/sqlitehistoryplugin.h'
--- plugins/sqlite/sqlitehistoryplugin.h 2016-09-21 17:44:39 +0000
+++ plugins/sqlite/sqlitehistoryplugin.h 2017-02-21 15:18:24 +0000
@@ -59,6 +59,10 @@
59 History::EventType type,59 History::EventType type,
60 const QVariantMap &properties,60 const QVariantMap &properties,
61 History::MatchFlags matchFlags = History::MatchCaseSensitive);61 History::MatchFlags matchFlags = History::MatchCaseSensitive);
62 virtual QString threadIdForProperties(const QString &accountId,
63 History::EventType type,
64 const QVariantMap &properties,
65 History::MatchFlags matchFlags = History::MatchCaseSensitive) override;
6266
63 QList<QVariantMap> eventsForThread(const QVariantMap &thread);67 QList<QVariantMap> eventsForThread(const QVariantMap &thread);
6468
6569
=== modified file 'src/plugin.h'
--- src/plugin.h 2016-09-21 17:44:39 +0000
+++ src/plugin.h 2017-02-21 15:18:24 +0000
@@ -65,6 +65,10 @@
65 EventType type,65 EventType type,
66 const QVariantMap &properties,66 const QVariantMap &properties,
67 History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;67 History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
68 virtual QString threadIdForProperties(const QString &accountId,
69 EventType type,
70 const QVariantMap &properties,
71 History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
6872
69 virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0;73 virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0;
7074

Subscribers

People subscribed via source and target branches

to all changes: