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

Proposed by Tiago Salem Herrmann
Status: Merged
Approved by: Gustavo Pichorim Boiko
Approved revision: 259
Merged at revision: 259
Proposed branch: lp:~phablet-team/history-service/mark_threads_as_read
Merge into: lp:history-service/staging
Prerequisite: lp:~phablet-team/history-service/improve_roles_management
Diff against target: 263 lines (+110/-0)
14 files modified
Ubuntu/History/historythreadmodel.cpp (+19/-0)
Ubuntu/History/historythreadmodel.h (+1/-0)
daemon/HistoryService.xml (+7/-0)
daemon/historydaemon.cpp (+23/-0)
daemon/historydaemon.h (+1/-0)
daemon/historyservicedbus.cpp (+5/-0)
daemon/historyservicedbus.h (+1/-0)
plugins/sqlite/sqlitehistoryplugin.cpp (+31/-0)
plugins/sqlite/sqlitehistoryplugin.h (+1/-0)
src/manager.cpp (+7/-0)
src/manager.h (+2/-0)
src/managerdbus.cpp (+10/-0)
src/managerdbus_p.h (+1/-0)
src/plugin.h (+1/-0)
To merge this branch: bzr merge lp:~phablet-team/history-service/mark_threads_as_read
Reviewer Review Type Date Requested Status
Gustavo Pichorim Boiko (community) Approve
Review via email: mp+316572@code.launchpad.net

Commit message

Mark entire conversations as read.

Description of the change

Mark entire conversations as read.

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

merge parent branch

259. By Tiago Salem Herrmann

merge parent branch

Revision history for this message
Gustavo Pichorim Boiko (boiko) wrote :

Looks good!

review: Approve

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 2017-02-21 15:16:27 +0000
3+++ Ubuntu/History/historythreadmodel.cpp 2017-02-21 15:16:27 +0000
4@@ -232,6 +232,25 @@
5 return mRoles;
6 }
7
8+void HistoryThreadModel::markThreadsAsRead(const QVariantList &threadsProperties)
9+{
10+ History::Threads threads;
11+ Q_FOREACH(const QVariant &entry, threadsProperties) {
12+ QVariantMap threadProperties = entry.toMap();
13+ History::Thread thread = History::Thread::fromProperties(threadProperties);
14+
15+ if (!thread.isNull()) {
16+ threads << thread;
17+ }
18+ }
19+
20+ if (threads.isEmpty()) {
21+ return;
22+ }
23+
24+ History::Manager::instance()->markThreadsAsRead(threads);
25+}
26+
27 bool HistoryThreadModel::removeThreads(const QVariantList &threadsProperties)
28 {
29 History::Threads threads;
30
31=== modified file 'Ubuntu/History/historythreadmodel.h'
32--- Ubuntu/History/historythreadmodel.h 2017-02-21 15:16:27 +0000
33+++ Ubuntu/History/historythreadmodel.h 2017-02-21 15:16:27 +0000
34@@ -70,6 +70,7 @@
35 virtual QHash<int, QByteArray> roleNames() const;
36
37 Q_INVOKABLE bool removeThreads(const QVariantList &threadsProperties);
38+ Q_INVOKABLE void markThreadsAsRead(const QVariantList &threadsProperties);
39
40 protected Q_SLOTS:
41 virtual void updateQuery();
42
43=== modified file 'daemon/HistoryService.xml'
44--- daemon/HistoryService.xml 2017-02-21 15:16:27 +0000
45+++ daemon/HistoryService.xml 2017-02-21 15:16:27 +0000
46@@ -62,6 +62,13 @@
47 <arg type="b" direction="out"/>
48 <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList &lt; QVariantMap &gt;"/>
49 </method>
50+ <method name="MarkThreadsAsRead">
51+ <dox:d><![CDATA[
52+ Mark an entire thread as read
53+ ]]></dox:d>
54+ <arg name="threads" type="a(a{sv})" direction="in"/>
55+ <annotation name="org.qtproject.QtDBus.QtTypeName.In0" value="QList &lt; QVariantMap &gt;"/>
56+ </method>
57 <method name="QueryThreads">
58 <dox:d><![CDATA[
59 Creates a threads view with the given filter and sort order.
60
61=== modified file 'daemon/historydaemon.cpp'
62--- daemon/historydaemon.cpp 2017-02-21 15:16:27 +0000
63+++ daemon/historydaemon.cpp 2017-02-21 15:16:27 +0000
64@@ -561,6 +561,29 @@
65 return true;
66 }
67
68+void HistoryDaemon::markThreadsAsRead(const QList<QVariantMap> &threads)
69+{
70+ if (!mBackend) {
71+ return;
72+ }
73+
74+ QList<QVariantMap> modifiedThreads;
75+
76+ Q_FOREACH(const QVariantMap &thread, threads) {
77+ mBackend->beginBatchOperation();
78+ QVariantMap newThread = mBackend->markThreadAsRead(thread);
79+ if (!newThread.isEmpty()) {
80+ modifiedThreads << newThread;
81+ }
82+
83+ mBackend->endBatchOperation();
84+ }
85+
86+ if (!modifiedThreads.isEmpty()) {
87+ mDBus.notifyThreadsModified(modifiedThreads);
88+ }
89+}
90+
91 bool HistoryDaemon::removeThreads(const QList<QVariantMap> &threads)
92 {
93 if (!mBackend) {
94
95=== modified file 'daemon/historydaemon.h'
96--- daemon/historydaemon.h 2017-02-21 15:16:27 +0000
97+++ daemon/historydaemon.h 2017-02-21 15:16:27 +0000
98@@ -62,6 +62,7 @@
99 bool writeEvents(const QList<QVariantMap> &events, const QVariantMap &properties, bool notify = true);
100 bool removeEvents(const QList<QVariantMap> &events);
101 bool removeThreads(const QList<QVariantMap> &threads);
102+ void markThreadsAsRead(const QList<QVariantMap> &threads);
103
104 private Q_SLOTS:
105 void onObserverCreated();
106
107=== modified file 'daemon/historyservicedbus.cpp'
108--- daemon/historyservicedbus.cpp 2017-02-21 15:16:27 +0000
109+++ daemon/historyservicedbus.cpp 2017-02-21 15:16:27 +0000
110@@ -122,6 +122,11 @@
111 return HistoryDaemon::instance()->removeThreads(threads);
112 }
113
114+void HistoryServiceDBus::MarkThreadsAsRead(const QList<QVariantMap> &threads)
115+{
116+ return HistoryDaemon::instance()->markThreadsAsRead(threads);
117+}
118+
119 bool HistoryServiceDBus::RemoveEvents(const QList<QVariantMap> &events)
120 {
121 return HistoryDaemon::instance()->removeEvents(events);
122
123=== modified file 'daemon/historyservicedbus.h'
124--- daemon/historyservicedbus.h 2017-02-21 15:16:27 +0000
125+++ daemon/historyservicedbus.h 2017-02-21 15:16:27 +0000
126@@ -62,6 +62,7 @@
127 bool WriteEvents(const QList <QVariantMap> &events);
128 bool RemoveThreads(const QList <QVariantMap> &threads);
129 bool RemoveEvents(const QList <QVariantMap> &events);
130+ void MarkThreadsAsRead(const QList <QVariantMap> &threads);
131
132 // views
133 QString QueryThreads(int type, const QVariantMap &sort, const QVariantMap &filter, const QVariantMap &properties);
134
135=== modified file 'plugins/sqlite/sqlitehistoryplugin.cpp'
136--- plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:16:27 +0000
137+++ plugins/sqlite/sqlitehistoryplugin.cpp 2017-02-21 15:16:27 +0000
138@@ -306,6 +306,37 @@
139 return new SQLiteHistoryEventView(this, type, sort, filter);
140 }
141
142+QVariantMap SQLiteHistoryPlugin::markThreadAsRead(const QVariantMap &thread)
143+{
144+ QSqlQuery query(SQLiteDatabase::instance()->database());
145+
146+ if (thread[History::FieldAccountId].toString().isEmpty() ||
147+ thread[History::FieldThreadId].toString().isEmpty()) {
148+ return QVariantMap();
149+ }
150+
151+ query.prepare("UPDATE text_events SET newEvent=:newEvent WHERE accountId=:accountId AND threadId=:threadId");
152+ query.bindValue(":accountId", thread[History::FieldAccountId].toString());
153+ query.bindValue(":threadId", thread[History::FieldThreadId].toString());
154+ query.bindValue(":newEvent", false);
155+
156+ if (!query.exec()) {
157+ qCritical() << "Failed to mark thread as read: Error:" << query.lastError() << query.lastQuery() << query.executedQuery();
158+ return QVariantMap();
159+ }
160+
161+ QVariantMap existingThread = getSingleThread((History::EventType) thread[History::FieldType].toInt(),
162+ thread[History::FieldAccountId].toString(),
163+ thread[History::FieldThreadId].toString(),
164+ QVariantMap());
165+ if (!existingThread.isEmpty()) {
166+ addThreadsToCache(QList<QVariantMap>() << existingThread);
167+ return existingThread;
168+ }
169+
170+ return QVariantMap();
171+}
172+
173 QVariantMap SQLiteHistoryPlugin::threadForProperties(const QString &accountId,
174 History::EventType type,
175 const QVariantMap &properties,
176
177=== modified file 'plugins/sqlite/sqlitehistoryplugin.h'
178--- plugins/sqlite/sqlitehistoryplugin.h 2017-02-21 15:16:27 +0000
179+++ plugins/sqlite/sqlitehistoryplugin.h 2017-02-21 15:16:27 +0000
180@@ -77,6 +77,7 @@
181 bool updateRoomParticipantsRoles(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &participantsRoles);
182 bool updateRoomInfo(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &properties, const QStringList &invalidated = QStringList());
183 bool removeThread(const QVariantMap &thread);
184+ QVariantMap markThreadAsRead(const QVariantMap &thread);
185
186 History::EventWriteResult writeTextEvent(const QVariantMap &event);
187 bool removeTextEvent(const QVariantMap &event);
188
189=== modified file 'src/manager.cpp'
190--- src/manager.cpp 2017-02-21 15:16:27 +0000
191+++ src/manager.cpp 2017-02-21 15:16:27 +0000
192@@ -107,6 +107,13 @@
193 return self;
194 }
195
196+void Manager::markThreadsAsRead(const History::Threads &threads)
197+{
198+ Q_D(Manager);
199+
200+ d->dbus->markThreadsAsRead(threads);
201+}
202+
203 ThreadViewPtr Manager::queryThreads(EventType type,
204 const Sort &sort,
205 const Filter &filter,
206
207=== modified file 'src/manager.h'
208--- src/manager.h 2017-02-21 15:16:27 +0000
209+++ src/manager.h 2017-02-21 15:16:27 +0000
210@@ -73,6 +73,8 @@
211 bool removeThreads(const Threads &threads);
212 bool removeEvents(const Events &events);
213
214+ void markThreadsAsRead(const History::Threads &thread);
215+
216 bool isServiceRunning() const;
217
218 Q_SIGNALS:
219
220=== modified file 'src/managerdbus.cpp'
221--- src/managerdbus.cpp 2017-02-21 15:16:27 +0000
222+++ src/managerdbus.cpp 2017-02-21 15:16:27 +0000
223@@ -76,6 +76,16 @@
224 return threadForProperties(accountId, type, properties, matchFlags, create);
225 }
226
227+void ManagerDBus::markThreadsAsRead(const History::Threads &threads)
228+{
229+ QList<QVariantMap> threadMap = threadsToProperties(threads);
230+ if (threadMap.isEmpty()) {
231+ return;
232+ }
233+
234+ mInterface.asyncCall("MarkThreadsAsRead", QVariant::fromValue(threadMap));
235+}
236+
237 Thread ManagerDBus::threadForProperties(const QString &accountId,
238 EventType type,
239 const QVariantMap &properties,
240
241=== modified file 'src/managerdbus_p.h'
242--- src/managerdbus_p.h 2017-02-21 15:16:27 +0000
243+++ src/managerdbus_p.h 2017-02-21 15:16:27 +0000
244@@ -56,6 +56,7 @@
245 bool removeEvents(const Events &events);
246 Thread getSingleThread(EventType type, const QString &accountId, const QString &threadId, const QVariantMap &properties = QVariantMap());
247 Event getSingleEvent(EventType type, const QString &accountId, const QString &threadId, const QString &eventId);
248+ void markThreadsAsRead(const History::Threads &threads);
249
250 Q_SIGNALS:
251 // signals that will be triggered after processing bus signals
252
253=== modified file 'src/plugin.h'
254--- src/plugin.h 2017-02-21 15:16:27 +0000
255+++ src/plugin.h 2017-02-21 15:16:27 +0000
256@@ -79,6 +79,7 @@
257 virtual bool updateRoomParticipantsRoles(const QString &accountId, const QString &threadId, History::EventType type, const QVariantMap &participantsRoles) { return false; };
258 virtual bool updateRoomInfo(const QString &accountId, const QString &threadId, EventType type, const QVariantMap &properties, const QStringList &invalidated = QStringList()) { return false; };
259 virtual bool removeThread(const QVariantMap &thread) { return false; }
260+ virtual QVariantMap markThreadAsRead(const QVariantMap &thread) { return QVariantMap(); }
261
262 virtual EventWriteResult writeTextEvent(const QVariantMap &event) { return EventWriteError; }
263 virtual bool removeTextEvent(const QVariantMap &event) { return false; }

Subscribers

People subscribed via source and target branches

to all changes: