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

Proposed by Gustavo Pichorim Boiko
Status: Superseded
Proposed branch: lp:~phablet-team/history-service/wait_for_self_not_pending
Merge into: lp:history-service/staging
Diff against target: 903 lines (+294/-55)
23 files modified
Ubuntu/History/historythreadmodel.cpp (+18/-0)
Ubuntu/History/historythreadmodel.h (+1/-0)
daemon/HistoryService.xml (+13/-0)
daemon/historydaemon.cpp (+107/-43)
daemon/historydaemon.h (+12/-7)
daemon/historyservicedbus.cpp (+8/-0)
daemon/historyservicedbus.h (+8/-0)
plugins/sqlite/sqlitehistoryplugin.cpp (+27/-5)
plugins/sqlite/sqlitehistoryplugin.h (+4/-0)
src/manager.cpp (+3/-0)
src/manager.h (+1/-0)
src/managerdbus.cpp (+17/-0)
src/managerdbus_p.h (+8/-0)
src/participant.cpp (+9/-0)
src/participant.h (+1/-0)
src/plugin.h (+4/-0)
src/thread.cpp (+16/-0)
src/thread.h (+2/-0)
src/threadview.cpp (+15/-0)
src/threadview.h (+8/-0)
src/threadview_p.h (+4/-0)
src/utils.cpp (+7/-0)
src/utils_p.h (+1/-0)
To merge this branch: bzr merge lp:~phablet-team/history-service/wait_for_self_not_pending
Reviewer Review Type Date Requested Status
Ubuntu Phablet Team Pending
Review via email: mp+315896@code.launchpad.net

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

This proposal has been superseded by a proposal from 2017-02-01.

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.
237. By Gustavo Pichorim Boiko

Fix method return value.

238. By Tiago Salem Herrmann

merge parent

239. By Tiago Salem Herrmann

merge parent branch

240. By Tiago Salem Herrmann

merge parent branch

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Ubuntu/History/historythreadmodel.cpp'
2--- Ubuntu/History/historythreadmodel.cpp 2016-06-17 01:49:46 +0000
3+++ Ubuntu/History/historythreadmodel.cpp 2017-02-01 17:42:07 +0000
4@@ -294,6 +294,10 @@
5 SIGNAL(threadsRemoved(History::Threads)),
6 SLOT(onThreadsRemoved(History::Threads)));
7 connect(mThreadView.data(),
8+ SIGNAL(threadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)),
9+ SLOT(onThreadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)));
10+
11+ connect(mThreadView.data(),
12 SIGNAL(invalidated()),
13 SLOT(triggerQueryUpdate()));
14
15@@ -311,6 +315,20 @@
16 fetchMore(QModelIndex());
17 }
18
19+
20+void HistoryThreadModel::onThreadParticipantsChanged(const History::Thread &thread, const History::Participants &added, const History::Participants &removed, const History::Participants &modified)
21+{
22+ int pos = mThreads.indexOf(thread);
23+ if (pos >= 0) {
24+ mThreads[pos].removeParticipants(removed);
25+ mThreads[pos].removeParticipants(modified);
26+ mThreads[pos].addParticipants(added);
27+ mThreads[pos].addParticipants(modified);
28+ QModelIndex idx = index(pos);
29+ Q_EMIT dataChanged(idx, idx);
30+ }
31+}
32+
33 void HistoryThreadModel::onThreadsAdded(const History::Threads &threads)
34 {
35 if (threads.isEmpty()) {
36
37=== modified file 'Ubuntu/History/historythreadmodel.h'
38--- Ubuntu/History/historythreadmodel.h 2016-06-17 01:49:46 +0000
39+++ Ubuntu/History/historythreadmodel.h 2017-02-01 17:42:07 +0000
40@@ -76,6 +76,7 @@
41 virtual void onThreadsAdded(const History::Threads &threads);
42 virtual void onThreadsModified(const History::Threads &threads);
43 virtual void onThreadsRemoved(const History::Threads &threads);
44+ virtual void onThreadParticipantsChanged(const History::Thread &thread, const History::Participants &added, const History::Participants &removed, const History::Participants &modified);
45
46 protected:
47 History::Threads fetchNextPage();
48
49=== modified file 'daemon/HistoryService.xml'
50--- daemon/HistoryService.xml 2016-04-15 22:23:21 +0000
51+++ daemon/HistoryService.xml 2017-02-01 17:42:07 +0000
52@@ -159,5 +159,18 @@
53 <arg name="events" type="a(a{sv})"/>
54 <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList &lt; QVariantMap &gt;"/>
55 </signal>
56+ <signal name="ThreadParticipantsChanged">
57+ <dox:d><![CDATA[
58+ Participants changed in a certain thread changed.
59+ ]]></dox:d>
60+ <arg name="thread" type="a{sv}"/>
61+ <arg name="added" type="a(a{sv})"/>
62+ <arg name="removed" type="a(a{sv})"/>
63+ <arg name="modified" type="a(a{sv})"/>
64+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QVariantMap"/>
65+ <annotation name="org.qtproject.QtDBus.QtTypeName.In1" value="QList &lt; QVariantMap &gt;"/>
66+ <annotation name="org.qtproject.QtDBus.QtTypeName.In2" value="QList &lt; QVariantMap &gt;"/>
67+ <annotation name="org.qtproject.QtDBus.QtTypeName.In3" value="QList &lt; QVariantMap &gt;"/>
68+ </signal>
69 </interface>
70 </node>
71
72=== modified file 'daemon/historydaemon.cpp'
73--- daemon/historydaemon.cpp 2016-11-24 02:02:32 +0000
74+++ daemon/historydaemon.cpp 2017-02-01 17:42:07 +0000
75@@ -1,5 +1,5 @@
76 /*
77- * Copyright (C) 2013-2016 Canonical, Ltd.
78+ * Copyright (C) 2013-2017 Canonical, Ltd.
79 *
80 * Authors:
81 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
82@@ -187,6 +187,7 @@
83 QVariantMap properties;
84 QVariantList participants;
85 QStringList participantIds;
86+ QString accountId = textChannel->property(History::FieldAccountId).toString();
87
88 ChannelInterfaceRolesInterface *roles_interface = textChannel->optionalInterface<ChannelInterfaceRolesInterface>();
89 RolesMap roles;
90@@ -197,7 +198,7 @@
91 Q_FOREACH(const Tp::ContactPtr contact, textChannel->groupContacts(false)) {
92 QVariantMap contactProperties;
93 contactProperties[History::FieldAlias] = contact->alias();
94- contactProperties[History::FieldAccountId] = textChannel->property(History::FieldAccountId).toString();
95+ contactProperties[History::FieldAccountId] = accountId;
96 contactProperties[History::FieldIdentifier] = contact->id();
97 contactProperties[History::FieldParticipantState] = History::ParticipantStateRegular;
98 contactProperties[History::FieldParticipantRoles] = roles[contact->handle().at(0)];
99@@ -208,7 +209,7 @@
100 Q_FOREACH(const Tp::ContactPtr contact, textChannel->groupRemotePendingContacts(false)) {
101 QVariantMap contactProperties;
102 contactProperties[History::FieldAlias] = contact->alias();
103- contactProperties[History::FieldAccountId] = textChannel->property(History::FieldAccountId).toString();
104+ contactProperties[History::FieldAccountId] = accountId;
105 contactProperties[History::FieldIdentifier] = contact->id();
106 contactProperties[History::FieldParticipantState] = History::ParticipantStateRemotePending;
107 contactProperties[History::FieldParticipantRoles] = roles[contact->handle().at(0)];
108@@ -219,7 +220,7 @@
109 Q_FOREACH(const Tp::ContactPtr contact, textChannel->groupLocalPendingContacts(false)) {
110 QVariantMap contactProperties;
111 contactProperties[History::FieldAlias] = contact->alias();
112- contactProperties[History::FieldAccountId] = textChannel->property(History::FieldAccountId).toString();
113+ contactProperties[History::FieldAccountId] = accountId;
114 contactProperties[History::FieldIdentifier] = contact->id();
115 contactProperties[History::FieldParticipantState] = History::ParticipantStateLocalPending;
116 contactProperties[History::FieldParticipantRoles] = roles[contact->handle().at(0)];
117@@ -231,7 +232,7 @@
118 textChannel->targetContact() == textChannel->connection()->selfContact()) {
119 QVariantMap contactProperties;
120 contactProperties[History::FieldAlias] = textChannel->targetContact()->alias();
121- contactProperties[History::FieldAccountId] = textChannel->property(History::FieldAccountId).toString();
122+ contactProperties[History::FieldAccountId] = accountId;
123 contactProperties[History::FieldIdentifier] = textChannel->targetContact()->id();
124 contactProperties[History::FieldParticipantState] = History::ParticipantStateRegular;
125 participantIds << textChannel->targetContact()->id();
126@@ -314,6 +315,31 @@
127 return thread;
128 }
129
130+QString HistoryDaemon::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags, bool create)
131+{
132+ if (!mBackend) {
133+ return QString::null;
134+ }
135+
136+ QString threadId = mBackend->threadIdForProperties(accountId,
137+ type,
138+ properties,
139+ matchFlags);
140+ if (threadId.isEmpty() && create) {
141+ QVariantMap thread = mBackend->createThreadForProperties(accountId, type, properties);
142+ if (!thread.isEmpty()) {
143+ if (properties.contains("Requested") && properties[History::FieldChatType].toInt() == History::ChatTypeRoom) {
144+ QVariantMap map = thread[History::FieldChatRoomInfo].toMap();
145+ map["Requested"] = properties["Requested"];
146+ thread[History::FieldChatRoomInfo] = map;
147+ }
148+ mDBus.notifyThreadsAdded(QList<QVariantMap>() << thread);
149+ threadId = thread[History::FieldThreadId].toString();
150+ }
151+ }
152+ return threadId;
153+}
154+
155 QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties)
156 {
157 if (!mBackend) {
158@@ -370,7 +396,7 @@
159 return mBackend->getSingleEvent((History::EventType)type, accountId, threadId, eventId);
160 }
161
162-bool HistoryDaemon::writeEvents(const QList<QVariantMap> &events, const QVariantMap &properties)
163+bool HistoryDaemon::writeEvents(const QList<QVariantMap> &events, const QVariantMap &properties, bool notify)
164 {
165 if (!mBackend) {
166 return false;
167@@ -407,7 +433,9 @@
168 threads[hash] = thread;
169
170 // set the participants field in the event
171- savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];
172+ if (type == History::EventTypeVoice) {
173+ savedEvent[History::FieldParticipants] = thread[History::FieldParticipants];
174+ }
175
176
177 // check if the event was a new one or a modification to an existing one
178@@ -427,13 +455,13 @@
179 mBackend->endBatchOperation();
180
181 // and last but not least, notify the results
182- if (!newEvents.isEmpty()) {
183+ if (!newEvents.isEmpty() && notify) {
184 mDBus.notifyEventsAdded(newEvents);
185 }
186- if (!modifiedEvents.isEmpty()) {
187+ if (!modifiedEvents.isEmpty() && notify) {
188 mDBus.notifyEventsModified(modifiedEvents);
189 }
190- if (!threads.isEmpty()) {
191+ if (!threads.isEmpty() && notify) {
192 mDBus.notifyThreadsModified(threads.values());
193 }
194 return true;
195@@ -620,6 +648,7 @@
196 // for Rooms we need to explicitly create the thread to allow users to send messages to groups even
197 // before they receive any message.
198 // for other types, we can wait until messages are received
199+ bool notify = false;
200 if (channel->targetHandleType() == Tp::HandleTypeRoom) {
201 QString accountId = channel->property(History::FieldAccountId).toString();
202 QVariantMap properties = propertiesFromChannel(channel);
203@@ -641,12 +670,13 @@
204
205 // write information event including all initial invitees
206 Q_FOREACH(const Tp::ContactPtr contact, channel->groupRemotePendingContacts(false)) {
207- writeInformationEvent(thread, History::InformationTypeInvitationSent, contact->alias());
208+ writeInformationEvent(thread, History::InformationTypeInvitationSent, contact->alias(), QString(), QString(), false);
209 }
210
211 // update participants only if the thread is not available previously. Otherwise we'll wait for membersChanged event
212 // for reflect in conversation information events for modified participants.
213- updateRoomParticipants(channel);
214+ updateRoomParticipants(channel, false);
215+ notify = true;
216 }
217
218 // write an entry saying you joined the group if 'joined' flag in thread is false and modify that flag.
219@@ -657,7 +687,8 @@
220 writeInformationEvent(thread, History::InformationTypeSelfJoined);
221 }
222 // update backend
223- updateRoomProperties(channel, QVariantMap{{"Joined", true}});
224+ updateRoomProperties(channel, QVariantMap{{"Joined", true}}, false);
225+ notify = true;
226 }
227
228 Tp::AbstractInterface *room_interface = channel->optionalInterface<Tp::Client::ChannelInterfaceRoomInterface>();
229@@ -685,6 +716,10 @@
230
231 connect(roles_interface, SIGNAL(RolesChanged(const HandleRolesMap&, const HandleRolesMap&)), SLOT(onRolesChanged(const HandleRolesMap&, const HandleRolesMap&)));
232 }
233+
234+ if (notify) {
235+ updateRoomParticipants(channel, true);
236+ }
237 }
238
239 void HistoryDaemon::onGroupMembersChanged(const Tp::Contacts &groupMembersAdded,
240@@ -702,6 +737,8 @@
241 bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0;
242 bool hasMembersAdded = groupMembersAdded.size() > 0;
243 bool hasMembersRemoved = groupMembersRemoved.size() > 0;
244+ Tp::ContactPtr selfContact = channel->connection()->selfContact();
245+ bool selfContactIsPending = channel->groupRemotePendingContacts(true).contains(selfContact);
246
247 if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) {
248 properties = propertiesFromChannel(channel);
249@@ -710,19 +747,34 @@
250 properties,
251 matchFlagsForChannel(channel),
252 false);
253- if (!thread.isEmpty()) {
254+ if (!thread.isEmpty() && !selfContactIsPending) {
255+ QList<QVariantMap> added;
256+ QList<QVariantMap> removed;
257+ QList<QVariantMap> modified;
258 if (hasRemotePendingMembersAdded) {
259 Q_FOREACH (const Tp::ContactPtr& contact, groupRemotePendingMembersAdded) {
260 if (!foundInThread(contact, thread)) {
261- writeInformationEvent(thread, History::InformationTypeInvitationSent, contact->alias());
262+ writeInformationEvent(thread, History::InformationTypeInvitationSent, contact->alias(), QString(), QString(), true);
263+ QVariantMap participant;
264+ participant[History::FieldIdentifier] = contact->id();
265+ participant[History::FieldAlias] = contact->alias();
266+ participant[History::FieldParticipantState] = History::ParticipantStateRemotePending;
267+ added << participant;
268 }
269 }
270+
271 }
272 if (hasMembersAdded) {
273 Q_FOREACH (const Tp::ContactPtr& contact, groupMembersAdded) {
274 // if this member was not previously regular member in thread, notify about his join
275 if (!foundAsMemberInThread(contact, thread)) {
276- writeInformationEvent(thread, History::InformationTypeJoined, contact->alias());
277+ writeInformationEvent(thread, History::InformationTypeJoined, contact->alias(), QString(), QString(), true);
278+
279+ QVariantMap participant;
280+ participant[History::FieldIdentifier] = contact->id();
281+ participant[History::FieldAlias] = contact->alias();
282+ participant[History::FieldParticipantState] = History::ParticipantStateRegular;
283+ added << participant;
284 }
285 }
286 }
287@@ -743,25 +795,30 @@
288 }
289 writeInformationEvent(thread, type);
290 // update backend
291- updateRoomProperties(channel, QVariantMap{{"Joined", false}});
292+ updateRoomProperties(channel, QVariantMap{{"Joined", false}}, true);
293 }
294 else // don't notify any other group member removal if we are leaving the group
295 {
296 Q_FOREACH (const Tp::ContactPtr& contact, groupMembersRemoved) {
297 // inform about removed members other than us
298 if (contact->id() != channel->groupSelfContact()->id()) {
299- writeInformationEvent(thread, History::InformationTypeLeaving, contact->alias());
300+ writeInformationEvent(thread, History::InformationTypeLeaving, contact->alias(), QString(), QString(), true);
301 }
302+ QVariantMap participant;
303+ participant[History::FieldIdentifier] = contact->id();
304+ participant[History::FieldAlias] = contact->alias();
305+ removed << participant;
306 }
307 }
308 }
309+ mDBus.notifyThreadParticipantsChanged(thread, added, removed, QList<QVariantMap>());
310 }
311 }
312
313- updateRoomParticipants(channel);
314+ updateRoomParticipants(channel, !selfContactIsPending);
315 }
316
317-void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel)
318+void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify)
319 {
320 if (!channel) {
321 return;
322@@ -811,12 +868,14 @@
323 QString accountId = channel->property(History::FieldAccountId).toString();
324 QString threadId = channel->targetId();
325 if (mBackend->updateRoomParticipants(accountId, threadId, History::EventTypeText, participants)) {
326- QVariantMap updatedThread = getSingleThread(History::EventTypeText, accountId, threadId, QVariantMap());
327- mDBus.notifyThreadsModified(QList<QVariantMap>() << updatedThread);
328+ if (notify) {
329+ QVariantMap updatedThread = getSingleThread(History::EventTypeText, accountId, threadId, QVariantMap());
330+ mDBus.notifyThreadsModified(QList<QVariantMap>() << updatedThread);
331+ }
332 }
333 }
334
335-void HistoryDaemon::updateRoomRoles(const Tp::TextChannelPtr &channel, const RolesMap &rolesMap)
336+void HistoryDaemon::updateRoomRoles(const Tp::TextChannelPtr &channel, const RolesMap &rolesMap, bool notify)
337 {
338 if (!channel) {
339 return;
340@@ -841,8 +900,10 @@
341 QString accountId = channel->property(History::FieldAccountId).toString();
342 QString threadId = channel->targetId();
343 if (mBackend->updateRoomParticipantsRoles(accountId, threadId, History::EventTypeText, participantsRoles)) {
344- QVariantMap updatedThread = getSingleThread(History::EventTypeText, accountId, threadId, QVariantMap());
345- mDBus.notifyThreadsModified(QList<QVariantMap>() << updatedThread);
346+ if (notify) {
347+ QVariantMap updatedThread = getSingleThread(History::EventTypeText, accountId, threadId, QVariantMap());
348+ mDBus.notifyThreadsModified(QList<QVariantMap>() << updatedThread);
349+ }
350 }
351
352 // update self roles in room properties
353@@ -865,19 +926,21 @@
354 updateRoomProperties(accountId, threadId, type, properties, invalidated);
355 }
356
357-void HistoryDaemon::updateRoomProperties(const Tp::TextChannelPtr &channel, const QVariantMap &properties)
358+void HistoryDaemon::updateRoomProperties(const Tp::TextChannelPtr &channel, const QVariantMap &properties, bool notify)
359 {
360 QString accountId = channel->property(History::FieldAccountId).toString();
361 QString threadId = channel->targetId();
362 History::EventType type = History::EventTypeText;
363- updateRoomProperties(accountId, threadId, type, properties, QStringList());
364+ updateRoomProperties(accountId, threadId, type, properties, QStringList(), notify);
365 }
366
367-void HistoryDaemon::updateRoomProperties(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &properties, const QStringList &invalidated)
368+void HistoryDaemon::updateRoomProperties(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &properties, const QStringList &invalidated, bool notify)
369 {
370 if (mBackend->updateRoomInfo(accountId, threadId, type, properties, invalidated)) {
371- QVariantMap thread = getSingleThread(type, accountId, threadId, QVariantMap());
372- mDBus.notifyThreadsModified(QList<QVariantMap>() << thread);
373+ if (notify) {
374+ QVariantMap thread = getSingleThread(type, accountId, threadId, QVariantMap());
375+ mDBus.notifyThreadsModified(QList<QVariantMap>() << thread);
376+ }
377 }
378 }
379
380@@ -955,19 +1018,20 @@
381 return;
382 }
383
384- QVariantMap thread = threadForProperties(textChannel->property(History::FieldAccountId).toString(),
385- History::EventTypeText,
386- properties,
387- matchFlagsForChannel(textChannel),
388- true);
389+ QString accountId = textChannel->property(History::FieldAccountId).toString();
390+ QString threadId = threadIdForProperties(accountId,
391+ History::EventTypeText,
392+ properties,
393+ matchFlagsForChannel(textChannel),
394+ true);
395 int count = 1;
396 QList<QVariantMap> attachments;
397 History::MessageType type = History::MessageTypeText;
398 QString subject;
399
400 if (message.hasNonTextContent()) {
401- QString normalizedAccountId = QString(QCryptographicHash::hash(thread[History::FieldAccountId].toString().toLatin1(), QCryptographicHash::Md5).toHex());
402- QString normalizedThreadId = QString(QCryptographicHash::hash(thread[History::FieldThreadId].toString().toLatin1(), QCryptographicHash::Md5).toHex());
403+ QString normalizedAccountId = QString(QCryptographicHash::hash(accountId.toLatin1(), QCryptographicHash::Md5).toHex());
404+ QString normalizedThreadId = QString(QCryptographicHash::hash(threadId.toLatin1(), QCryptographicHash::Md5).toHex());
405 QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex());
406 QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation);
407
408@@ -1000,8 +1064,8 @@
409 file.close();
410
411 QVariantMap attachment;
412- attachment[History::FieldAccountId] = thread[History::FieldAccountId];
413- attachment[History::FieldThreadId] = thread[History::FieldThreadId];
414+ attachment[History::FieldAccountId] = accountId;
415+ attachment[History::FieldThreadId] = threadId;
416 attachment[History::FieldEventId] = eventId;
417 attachment[History::FieldAttachmentId] = part["identifier"].variant();
418 attachment[History::FieldContentType] = part["content-type"].variant();
419@@ -1013,8 +1077,8 @@
420
421 QVariantMap event;
422 event[History::FieldType] = History::EventTypeText;
423- event[History::FieldAccountId] = thread[History::FieldAccountId];
424- event[History::FieldThreadId] = thread[History::FieldThreadId];
425+ event[History::FieldAccountId] = accountId;
426+ event[History::FieldThreadId] = threadId;
427 event[History::FieldEventId] = eventId;
428 event[History::FieldSenderId] = senderId;
429 event[History::FieldTimestamp] = message.received().toString("yyyy-MM-ddTHH:mm:ss.zzz");
430@@ -1191,7 +1255,7 @@
431 return reply.value();
432 }
433
434-void HistoryDaemon::writeInformationEvent(const QVariantMap &thread, History::InformationType type, const QString &subject, const QString &sender, const QString &text)
435+void HistoryDaemon::writeInformationEvent(const QVariantMap &thread, History::InformationType type, const QString &subject, const QString &sender, const QString &text, bool notify)
436 {
437 History::TextEvent historyEvent = History::TextEvent(thread[History::FieldAccountId].toString(),
438 thread[History::FieldThreadId].toString(),
439@@ -1207,7 +1271,7 @@
440 QDateTime::currentDateTime(),
441 subject,
442 type);
443- writeEvents(QList<QVariantMap>() << historyEvent.properties(), thread);
444+ writeEvents(QList<QVariantMap>() << historyEvent.properties(), thread, notify);
445 }
446
447 void HistoryDaemon::writeRoomChangesInformationEvents(const QVariantMap &thread, const QVariantMap &interfaceProperties)
448
449=== modified file 'daemon/historydaemon.h'
450--- daemon/historydaemon.h 2016-10-20 13:56:10 +0000
451+++ daemon/historydaemon.h 2017-02-01 17:42:07 +0000
452@@ -1,5 +1,5 @@
453 /*
454- * Copyright (C) 2013-2016 Canonical, Ltd.
455+ * Copyright (C) 2013-2017 Canonical, Ltd.
456 *
457 * Authors:
458 * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com>
459@@ -48,13 +48,18 @@
460 const QVariantMap &properties,
461 History::MatchFlags matchFlags = History::MatchCaseSensitive,
462 bool create = true);
463+ QString threadIdForProperties(const QString &accountId,
464+ History::EventType type,
465+ const QVariantMap &properties,
466+ History::MatchFlags matchFlags = History::MatchCaseSensitive,
467+ bool create = true);
468 QString queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties);
469 QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter);
470 QVariantMap getSingleThread(int type, const QString &accountId, const QString &threadId, const QVariantMap &properties);
471 QVariantMap getSingleEvent(int type, const QString &accountId, const QString &threadId, const QString &eventId);
472 QVariantMap getSingleEventFromTextChannel(const Tp::TextChannelPtr textChannel, const QString &messageId);
473
474- bool writeEvents(const QList<QVariantMap> &events, const QVariantMap &properties);
475+ bool writeEvents(const QList<QVariantMap> &events, const QVariantMap &properties, bool notify = true);
476 bool removeEvents(const QList<QVariantMap> &events);
477 bool removeThreads(const QList<QVariantMap> &threads);
478
479@@ -73,14 +78,14 @@
480
481 protected:
482 History::MatchFlags matchFlagsForChannel(const Tp::ChannelPtr &channel);
483- void updateRoomParticipants(const Tp::TextChannelPtr channel);
484- void updateRoomRoles(const Tp::TextChannelPtr &channel, const RolesMap &rolesMap);
485+ void updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify = true);
486+ void updateRoomRoles(const Tp::TextChannelPtr &channel, const RolesMap &rolesMap, bool notify = true);
487 QString hashThread(const QVariantMap &thread);
488 static QVariantMap getInterfaceProperties(const Tp::AbstractInterface *interface);
489- void updateRoomProperties(const Tp::TextChannelPtr &channel, const QVariantMap &properties);
490- void updateRoomProperties(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &properties, const QStringList &invalidated);
491+ void updateRoomProperties(const Tp::TextChannelPtr &channel, const QVariantMap &properties, bool notify = true);
492+ void updateRoomProperties(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &properties, const QStringList &invalidated, bool notify = true);
493
494- void writeInformationEvent(const QVariantMap &thread, History::InformationType type, const QString &subject = QString(), const QString &sender = QString("self"), const QString &text = QString());
495+ void writeInformationEvent(const QVariantMap &thread, History::InformationType type, const QString &subject = QString(), const QString &sender = QString("self"), const QString &text = QString(), bool notify = true);
496
497 void writeRoomChangesInformationEvents(const QVariantMap &thread, const QVariantMap &interfaceProperties);
498 void writeRolesInformationEvents(const QVariantMap &thread, const Tp::ChannelPtr &channel, const RolesMap &rolesMap);
499
500=== modified file 'daemon/historyservicedbus.cpp'
501--- daemon/historyservicedbus.cpp 2016-11-24 01:56:01 +0000
502+++ daemon/historyservicedbus.cpp 2017-02-01 17:42:07 +0000
503@@ -75,6 +75,14 @@
504 Q_EMIT EventsRemoved(events);
505 }
506
507+void HistoryServiceDBus::notifyThreadParticipantsChanged(const QVariantMap &thread,
508+ const QList<QVariantMap> &added,
509+ const QList<QVariantMap> &removed,
510+ const QList<QVariantMap> &modified)
511+{
512+ Q_EMIT ThreadParticipantsChanged(thread, added, removed, modified);
513+}
514+
515 QVariantMap HistoryServiceDBus::ThreadForProperties(const QString &accountId,
516 int type,
517 const QVariantMap &properties,
518
519=== modified file 'daemon/historyservicedbus.h'
520--- daemon/historyservicedbus.h 2016-06-17 01:49:46 +0000
521+++ daemon/historyservicedbus.h 2017-02-01 17:42:07 +0000
522@@ -39,6 +39,10 @@
523 void notifyThreadsAdded(const QList<QVariantMap> &threads);
524 void notifyThreadsModified(const QList<QVariantMap> &threads);
525 void notifyThreadsRemoved(const QList<QVariantMap> &threads);
526+ void notifyThreadParticipantsChanged(const QVariantMap &thread,
527+ const QList<QVariantMap> &added,
528+ const QList<QVariantMap> &removed,
529+ const QList<QVariantMap> &modified);
530
531 void notifyEventsAdded(const QList<QVariantMap> &events);
532 void notifyEventsModified(const QList<QVariantMap> &events);
533@@ -70,6 +74,10 @@
534 void ThreadsAdded(const QList<QVariantMap> &threads);
535 void ThreadsModified(const QList<QVariantMap> &threads);
536 void ThreadsRemoved(const QList<QVariantMap> &threads);
537+ void ThreadParticipantsChanged(const QVariantMap &thread,
538+ const QList<QVariantMap> &added,
539+ const QList<QVariantMap> &removed,
540+ const QList<QVariantMap> &modified);
541
542 void EventsAdded(const QList<QVariantMap> &events);
543 void EventsModified(const QList<QVariantMap> &events);
544
545=== modified file 'plugins/sqlite/sqlitehistoryplugin.cpp'
546--- plugins/sqlite/sqlitehistoryplugin.cpp 2016-11-24 01:50:48 +0000
547+++ plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-01 17:42:07 +0000
548@@ -315,8 +315,6 @@
549 return QVariantMap();
550 }
551
552- QSqlQuery query(SQLiteDatabase::instance()->database());
553-
554 History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
555
556 if (chatType == History::ChatTypeRoom) {
557@@ -332,6 +330,24 @@
558 return threadForParticipants(accountId, type, participants.identifiers(), matchFlags);
559 }
560
561+QString SQLiteHistoryPlugin::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags)
562+{
563+ if (properties.isEmpty()) {
564+ return QString::null;
565+ }
566+
567+ // if chat type is room, just get the threadId directly
568+ History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt();
569+ if (chatType == History::ChatTypeRoom) {
570+ QString threadId = properties[History::FieldThreadId].toString();
571+ return threadId;
572+ }
573+
574+ // if chat type is anything else, fallback to returning the threadId from the participants list
575+ History::Participants participants = History::Participants::fromVariant(properties[History::FieldParticipantIds]);
576+ return threadForParticipants(accountId, type, participants.identifiers(), matchFlags)[History::FieldThreadId].toString();
577+}
578+
579 QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId,
580 History::EventType type,
581 const QStringList &participants,
582@@ -1290,6 +1306,9 @@
583 chatRoomInfo["SelfRoles"] = query1.value(20).toInt();
584
585 thread[History::FieldChatRoomInfo] = chatRoomInfo;
586+ if (!History::Utils::shouldIncludeParticipants(accountId)) {
587+ thread.remove(History::FieldParticipants);
588+ }
589 }
590 break;
591 case History::EventTypeVoice:
592@@ -1317,7 +1336,8 @@
593 QString queryText;
594 switch (type) {
595 case History::EventTypeText:
596- participantsField = participantsField.arg("text_events", QString::number(type));
597+ // for text events we don't need the participants at all
598+ participantsField = "\"\" as participants";
599 queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, "
600 "message, messageType, messageStatus, readTimestamp, subject, informationType FROM text_events %2 %3").arg(participantsField, modifiedCondition, order);
601 break;
602@@ -1353,8 +1373,10 @@
603 event[History::FieldSenderId] = query.value(3);
604 event[History::FieldTimestamp] = toLocalTimeString(query.value(4).toDateTime());
605 event[History::FieldNewEvent] = query.value(5).toBool();
606- QStringList participants = query.value(6).toString().split("|,|");
607- event[History::FieldParticipants] = History::ContactMatcher::instance()->contactInfo(accountId, participants, true);
608+ if (type != History::EventTypeText) {
609+ QStringList participants = query.value(6).toString().split("|,|");
610+ event[History::FieldParticipants] = History::ContactMatcher::instance()->contactInfo(accountId, participants, true);
611+ }
612
613 switch (type) {
614 case History::EventTypeText:
615
616=== modified file 'plugins/sqlite/sqlitehistoryplugin.h'
617--- plugins/sqlite/sqlitehistoryplugin.h 2016-09-21 17:44:39 +0000
618+++ plugins/sqlite/sqlitehistoryplugin.h 2017-02-01 17:42:07 +0000
619@@ -59,6 +59,10 @@
620 History::EventType type,
621 const QVariantMap &properties,
622 History::MatchFlags matchFlags = History::MatchCaseSensitive);
623+ virtual QString threadIdForProperties(const QString &accountId,
624+ History::EventType type,
625+ const QVariantMap &properties,
626+ History::MatchFlags matchFlags = History::MatchCaseSensitive) override;
627
628 QList<QVariantMap> eventsForThread(const QVariantMap &thread);
629
630
631=== modified file 'src/manager.cpp'
632--- src/manager.cpp 2016-06-17 01:49:46 +0000
633+++ src/manager.cpp 2017-02-01 17:42:07 +0000
634@@ -65,6 +65,9 @@
635 SIGNAL(threadsRemoved(History::Threads)),
636 SIGNAL(threadsRemoved(History::Threads)));
637 connect(d->dbus.data(),
638+ SIGNAL(threadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)),
639+ SIGNAL(threadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)));
640+ connect(d->dbus.data(),
641 SIGNAL(eventsAdded(History::Events)),
642 SIGNAL(eventsAdded(History::Events)));
643 connect(d->dbus.data(),
644
645=== modified file 'src/manager.h'
646--- src/manager.h 2016-06-17 01:49:46 +0000
647+++ src/manager.h 2017-02-01 17:42:07 +0000
648@@ -79,6 +79,7 @@
649 void threadsAdded(const History::Threads &threads);
650 void threadsModified(const History::Threads &threads);
651 void threadsRemoved(const History::Threads &threads);
652+ void threadParticipantsChanged(const History::Thread &thread, const History::Participants &added, const History::Participants &removed, const History::Participants &modified);
653
654 void eventsAdded(const History::Events &events);
655 void eventsModified(const History::Events &events);
656
657=== modified file 'src/managerdbus.cpp'
658--- src/managerdbus.cpp 2016-06-17 01:49:46 +0000
659+++ src/managerdbus.cpp 2017-02-01 17:42:07 +0000
660@@ -50,6 +50,12 @@
661 connection.connect(DBusService, DBusObjectPath, DBusInterface, "ThreadsRemoved",
662 this, SLOT(onThreadsRemoved(QList<QVariantMap>)));
663
664+ connection.connect(DBusService, DBusObjectPath, DBusInterface, "ThreadParticipantsChanged",
665+ this, SLOT(onThreadParticipantsChanged(QVariantMap,
666+ QList<QVariantMap>,
667+ QList<QVariantMap>,
668+ QList<QVariantMap>)));
669+
670 connection.connect(DBusService, DBusObjectPath, DBusInterface, "EventsAdded",
671 this, SLOT(onEventsAdded(QList<QVariantMap>)));
672 connection.connect(DBusService, DBusObjectPath, DBusInterface, "EventsModified",
673@@ -168,6 +174,17 @@
674 Q_EMIT threadsRemoved(threadsFromProperties(threads));
675 }
676
677+void ManagerDBus::onThreadParticipantsChanged(const QVariantMap &thread,
678+ const QList<QVariantMap> &added,
679+ const QList<QVariantMap> &removed,
680+ const QList<QVariantMap> &modified)
681+{
682+ Q_EMIT threadParticipantsChanged(threadsFromProperties(QList<QVariantMap>() << thread).first(),
683+ Participants::fromVariantMapList(added),
684+ Participants::fromVariantMapList(removed),
685+ Participants::fromVariantMapList(modified));
686+}
687+
688 void ManagerDBus::onEventsAdded(const QList<QVariantMap> &events)
689 {
690 Q_EMIT eventsAdded(eventsFromProperties(events));
691
692=== modified file 'src/managerdbus_p.h'
693--- src/managerdbus_p.h 2016-06-17 01:49:46 +0000
694+++ src/managerdbus_p.h 2017-02-01 17:42:07 +0000
695@@ -62,6 +62,10 @@
696 void threadsAdded(const History::Threads &threads);
697 void threadsModified(const History::Threads &threads);
698 void threadsRemoved(const History::Threads &threads);
699+ void threadParticipantsChanged(const History::Thread &thread,
700+ const History::Participants &added,
701+ const History::Participants &removed,
702+ const History::Participants &modified);
703
704 void eventsAdded(const History::Events &events);
705 void eventsModified(const History::Events &events);
706@@ -71,6 +75,10 @@
707 void onThreadsAdded(const QList<QVariantMap> &threads);
708 void onThreadsModified(const QList<QVariantMap> &threads);
709 void onThreadsRemoved(const QList<QVariantMap> &threads);
710+ void onThreadParticipantsChanged(const QVariantMap &thread,
711+ const QList<QVariantMap> &added,
712+ const QList<QVariantMap> &removed,
713+ const QList<QVariantMap> &modified);
714
715 void onEventsAdded(const QList<QVariantMap> &events);
716 void onEventsModified(const QList<QVariantMap> &events);
717
718=== modified file 'src/participant.cpp'
719--- src/participant.cpp 2016-11-24 01:04:37 +0000
720+++ src/participant.cpp 2017-02-01 17:42:07 +0000
721@@ -233,6 +233,15 @@
722 return participants;
723 }
724
725+Participants Participants::fromVariantMapList(const QList<QVariantMap> &list)
726+{
727+ Participants participants;
728+ Q_FOREACH(const QVariantMap& entry, list) {
729+ participants << Participant::fromProperties(entry);
730+ }
731+ return participants;
732+}
733+
734 QVariantList Participants::toVariantList() const
735 {
736 QVariantList list;
737
738=== modified file 'src/participant.h'
739--- src/participant.h 2016-11-24 01:04:37 +0000
740+++ src/participant.h 2017-02-01 17:42:07 +0000
741@@ -79,6 +79,7 @@
742 QStringList identifiers() const;
743 static Participants fromVariant(const QVariant &variant);
744 static Participants fromVariantList(const QVariantList &list);
745+ static Participants fromVariantMapList(const QList<QVariantMap> &list);
746 static Participants fromStringList(const QStringList &list);
747 QVariantList toVariantList() const;
748 History::Participants filterByState(uint state) const;
749
750=== modified file 'src/plugin.h'
751--- src/plugin.h 2016-09-21 17:44:39 +0000
752+++ src/plugin.h 2017-02-01 17:42:07 +0000
753@@ -65,6 +65,10 @@
754 EventType type,
755 const QVariantMap &properties,
756 History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
757+ virtual QString threadIdForProperties(const QString &accountId,
758+ EventType type,
759+ const QVariantMap &properties,
760+ History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0;
761
762 virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0;
763
764
765=== modified file 'src/thread.cpp'
766--- src/thread.cpp 2016-07-12 02:08:11 +0000
767+++ src/thread.cpp 2017-02-01 17:42:07 +0000
768@@ -192,6 +192,22 @@
769 return selfData < otherData;
770 }
771
772+void Thread::removeParticipants(const Participants &participants)
773+{
774+ Q_D(Thread);
775+ Q_FOREACH(const Participant &participant, participants) {
776+ d->participants.removeAll(participant);
777+ }
778+}
779+
780+void Thread::addParticipants(const Participants &participants)
781+{
782+ Q_D(Thread);
783+ Q_FOREACH(const Participant &participant, participants) {
784+ d->participants.append(participant);
785+ }
786+}
787+
788 QVariantMap Thread::properties() const
789 {
790 Q_D(const Thread);
791
792=== modified file 'src/thread.h'
793--- src/thread.h 2016-07-12 01:59:06 +0000
794+++ src/thread.h 2017-02-01 17:42:07 +0000
795@@ -73,6 +73,8 @@
796 ChatType chatType() const;
797 Threads groupedThreads() const;
798 QVariantMap chatRoomInfo() const;
799+ void addParticipants(const History::Participants &participants);
800+ void removeParticipants(const History::Participants &participants);
801
802 bool isNull() const;
803 bool operator==(const Thread &other) const;
804
805=== modified file 'src/threadview.cpp'
806--- src/threadview.cpp 2015-10-01 19:44:45 +0000
807+++ src/threadview.cpp 2017-02-01 17:42:07 +0000
808@@ -89,6 +89,18 @@
809 }
810 }
811
812+void ThreadViewPrivate::_d_threadParticipantsChanged(const History::Thread &thread,
813+ const History::Participants &added,
814+ const History::Participants &removed,
815+ const History::Participants &modified)
816+{
817+ Q_Q(ThreadView);
818+ Threads filtered = filteredThreads(History::Threads() << thread);
819+ if (!filtered.isEmpty()) {
820+ Q_EMIT q->threadParticipantsChanged(filtered.first(), added, removed, modified);
821+ }
822+}
823+
824 // ------------- ThreadView -------------------------------------------------------
825
826 ThreadView::ThreadView(History::EventType type,
827@@ -132,6 +144,9 @@
828 connect(Manager::instance(),
829 SIGNAL(threadsRemoved(History::Threads)),
830 SLOT(_d_threadsRemoved(History::Threads)));
831+ connect(Manager::instance(),
832+ SIGNAL(threadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)),
833+ SLOT(_d_threadParticipantsChanged(History::Thread, History::Participants, History::Participants, History::Participants)));
834 }
835
836 ThreadView::~ThreadView()
837
838=== modified file 'src/threadview.h'
839--- src/threadview.h 2015-09-21 20:05:06 +0000
840+++ src/threadview.h 2017-02-01 17:42:07 +0000
841@@ -52,12 +52,20 @@
842 void threadsAdded(const History::Threads &threads);
843 void threadsModified(const History::Threads &threads);
844 void threadsRemoved(const History::Threads &threads);
845+ void threadParticipantsChanged(const History::Thread &thread,
846+ const History::Participants &added,
847+ const History::Participants &removed,
848+ const History::Participants &modified);
849 void invalidated();
850
851 private:
852 Q_PRIVATE_SLOT(d_func(), void _d_threadsAdded(const History::Threads &threads))
853 Q_PRIVATE_SLOT(d_func(), void _d_threadsModified(const History::Threads &threads))
854 Q_PRIVATE_SLOT(d_func(), void _d_threadsRemoved(const History::Threads &threads))
855+ Q_PRIVATE_SLOT(d_func(), void _d_threadParticipantsChanged(const History::Thread &thread,
856+ const History::Participants &added,
857+ const History::Participants &removed,
858+ const History::Participants &modified))
859 QScopedPointer<ThreadViewPrivate> d_ptr;
860
861 };
862
863=== modified file 'src/threadview_p.h'
864--- src/threadview_p.h 2013-09-17 21:33:34 +0000
865+++ src/threadview_p.h 2017-02-01 17:42:07 +0000
866@@ -50,6 +50,10 @@
867 void _d_threadsAdded(const History::Threads &threads);
868 void _d_threadsModified(const History::Threads &threads);
869 void _d_threadsRemoved(const History::Threads &threads);
870+ void _d_threadParticipantsChanged(const History::Thread &thread,
871+ const History::Participants &added,
872+ const History::Participants &removed,
873+ const History::Participants &modified);
874
875 ThreadView *q_ptr;
876 };
877
878=== modified file 'src/utils.cpp'
879--- src/utils.cpp 2016-11-08 16:02:18 +0000
880+++ src/utils.cpp 2017-02-01 17:42:07 +0000
881@@ -175,4 +175,11 @@
882 return QVariant();
883 }
884
885+bool Utils::shouldIncludeParticipants(const QString &accountId)
886+{
887+ // FIXME
888+ // this is obviously incorrect. we have to query the protocol files as a final solution
889+ return protocolFromAccountId(accountId) != "irc";
890+}
891+
892 }
893
894=== modified file 'src/utils_p.h'
895--- src/utils_p.h 2016-11-08 16:02:18 +0000
896+++ src/utils_p.h 2017-02-01 17:42:07 +0000
897@@ -36,6 +36,7 @@
898 static bool compareParticipants(const QStringList &participants1, const QStringList &participants2, MatchFlags flags);
899 static bool compareNormalizedParticipants(const QStringList &participants1, const QStringList &participants2, MatchFlags flags);
900 static bool shouldGroupThread(const Thread &thread);
901+ static bool shouldIncludeParticipants(const QString &accountId);
902 static QString normalizeId(const QString &accountId, const QString &id);
903 static QVariant getUserValue(const QString &interface, const QString &propName);
904

Subscribers

People subscribed via source and target branches

to all changes: