Merge lp:~phablet-team/history-service/wait_for_self_not_pending into lp:history-service/staging
- wait_for_self_not_pending
- Merge into 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 |
Related bugs: |
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
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 | 1 | /* | 1 | /* |
7 | 2 | * Copyright (C) 2013-2016 Canonical, Ltd. | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. |
8 | 3 | * | 3 | * |
9 | 4 | * Authors: | 4 | * Authors: |
10 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
11 | @@ -315,6 +315,31 @@ | |||
12 | 315 | return thread; | 315 | return thread; |
13 | 316 | } | 316 | } |
14 | 317 | 317 | ||
15 | 318 | QString HistoryDaemon::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags, bool create) | ||
16 | 319 | { | ||
17 | 320 | if (!mBackend) { | ||
18 | 321 | return QString::null; | ||
19 | 322 | } | ||
20 | 323 | |||
21 | 324 | QString threadId = mBackend->threadIdForProperties(accountId, | ||
22 | 325 | type, | ||
23 | 326 | properties, | ||
24 | 327 | matchFlags); | ||
25 | 328 | if (threadId.isEmpty() && create) { | ||
26 | 329 | QVariantMap thread = mBackend->createThreadForProperties(accountId, type, properties); | ||
27 | 330 | if (!thread.isEmpty()) { | ||
28 | 331 | if (properties.contains("Requested") && properties[History::FieldChatType].toInt() == History::ChatTypeRoom) { | ||
29 | 332 | QVariantMap map = thread[History::FieldChatRoomInfo].toMap(); | ||
30 | 333 | map["Requested"] = properties["Requested"]; | ||
31 | 334 | thread[History::FieldChatRoomInfo] = map; | ||
32 | 335 | } | ||
33 | 336 | mDBus.notifyThreadsAdded(QList<QVariantMap>() << thread); | ||
34 | 337 | threadId = thread[History::FieldThreadId].toString(); | ||
35 | 338 | } | ||
36 | 339 | } | ||
37 | 340 | return threadId; | ||
38 | 341 | } | ||
39 | 342 | |||
40 | 318 | QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties) | 343 | QString HistoryDaemon::queryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties) |
41 | 319 | { | 344 | { |
42 | 320 | if (!mBackend) { | 345 | if (!mBackend) { |
43 | @@ -408,7 +433,9 @@ | |||
44 | 408 | threads[hash] = thread; | 433 | threads[hash] = thread; |
45 | 409 | 434 | ||
46 | 410 | // set the participants field in the event | 435 | // set the participants field in the event |
48 | 411 | savedEvent[History::FieldParticipants] = thread[History::FieldParticipants]; | 436 | if (type == History::EventTypeVoice) { |
49 | 437 | savedEvent[History::FieldParticipants] = thread[History::FieldParticipants]; | ||
50 | 438 | } | ||
51 | 412 | 439 | ||
52 | 413 | 440 | ||
53 | 414 | // check if the event was a new one or a modification to an existing one | 441 | // check if the event was a new one or a modification to an existing one |
54 | @@ -709,6 +736,8 @@ | |||
55 | 709 | bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0; | 736 | bool hasRemotePendingMembersAdded = groupRemotePendingMembersAdded.size() > 0; |
56 | 710 | bool hasMembersAdded = groupMembersAdded.size() > 0; | 737 | bool hasMembersAdded = groupMembersAdded.size() > 0; |
57 | 711 | bool hasMembersRemoved = groupMembersRemoved.size() > 0; | 738 | bool hasMembersRemoved = groupMembersRemoved.size() > 0; |
58 | 739 | Tp::ContactPtr selfContact = channel->connection()->selfContact(); | ||
59 | 740 | bool selfContactIsPending = channel->groupRemotePendingContacts(true).contains(selfContact); | ||
60 | 712 | 741 | ||
61 | 713 | if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) { | 742 | if (hasRemotePendingMembersAdded || hasMembersAdded || hasMembersRemoved) { |
62 | 714 | properties = propertiesFromChannel(channel); | 743 | properties = propertiesFromChannel(channel); |
63 | @@ -717,7 +746,7 @@ | |||
64 | 717 | properties, | 746 | properties, |
65 | 718 | matchFlagsForChannel(channel), | 747 | matchFlagsForChannel(channel), |
66 | 719 | false); | 748 | false); |
68 | 720 | if (!thread.isEmpty()) { | 749 | if (!thread.isEmpty() && !selfContactIsPending) { |
69 | 721 | QList<QVariantMap> added; | 750 | QList<QVariantMap> added; |
70 | 722 | QList<QVariantMap> removed; | 751 | QList<QVariantMap> removed; |
71 | 723 | QList<QVariantMap> modified; | 752 | QList<QVariantMap> modified; |
72 | @@ -785,7 +814,7 @@ | |||
73 | 785 | } | 814 | } |
74 | 786 | } | 815 | } |
75 | 787 | 816 | ||
77 | 788 | updateRoomParticipants(channel, true); | 817 | updateRoomParticipants(channel, !selfContactIsPending); |
78 | 789 | } | 818 | } |
79 | 790 | 819 | ||
80 | 791 | void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify) | 820 | void HistoryDaemon::updateRoomParticipants(const Tp::TextChannelPtr channel, bool notify) |
81 | @@ -988,19 +1017,20 @@ | |||
82 | 988 | return; | 1017 | return; |
83 | 989 | } | 1018 | } |
84 | 990 | 1019 | ||
90 | 991 | QVariantMap thread = threadForProperties(textChannel->property(History::FieldAccountId).toString(), | 1020 | QString accountId = textChannel->property(History::FieldAccountId).toString(); |
91 | 992 | History::EventTypeText, | 1021 | QString threadId = threadIdForProperties(accountId, |
92 | 993 | properties, | 1022 | History::EventTypeText, |
93 | 994 | matchFlagsForChannel(textChannel), | 1023 | properties, |
94 | 995 | true); | 1024 | matchFlagsForChannel(textChannel), |
95 | 1025 | true); | ||
96 | 996 | int count = 1; | 1026 | int count = 1; |
97 | 997 | QList<QVariantMap> attachments; | 1027 | QList<QVariantMap> attachments; |
98 | 998 | History::MessageType type = History::MessageTypeText; | 1028 | History::MessageType type = History::MessageTypeText; |
99 | 999 | QString subject; | 1029 | QString subject; |
100 | 1000 | 1030 | ||
101 | 1001 | if (message.hasNonTextContent()) { | 1031 | if (message.hasNonTextContent()) { |
104 | 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()); |
105 | 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()); |
106 | 1004 | QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex()); | 1034 | QString normalizedEventId = QString(QCryptographicHash::hash(eventId.toLatin1(), QCryptographicHash::Md5).toHex()); |
107 | 1005 | QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); | 1035 | QString mmsStoragePath = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); |
108 | 1006 | 1036 | ||
109 | @@ -1033,8 +1063,8 @@ | |||
110 | 1033 | file.close(); | 1063 | file.close(); |
111 | 1034 | 1064 | ||
112 | 1035 | QVariantMap attachment; | 1065 | QVariantMap attachment; |
115 | 1036 | attachment[History::FieldAccountId] = thread[History::FieldAccountId]; | 1066 | attachment[History::FieldAccountId] = accountId; |
116 | 1037 | attachment[History::FieldThreadId] = thread[History::FieldThreadId]; | 1067 | attachment[History::FieldThreadId] = threadId; |
117 | 1038 | attachment[History::FieldEventId] = eventId; | 1068 | attachment[History::FieldEventId] = eventId; |
118 | 1039 | attachment[History::FieldAttachmentId] = part["identifier"].variant(); | 1069 | attachment[History::FieldAttachmentId] = part["identifier"].variant(); |
119 | 1040 | attachment[History::FieldContentType] = part["content-type"].variant(); | 1070 | attachment[History::FieldContentType] = part["content-type"].variant(); |
120 | @@ -1046,8 +1076,8 @@ | |||
121 | 1046 | 1076 | ||
122 | 1047 | QVariantMap event; | 1077 | QVariantMap event; |
123 | 1048 | event[History::FieldType] = History::EventTypeText; | 1078 | event[History::FieldType] = History::EventTypeText; |
126 | 1049 | event[History::FieldAccountId] = thread[History::FieldAccountId]; | 1079 | event[History::FieldAccountId] = accountId; |
127 | 1050 | event[History::FieldThreadId] = thread[History::FieldThreadId]; | 1080 | event[History::FieldThreadId] = threadId; |
128 | 1051 | event[History::FieldEventId] = eventId; | 1081 | event[History::FieldEventId] = eventId; |
129 | 1052 | event[History::FieldSenderId] = senderId; | 1082 | event[History::FieldSenderId] = senderId; |
130 | 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"); |
131 | 1054 | 1084 | ||
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 | 1 | /* | 1 | /* |
138 | 2 | * Copyright (C) 2013-2016 Canonical, Ltd. | 2 | * Copyright (C) 2013-2017 Canonical, Ltd. |
139 | 3 | * | 3 | * |
140 | 4 | * Authors: | 4 | * Authors: |
141 | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> | 5 | * Gustavo Pichorim Boiko <gustavo.boiko@canonical.com> |
142 | @@ -48,6 +48,11 @@ | |||
143 | 48 | const QVariantMap &properties, | 48 | const QVariantMap &properties, |
144 | 49 | History::MatchFlags matchFlags = History::MatchCaseSensitive, | 49 | History::MatchFlags matchFlags = History::MatchCaseSensitive, |
145 | 50 | bool create = true); | 50 | bool create = true); |
146 | 51 | QString threadIdForProperties(const QString &accountId, | ||
147 | 52 | History::EventType type, | ||
148 | 53 | const QVariantMap &properties, | ||
149 | 54 | History::MatchFlags matchFlags = History::MatchCaseSensitive, | ||
150 | 55 | bool create = true); | ||
151 | 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); |
152 | 52 | QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter); | 57 | QString queryEvents(int type, const QVariantMap &sort, const QVariantMap &filter); |
153 | 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); |
154 | 54 | 59 | ||
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 | 315 | return QVariantMap(); | 315 | return QVariantMap(); |
160 | 316 | } | 316 | } |
161 | 317 | 317 | ||
162 | 318 | QSqlQuery query(SQLiteDatabase::instance()->database()); | ||
163 | 319 | |||
164 | 320 | History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt(); | 318 | History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt(); |
165 | 321 | 319 | ||
166 | 322 | if (chatType == History::ChatTypeRoom) { | 320 | if (chatType == History::ChatTypeRoom) { |
167 | @@ -332,6 +330,24 @@ | |||
168 | 332 | return threadForParticipants(accountId, type, participants.identifiers(), matchFlags); | 330 | return threadForParticipants(accountId, type, participants.identifiers(), matchFlags); |
169 | 333 | } | 331 | } |
170 | 334 | 332 | ||
171 | 333 | QString SQLiteHistoryPlugin::threadIdForProperties(const QString &accountId, History::EventType type, const QVariantMap &properties, History::MatchFlags matchFlags) | ||
172 | 334 | { | ||
173 | 335 | if (properties.isEmpty()) { | ||
174 | 336 | return QString::null; | ||
175 | 337 | } | ||
176 | 338 | |||
177 | 339 | // if chat type is room, just get the threadId directly | ||
178 | 340 | History::ChatType chatType = (History::ChatType)properties[History::FieldChatType].toUInt(); | ||
179 | 341 | if (chatType == History::ChatTypeRoom) { | ||
180 | 342 | QString threadId = properties[History::FieldThreadId].toString(); | ||
181 | 343 | return threadId; | ||
182 | 344 | } | ||
183 | 345 | |||
184 | 346 | // if chat type is anything else, fallback to returning the threadId from the participants list | ||
185 | 347 | History::Participants participants = History::Participants::fromVariant(properties[History::FieldParticipantIds]); | ||
186 | 348 | return threadForParticipants(accountId, type, participants.identifiers(), matchFlags)[History::FieldThreadId].toString(); | ||
187 | 349 | } | ||
188 | 350 | |||
189 | 335 | QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId, | 351 | QVariantMap SQLiteHistoryPlugin::threadForParticipants(const QString &accountId, |
190 | 336 | History::EventType type, | 352 | History::EventType type, |
191 | 337 | const QStringList &participants, | 353 | const QStringList &participants, |
192 | @@ -1320,7 +1336,8 @@ | |||
193 | 1320 | QString queryText; | 1336 | QString queryText; |
194 | 1321 | switch (type) { | 1337 | switch (type) { |
195 | 1322 | case History::EventTypeText: | 1338 | case History::EventTypeText: |
197 | 1323 | participantsField = participantsField.arg("text_events", QString::number(type)); | 1339 | // for text events we don't need the participants at all |
198 | 1340 | participantsField = "\"\" as participants"; | ||
199 | 1324 | queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, " | 1341 | queryText = QString("SELECT accountId, threadId, eventId, senderId, timestamp, newEvent, %1, " |
200 | 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); |
201 | 1326 | break; | 1343 | break; |
202 | 1327 | 1344 | ||
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 | 59 | History::EventType type, | 59 | History::EventType type, |
208 | 60 | const QVariantMap &properties, | 60 | const QVariantMap &properties, |
209 | 61 | History::MatchFlags matchFlags = History::MatchCaseSensitive); | 61 | History::MatchFlags matchFlags = History::MatchCaseSensitive); |
210 | 62 | virtual QString threadIdForProperties(const QString &accountId, | ||
211 | 63 | History::EventType type, | ||
212 | 64 | const QVariantMap &properties, | ||
213 | 65 | History::MatchFlags matchFlags = History::MatchCaseSensitive) override; | ||
214 | 62 | 66 | ||
215 | 63 | QList<QVariantMap> eventsForThread(const QVariantMap &thread); | 67 | QList<QVariantMap> eventsForThread(const QVariantMap &thread); |
216 | 64 | 68 | ||
217 | 65 | 69 | ||
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 | 65 | EventType type, | 65 | EventType type, |
223 | 66 | const QVariantMap &properties, | 66 | const QVariantMap &properties, |
224 | 67 | History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0; | 67 | History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0; |
225 | 68 | virtual QString threadIdForProperties(const QString &accountId, | ||
226 | 69 | EventType type, | ||
227 | 70 | const QVariantMap &properties, | ||
228 | 71 | History::MatchFlags matchFlags = History::MatchCaseSensitive) = 0; | ||
229 | 68 | 72 | ||
230 | 69 | virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0; | 73 | virtual QList<QVariantMap> eventsForThread(const QVariantMap &thread) = 0; |
231 | 70 | 74 |
looks good. thanks.