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
1=== modified file 'daemon/historydaemon.cpp'
2--- daemon/historydaemon.cpp 2017-02-21 15:18:24 +0000
3+++ daemon/historydaemon.cpp 2017-02-21 15:18:24 +0000
4@@ -1,5 +1,5 @@
5 /*
6- * Copyright (C) 2013-2016 Canonical, Ltd.
7+ * Copyright (C) 2013-2017 Canonical, Ltd.
8 *
9 * Authors:
10 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
11@@ -315,6 +315,31 @@
12 return thread;
13 }
14
15+QString HistoryDaemon::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags, bool create)
16+{
17+ if (!mBackend) {
18+ return QString::null;
19+ }
20+
21+ QString threadId = mBackend->threadIdForProperties(accountId,
22+ type,
23+ properties,
24+ matchFlags);
25+ if (threadId.isEmpty() && create) {
26+ QVariantMap thread = mBackend->createThreadForProperties(accountId, type, properties);
27+ if (!thread.isEmpty()) {
28+ if (properties.contains("Requested") && properties[History::FieldChatType].toInt() == History::ChatTypeRoom) {
29+ QVariantMap map = thread[History::FieldChatRoomInfo].toMap();
30+ map["Requested"] = properties["Requested"];
31+ thread[History::FieldChatRoomInfo] = map;
32+ }
33+ mDBus.notifyThreadsAdded(QList<QVariantMap>() << thread);
34+ threadId = thread[History::FieldThreadId].toString();
35+ }
36+ }
37+ return threadId;
38+}
39+
40 QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties)
41 {
42 if (!mBackend) {
43@@ -408,7 +433,9 @@
44 threads[hash] = thread;
45
46 // set the participants field in the event
47- savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];
48+ if (type == History::EventTypeVoice) {
49+ savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];
50+ }
51
52
53 // check if the event was a new one or a modification to an existing one
54@@ -709,6 +736,8 @@
55 bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0;
56 bool hasMembersAdded = groupMembersAdded.size() > 0;
57 bool hasMembersRemoved = groupMembersRemoved.size() > 0;
58+ Tp::ContactPtr selfContact = channel->connection()->selfContact();
59+ bool selfContactIsPending = channel->groupRemotePendingContacts(true).contains(selfContact);
60
61 if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) {
62 properties = propertiesFromChannel(channel);
63@@ -717,7 +746,7 @@
64 properties,
65 matchFlagsForChannel(channel),
66 false);
67- if (!thread.isEmpty()) {
68+ if (!thread.isEmpty() && !selfContactIsPending) {
69 QList<QVariantMap> added;
70 QList<QVariantMap> removed;
71 QList<QVariantMap> modified;
72@@ -785,7 +814,7 @@
73 }
74 }
75
76- updateRoomParticipants(channel, true);
77+ updateRoomParticipants(channel, !selfContactIsPending);
78 }
79
80 void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify)
81@@ -988,19 +1017,20 @@
82 return;
83 }
84
85- QVariantMap thread = threadForProperties(textChannel->property(History::FieldAccountId).toString(),
86- History::EventTypeText,
87- properties,
88- matchFlagsForChannel(textChannel),
89- true);
90+ QString accountId = textChannel->property(History::FieldAccountId).toString();
91+ QString threadId = threadIdForProperties(accountId,
92+ History::EventTypeText,
93+ properties,
94+ matchFlagsForChannel(textChannel),
95+ true);
96 int count = 1;
97 QList<QVariantMap> attachments;
98 History::MessageType type = History::MessageTypeText;
99 QString subject;
100
101 if (message.hasNonTextContent()) {
102- QString normalizedAccountId = QString(QCryptographicHash::hash(thread[History::FieldAccountId].toString().toLatin1(), QCryptographicHash::Md5).toHex());
103- QString normalizedThreadId = QString(QCryptographicHash::hash(thread[History::FieldThreadId].toString().toLatin1(), QCryptographicHash::Md5).toHex());
104+ QString normalizedAccountId = QString(QCryptographicHash::hash(accountId.toLatin1(), QCryptographicHash::Md5).toHex());
105+ QString normalizedThreadId = QString(QCryptographicHash::hash(threadId.toLatin1(), QCryptographicHash::Md5).toHex());
106 QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex());
107 QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
108
109@@ -1033,8 +1063,8 @@
110 file.close();
111
112 QVariantMap attachment;
113- attachment[History::FieldAccountId] = thread[History::FieldAccountId];
114- attachment[History::FieldThreadId] = thread[History::FieldThreadId];
115+ attachment[History::FieldAccountId] = accountId;
116+ attachment[History::FieldThreadId] = threadId;
117 attachment[History::FieldEventId] = eventId;
118 attachment[History::FieldAttachmentId] = part["identifier"].variant();
119 attachment[History::FieldContentType] = part["content-type"].variant();
120@@ -1046,8 +1076,8 @@
121
122 QVariantMap event;
123 event[History::FieldType] = History::EventTypeText;
124- event[History::FieldAccountId] = thread[History::FieldAccountId];
125- event[History::FieldThreadId] = thread[History::FieldThreadId];
126+ event[History::FieldAccountId] = accountId;
127+ event[History::FieldThreadId] = threadId;
128 event[History::FieldEventId] = eventId;
129 event[History::FieldSenderId] = senderId;
130 event[History::FieldTimestamp] = message.received().toString("yyyy-MM-ddTHH:mm:ss.zzz");
131
132=== modified file 'daemon/historydaemon.h'
133--- daemon/historydaemon.h 2017-02-21 15:18:24 +0000
134+++ daemon/historydaemon.h 2017-02-21 15:18:24 +0000
135@@ -1,5 +1,5 @@
136 /*
137- * Copyright (C) 2013-2016 Canonical, Ltd.
138+ * Copyright (C) 2013-2017 Canonical, Ltd.
139 *
140 * Authors:
141 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
142@@ -48,6 +48,11 @@
143 const QVariantMap &properties,
144 History::MatchFlags matchFlags = History::MatchCaseSensitive,
145 bool create = true);
146+ QString threadIdForProperties(const QString &accountId,
147+ History::EventType type,
148+ const QVariantMap &properties,
149+ History::MatchFlags matchFlags = History::MatchCaseSensitive,
150+ bool create = true);
151 QString queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties);
152 QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter);
153 QVariantMap getSingleThread(int type, const QString &accountId, const QString &threadId, const QVariantMap &properties);
154
155=== modified file 'plugins/sqlite/sqlitehistoryplugin.cpp'
156--- plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:18:24 +0000
157+++ plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:18:24 +0000
158@@ -315,8 +315,6 @@
159 return QVariantMap();
160 }
161
162- QSqlQuery query(SQLiteDatabase::instance()->database());
163-
164 History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
165
166 if (chatType == History::ChatTypeRoom) {
167@@ -332,6 +330,24 @@
168 return threadForParticipants(accountId, type, participants.identifiers(), matchFlags);
169 }
170
171+QString SQLiteHistoryPlugin::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags)
172+{
173+ if (properties.isEmpty()) {
174+ return QString::null;
175+ }
176+
177+ // if chat type is room, just get the threadId directly
178+ History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
179+ if (chatType == History::ChatTypeRoom) {
180+ QString threadId = properties[History::FieldThreadId].toString();
181+ return threadId;
182+ }
183+
184+ // if chat type is anything else, fallback to returning the threadId from the participants list
185+ History::Participants participants = History::Participants::fromVariant(properties[History::FieldParticipantIds]);
186+ return threadForParticipants(accountId, type, participants.identifiers(), matchFlags)[History::FieldThreadId].toString();
187+}
188+
189 QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId,
190 History::EventType type,
191 const QStringList &participants,
192@@ -1320,7 +1336,8 @@
193 QString queryText;
194 switch (type) {
195 case History::EventTypeText:
196- participantsField = participantsField.arg("text_events", QString::number(type));
197+ // for text events we don't need the participants at all
198+ participantsField = "\"\" as participants";
199 queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, "
200 "message, messageType, messageStatus, readTimestamp, subject, informationType FROM text_events %2 %3").arg(participantsField, modifiedCondition, order);
201 break;
202
203=== modified file 'plugins/sqlite/sqlitehistoryplugin.h'
204--- plugins/sqlite/sqlitehistoryplugin.h 2016-09-21 17:44:39 +0000
205+++ plugins/sqlite/sqlitehistoryplugin.h 2017-02-21 15:18:24 +0000
206@@ -59,6 +59,10 @@
207 History::EventType type,
208 const QVariantMap &properties,
209 History::MatchFlags matchFlags = History::MatchCaseSensitive);
210+ virtual QString threadIdForProperties(const QString &accountId,
211+ History::EventType type,
212+ const QVariantMap &properties,
213+ History::MatchFlags matchFlags = History::MatchCaseSensitive) override;
214
215 QList<QVariantMap> eventsForThread(const QVariantMap &thread);
216
217
218=== modified file 'src/plugin.h'
219--- src/plugin.h 2016-09-21 17:44:39 +0000
220+++ src/plugin.h 2017-02-21 15:18:24 +0000
221@@ -65,6 +65,10 @@
222 EventType type,
223 const QVariantMap &properties,
224 History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
225+ virtual QString threadIdForProperties(const QString &accountId,
226+ EventType type,
227+ const QVariantMap &properties,
228+ History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
229
230 virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0;
231

Subscribers

People subscribed via source and target branches

to all changes: