Merge lp:~libqtelegram-team/telegram-app/app-dev-cpp-push-helper into lp:telegram-app/app-dev
- app-dev-cpp-push-helper
- Merge into telegram-app-dev
Status: | Merged | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Approved by: | Giulio Collura | ||||||||||||
Approved revision: | 278 | ||||||||||||
Merged at revision: | 269 | ||||||||||||
Proposed branch: | lp:~libqtelegram-team/telegram-app/app-dev-cpp-push-helper | ||||||||||||
Merge into: | lp:telegram-app/app-dev | ||||||||||||
Diff against target: |
700 lines (+594/-11) 12 files modified
.bzrignore (+1/-0) CMakeLists.txt (+38/-1) config.h.in (+0/-1) push.cpp (+25/-0) push.json (+1/-1) pushclient.cpp (+113/-0) pushclient.h (+76/-0) pushhelper.cpp (+290/-0) pushhelper.h (+41/-0) scripts/pushlog.sh (+3/-0) src.moved/_sctelegram.ini (+0/-8) telegram.qml (+6/-0) |
||||||||||||
To merge this branch: | bzr merge lp:~libqtelegram-team/telegram-app/app-dev-cpp-push-helper | ||||||||||||
Related bugs: |
|
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Giulio Collura | Approve | ||
Roberto Mier Escandon (community) | Needs Fixing | ||
Review via email: mp+250608@code.launchpad.net |
Commit message
Description of the change
Rewrote push helper in C++.
Add 'grouping' of notifications (no counter in notification of grouped messages yet).
Add clearing counter / notifications when logging out.
Requires lib: lp:~libqtelegram-team/libqtelegram/dev-cpp-push-helper
https:/
Tested:
- reading msg on PC and opening Tg clears counter/
- opening Tg and reading msg on PC clears counter/
- opening chat clears counter
- most of incoming push notification types listed in pushhelper.cpp
Michał Karnicki (karni) wrote : | # |
Roberto Mier Escandon (rmescandon) wrote : | # |
helper should manage CHAT_MESSAGE_NOTEXT push received message from telegram servers (see https:/
Giulio Collura (gcollura) wrote : | # |
As discussed extensively on IRC, this is working and looking fine. Thanks karni!
Preview Diff
1 | === modified file '.bzrignore' | |||
2 | --- .bzrignore 2015-02-23 15:00:09 +0000 | |||
3 | +++ .bzrignore 2015-02-24 16:42:37 +0000 | |||
4 | @@ -2,6 +2,7 @@ | |||
5 | 2 | click | 2 | click |
6 | 3 | *.click | 3 | *.click |
7 | 4 | library | 4 | library |
8 | 5 | push | ||
9 | 5 | push.py | 6 | push.py |
10 | 6 | config.h | 7 | config.h |
11 | 7 | manifest.json | 8 | manifest.json |
12 | 8 | 9 | ||
13 | === modified file 'CMakeLists.txt' | |||
14 | --- CMakeLists.txt 2015-02-03 19:03:00 +0000 | |||
15 | +++ CMakeLists.txt 2015-02-24 16:42:37 +0000 | |||
16 | @@ -190,9 +190,35 @@ | |||
17 | 190 | QML_JS_TARGET ALL SOURCES ${QML_JS_FILES} | 190 | QML_JS_TARGET ALL SOURCES ${QML_JS_FILES} |
18 | 191 | ) | 191 | ) |
19 | 192 | 192 | ||
20 | 193 | add_custom_target( | ||
21 | 194 | "_project_files" ALL SOURCES | ||
22 | 195 | |||
23 | 196 | "manifest.json.in" | ||
24 | 197 | "apparmor-telegram.json" | ||
25 | 198 | "push.json" | ||
26 | 199 | "apparmor-push.json" | ||
27 | 200 | "content-hub.json" | ||
28 | 201 | "telegram.desktop.in.in" | ||
29 | 202 | |||
30 | 203 | "config.h.in" | ||
31 | 204 | "push.cpp" | ||
32 | 205 | "pushhelper.h" | ||
33 | 206 | "pushhelper.cpp" | ||
34 | 207 | "pushclient.h" | ||
35 | 208 | "pushclient.cpp" | ||
36 | 209 | |||
37 | 210 | "push.py" | ||
38 | 211 | "countries.py" | ||
39 | 212 | |||
40 | 213 | "HACKING.md" | ||
41 | 214 | "README.md" | ||
42 | 215 | "README.translations" | ||
43 | 216 | "LICENSE" | ||
44 | 217 | ) | ||
45 | 218 | |||
46 | 193 | configure_file( | 219 | configure_file( |
47 | 194 | config.h.in | 220 | config.h.in |
49 | 195 | ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONL | 221 | ${CMAKE_CURRENT_BINARY_DIR}/config.h @ONLY |
50 | 196 | ) | 222 | ) |
51 | 197 | 223 | ||
52 | 198 | set(telegram_app_SRCS | 224 | set(telegram_app_SRCS |
53 | @@ -218,3 +244,14 @@ | |||
54 | 218 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} | 244 | RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} |
55 | 219 | ) | 245 | ) |
56 | 220 | 246 | ||
57 | 247 | add_executable(push | ||
58 | 248 | push.cpp | ||
59 | 249 | pushhelper.cpp | ||
60 | 250 | pushclient.cpp | ||
61 | 251 | ) | ||
62 | 252 | qt5_use_modules(push | ||
63 | 253 | Core | ||
64 | 254 | DBus | ||
65 | 255 | ) | ||
66 | 256 | install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/push | ||
67 | 257 | DESTINATION ${CMAKE_INSTALL_BINDIR}) | ||
68 | 221 | 258 | ||
69 | === modified file 'config.h.in' | |||
70 | --- config.h.in 2014-11-03 09:57:18 +0000 | |||
71 | +++ config.h.in 2015-02-24 16:42:37 +0000 | |||
72 | @@ -1,2 +1,1 @@ | |||
73 | 1 | |||
74 | 2 | #define TELEGRAM_VERSION "@APP_VERSION@" | 1 | #define TELEGRAM_VERSION "@APP_VERSION@" |
75 | 3 | 2 | ||
76 | === added file 'push.cpp' | |||
77 | --- push.cpp 1970-01-01 00:00:00 +0000 | |||
78 | +++ push.cpp 2015-02-24 16:42:37 +0000 | |||
79 | @@ -0,0 +1,25 @@ | |||
80 | 1 | #include <QCoreApplication> | ||
81 | 2 | #include <QStringList> | ||
82 | 3 | #include <QTimer> | ||
83 | 4 | |||
84 | 5 | #include "pushhelper.h" | ||
85 | 6 | |||
86 | 7 | int main(int argc, char *argv[]) { | ||
87 | 8 | if (argc != 3) { | ||
88 | 9 | qFatal("Usage: %s infile outfile", argv[0]); | ||
89 | 10 | } | ||
90 | 11 | |||
91 | 12 | QCoreApplication app(argc, argv); | ||
92 | 13 | QStringList args = app.arguments(); | ||
93 | 14 | |||
94 | 15 | PushHelper pushHelper("com.ubuntu.telegram_telegram", | ||
95 | 16 | QString(args.at(1)), QString(args.at(2)), &app); | ||
96 | 17 | |||
97 | 18 | // QObject::connect(&pushHelper, SIGNAL(done()), &app, SLOT(quit())); | ||
98 | 19 | pushHelper.process(); | ||
99 | 20 | |||
100 | 21 | // TODO check why I need this and the connect above doesn't work. | ||
101 | 22 | QTimer::singleShot(500, &app, SLOT(quit())); | ||
102 | 23 | |||
103 | 24 | return app.exec(); | ||
104 | 25 | } | ||
105 | 0 | 26 | ||
106 | === modified file 'push.json' | |||
107 | --- push.json 2014-09-02 21:51:24 +0000 | |||
108 | +++ push.json 2015-02-24 16:42:37 +0000 | |||
109 | @@ -1,4 +1,4 @@ | |||
110 | 1 | { | 1 | { |
112 | 2 | "exec": "push.py", | 2 | "exec": "push", |
113 | 3 | "app_id": "com.ubuntu.telegram_telegram" | 3 | "app_id": "com.ubuntu.telegram_telegram" |
114 | 4 | } | 4 | } |
115 | 5 | 5 | ||
116 | === added file 'pushclient.cpp' | |||
117 | --- pushclient.cpp 1970-01-01 00:00:00 +0000 | |||
118 | +++ pushclient.cpp 2015-02-24 16:42:37 +0000 | |||
119 | @@ -0,0 +1,113 @@ | |||
120 | 1 | /* | ||
121 | 2 | Copyright 2014 Canonical Ltd. | ||
122 | 3 | |||
123 | 4 | This program is free software: you can redistribute it and/or modify | ||
124 | 5 | it under the terms of the GNU Lesser General Public License, version 3 | ||
125 | 6 | as published by the Free Software Foundation. | ||
126 | 7 | |||
127 | 8 | This program is distributed in the hope that it will be useful, but | ||
128 | 9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
129 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
130 | 11 | GNU Lesser General Public License for more details. | ||
131 | 12 | |||
132 | 13 | You should have received a copy of the GNU Lesser General Public | ||
133 | 14 | License along with this program. If not, see | ||
134 | 15 | <http://www.gnu.org/licenses/>. | ||
135 | 16 | */ | ||
136 | 17 | |||
137 | 18 | #include "pushclient.h" | ||
138 | 19 | #include <QtDBus/QDBusConnection> | ||
139 | 20 | #include <QtDBus/QDBusMessage> | ||
140 | 21 | #include <QtDBus/QDBusPendingCall> | ||
141 | 22 | #include <QtDBus/QDBusPendingReply> | ||
142 | 23 | #include <QTimer> | ||
143 | 24 | |||
144 | 25 | #define PUSH_SERVICE "com.ubuntu.PushNotifications" | ||
145 | 26 | #define POSTAL_SERVICE "com.ubuntu.Postal" | ||
146 | 27 | #define PUSH_PATH "/com/ubuntu/PushNotifications" | ||
147 | 28 | #define POSTAL_PATH "/com/ubuntu/Postal" | ||
148 | 29 | #define PUSH_IFACE "com.ubuntu.PushNotifications" | ||
149 | 30 | #define POSTAL_IFACE "com.ubuntu.Postal" | ||
150 | 31 | |||
151 | 32 | PushClient::PushClient(QObject *parent) : QObject(parent) { | ||
152 | 33 | } | ||
153 | 34 | |||
154 | 35 | void PushClient::registerApp(const QString &appId) { | ||
155 | 36 | pkgname = appId.split("_").at(0); | ||
156 | 37 | pkgname = pkgname.replace(".","_2e").replace("-","_2d"); | ||
157 | 38 | Q_EMIT appIdChanged(appId); | ||
158 | 39 | } | ||
159 | 40 | |||
160 | 41 | QString PushClient::getAppId() { | ||
161 | 42 | return appId; | ||
162 | 43 | } | ||
163 | 44 | |||
164 | 45 | QString PushClient::getToken() { | ||
165 | 46 | return token; | ||
166 | 47 | } | ||
167 | 48 | |||
168 | 49 | void PushClient::emitError() { | ||
169 | 50 | Q_EMIT error(status); | ||
170 | 51 | } | ||
171 | 52 | |||
172 | 53 | void PushClient::clearPersistent(const QStringList &tags) { | ||
173 | 54 | QDBusConnection bus = QDBusConnection::sessionBus(); | ||
174 | 55 | QString path(POSTAL_PATH); | ||
175 | 56 | path += "/" + pkgname; | ||
176 | 57 | QDBusMessage message = QDBusMessage::createMethodCall( | ||
177 | 58 | POSTAL_SERVICE, path, POSTAL_IFACE, "ClearPersistent"); | ||
178 | 59 | message << this->appId; | ||
179 | 60 | for (int i = 0; i < tags.size(); ++i) { | ||
180 | 61 | message << tags.at(i); | ||
181 | 62 | } | ||
182 | 63 | bus.send(message); | ||
183 | 64 | |||
184 | 65 | QDBusPendingCall pcall = bus.asyncCall(message); | ||
185 | 66 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); | ||
186 | 67 | connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), | ||
187 | 68 | this, SLOT(clearPersistentFinished(QDBusPendingCallWatcher*))); | ||
188 | 69 | } | ||
189 | 70 | |||
190 | 71 | void PushClient::clearPersistentFinished(QDBusPendingCallWatcher *watcher) { | ||
191 | 72 | QDBusPendingReply<void> reply = *watcher; | ||
192 | 73 | |||
193 | 74 | if (reply.isError()) { | ||
194 | 75 | Q_EMIT error(reply.error().message()); | ||
195 | 76 | } else { | ||
196 | 77 | Q_EMIT persistentCleared(); | ||
197 | 78 | } | ||
198 | 79 | watcher->deleteLater(); | ||
199 | 80 | } | ||
200 | 81 | |||
201 | 82 | void PushClient::setCount(int count) { | ||
202 | 83 | QDBusConnection bus = QDBusConnection::sessionBus(); | ||
203 | 84 | QString path(POSTAL_PATH); | ||
204 | 85 | bool visible = count != 0; | ||
205 | 86 | counter = count; | ||
206 | 87 | path += "/" + pkgname; | ||
207 | 88 | QDBusMessage message = QDBusMessage::createMethodCall(POSTAL_SERVICE, path, POSTAL_IFACE, "setCounter"); | ||
208 | 89 | message << this->appId << count << visible; | ||
209 | 90 | QDBusPendingCall pcall = bus.asyncCall(message); | ||
210 | 91 | QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(pcall, this); | ||
211 | 92 | connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), | ||
212 | 93 | this, SLOT(setCounterFinished(QDBusPendingCallWatcher*))); | ||
213 | 94 | } | ||
214 | 95 | |||
215 | 96 | void PushClient::setCounterFinished(QDBusPendingCallWatcher *watcher) { | ||
216 | 97 | QDBusPendingReply<void> reply = *watcher; | ||
217 | 98 | if (reply.isError()) { | ||
218 | 99 | Q_EMIT error(reply.error().message()); | ||
219 | 100 | } | ||
220 | 101 | else { | ||
221 | 102 | Q_EMIT countChanged(counter); | ||
222 | 103 | } | ||
223 | 104 | watcher->deleteLater(); | ||
224 | 105 | } | ||
225 | 106 | |||
226 | 107 | int PushClient::getCount() { | ||
227 | 108 | return counter; | ||
228 | 109 | } | ||
229 | 110 | |||
230 | 111 | void PushClient::setAppId(const QString &appId) { | ||
231 | 112 | this->appId = appId; | ||
232 | 113 | } | ||
233 | 0 | 114 | ||
234 | === added file 'pushclient.h' | |||
235 | --- pushclient.h 1970-01-01 00:00:00 +0000 | |||
236 | +++ pushclient.h 2015-02-24 16:42:37 +0000 | |||
237 | @@ -0,0 +1,76 @@ | |||
238 | 1 | /* | ||
239 | 2 | Copyright 2014 Canonical Ltd. | ||
240 | 3 | |||
241 | 4 | This program is free software: you can redistribute it and/or modify | ||
242 | 5 | it under the terms of the GNU Lesser General Public License, version 3 | ||
243 | 6 | as published by the Free Software Foundation. | ||
244 | 7 | |||
245 | 8 | This program is distributed in the hope that it will be useful, but | ||
246 | 9 | WITHOUT ANY WARRANTY; without even the implied warranty of | ||
247 | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
248 | 11 | GNU Lesser General Public License for more details. | ||
249 | 12 | |||
250 | 13 | You should have received a copy of the GNU Lesser General Public | ||
251 | 14 | License along with this program. If not, see | ||
252 | 15 | <http://www.gnu.org/licenses/>. | ||
253 | 16 | */ | ||
254 | 17 | |||
255 | 18 | #ifndef PUSHCLIENT_H | ||
256 | 19 | #define PUSHCLIENT_H | ||
257 | 20 | |||
258 | 21 | #include <QObject> | ||
259 | 22 | #include <QString> | ||
260 | 23 | #include <QStringList> | ||
261 | 24 | |||
262 | 25 | class QDBusPendingCallWatcher; | ||
263 | 26 | |||
264 | 27 | class PushClient : public QObject { | ||
265 | 28 | Q_OBJECT | ||
266 | 29 | |||
267 | 30 | public: | ||
268 | 31 | explicit PushClient(QObject *parent = 0); | ||
269 | 32 | |||
270 | 33 | QString getAppId(); | ||
271 | 34 | void setAppId(const QString &appId); | ||
272 | 35 | QString getToken(); | ||
273 | 36 | QString getStatus() { return this->status; } | ||
274 | 37 | int getCount(); | ||
275 | 38 | void setCount(int count); | ||
276 | 39 | |||
277 | 40 | void registerApp(const QString &appid); | ||
278 | 41 | |||
279 | 42 | Q_PROPERTY(QString appId WRITE setAppId READ getAppId NOTIFY appIdChanged); | ||
280 | 43 | Q_PROPERTY(QString token READ getToken NOTIFY tokenChanged); | ||
281 | 44 | Q_PROPERTY(QStringList notifications NOTIFY notificationsChanged); | ||
282 | 45 | Q_PROPERTY(QString status READ getStatus NOTIFY statusChanged); | ||
283 | 46 | Q_PROPERTY(int count READ getCount WRITE setCount NOTIFY countChanged) | ||
284 | 47 | |||
285 | 48 | signals: | ||
286 | 49 | void appIdChanged(const QString &appId); | ||
287 | 50 | void tokenChanged(const QString &token); | ||
288 | 51 | void statusChanged(const QString &status); | ||
289 | 52 | void countChanged(int count); | ||
290 | 53 | void notificationsChanged(const QStringList ¬ifications); | ||
291 | 54 | void persistentChanged(const QStringList &tags); | ||
292 | 55 | void persistentCleared(); | ||
293 | 56 | |||
294 | 57 | void error(const QString &error); | ||
295 | 58 | |||
296 | 59 | public slots: | ||
297 | 60 | void emitError(); | ||
298 | 61 | void clearPersistent(const QStringList &tags); | ||
299 | 62 | |||
300 | 63 | private slots: | ||
301 | 64 | void setCounterFinished(QDBusPendingCallWatcher *watcher); | ||
302 | 65 | void clearPersistentFinished(QDBusPendingCallWatcher *watcher); | ||
303 | 66 | |||
304 | 67 | private: | ||
305 | 68 | QString appId; | ||
306 | 69 | QString pkgname; | ||
307 | 70 | QString token; | ||
308 | 71 | QString status; | ||
309 | 72 | QStringList notifications; | ||
310 | 73 | int counter; | ||
311 | 74 | }; | ||
312 | 75 | |||
313 | 76 | #endif // PUSHCLIENT_H | ||
314 | 0 | 77 | ||
315 | === added file 'pushhelper.cpp' | |||
316 | --- pushhelper.cpp 1970-01-01 00:00:00 +0000 | |||
317 | +++ pushhelper.cpp 2015-02-24 16:42:37 +0000 | |||
318 | @@ -0,0 +1,290 @@ | |||
319 | 1 | #include <QDebug> | ||
320 | 2 | #include <QFile> | ||
321 | 3 | #include <QJsonDocument> | ||
322 | 4 | #include <QJsonArray> | ||
323 | 5 | #include <QStringList> | ||
324 | 6 | #include <QTextStream> | ||
325 | 7 | |||
326 | 8 | #include "pushhelper.h" | ||
327 | 9 | |||
328 | 10 | PushHelper::PushHelper(QString appId, QString infile, QString outfile, | ||
329 | 11 | QObject *parent) : QObject(parent) { | ||
330 | 12 | connect(&mPushClient, SIGNAL(persistentCleared()), | ||
331 | 13 | this, SLOT(notificationDismissed())); | ||
332 | 14 | |||
333 | 15 | mPushClient.setAppId(appId); | ||
334 | 16 | mPushClient.registerApp(appId); | ||
335 | 17 | mInfile = infile; | ||
336 | 18 | mOutfile = outfile; | ||
337 | 19 | } | ||
338 | 20 | |||
339 | 21 | PushHelper::~PushHelper() { | ||
340 | 22 | } | ||
341 | 23 | |||
342 | 24 | void PushHelper::process() { | ||
343 | 25 | QString tag = ""; | ||
344 | 26 | |||
345 | 27 | QJsonObject pushMessage = readPushMessage(mInfile); | ||
346 | 28 | mPostalMessage = pushToPostalMessage(pushMessage, tag); | ||
347 | 29 | if (!tag.isEmpty()) { | ||
348 | 30 | dismissNotification(tag); | ||
349 | 31 | } | ||
350 | 32 | } | ||
351 | 33 | |||
352 | 34 | void PushHelper::notificationDismissed() { | ||
353 | 35 | writePostalMessage(mPostalMessage, mOutfile); | ||
354 | 36 | Q_EMIT done(); | ||
355 | 37 | } | ||
356 | 38 | |||
357 | 39 | QJsonObject PushHelper::readPushMessage(const QString &filename) { | ||
358 | 40 | QFile file(filename); | ||
359 | 41 | file.open(QIODevice::ReadOnly | QIODevice::Text); | ||
360 | 42 | |||
361 | 43 | QString val = file.readAll(); | ||
362 | 44 | file.close(); | ||
363 | 45 | return QJsonDocument::fromJson(val.toUtf8()).object(); | ||
364 | 46 | } | ||
365 | 47 | |||
366 | 48 | void PushHelper::writePostalMessage(const QJsonObject &postalMessage, const QString &filename) { | ||
367 | 49 | QFile out; | ||
368 | 50 | out.setFileName(filename); | ||
369 | 51 | out.open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate); | ||
370 | 52 | |||
371 | 53 | QTextStream(&out) << QJsonDocument(postalMessage).toJson(); | ||
372 | 54 | out.close(); | ||
373 | 55 | } | ||
374 | 56 | |||
375 | 57 | QJsonObject PushHelper::pushToPostalMessage(const QJsonObject &push, QString &tag) { | ||
376 | 58 | QString summary = ""; | ||
377 | 59 | QString body = ""; | ||
378 | 60 | qint32 count = 0; | ||
379 | 61 | |||
380 | 62 | QJsonObject message = push["message"].toObject(); | ||
381 | 63 | QJsonObject custom = message["custom"].toObject(); | ||
382 | 64 | |||
383 | 65 | QString key = ""; | ||
384 | 66 | if (message.keys().contains("loc_key")) { | ||
385 | 67 | key = message["loc_key"].toString(); | ||
386 | 68 | } | ||
387 | 69 | QJsonArray args; | ||
388 | 70 | if (message.keys().contains("loc_args")) { | ||
389 | 71 | args = message["loc_args"].toArray(); | ||
390 | 72 | } | ||
391 | 73 | |||
392 | 74 | QString chatId = "0"; // More useful as string in this context. | ||
393 | 75 | if (custom.keys().contains("from_id")) { | ||
394 | 76 | chatId = custom["from_id"].toString(); | ||
395 | 77 | } | ||
396 | 78 | if (custom.keys().contains("chat_id")) { | ||
397 | 79 | chatId = custom["chat_id"].toString(); | ||
398 | 80 | } | ||
399 | 81 | |||
400 | 82 | QString tg = QString("Telegram"); | ||
401 | 83 | summary = args[0].toString(); | ||
402 | 84 | |||
403 | 85 | if (key == "MESSAGE_TEXT") { | ||
404 | 86 | |||
405 | 87 | body = args[1].toString(); | ||
406 | 88 | |||
407 | 89 | } else if (key == "MESSAGE_NOTEXT") { | ||
408 | 90 | |||
409 | 91 | body = "sent you a message"; | ||
410 | 92 | |||
411 | 93 | } else if (key == "MESSAGE_PHOTO") { | ||
412 | 94 | |||
413 | 95 | body = "sent you a photo"; | ||
414 | 96 | |||
415 | 97 | } else if (key == "MESSAGE_VIDEO") { | ||
416 | 98 | |||
417 | 99 | body = "sent you a video"; | ||
418 | 100 | |||
419 | 101 | } else if (key == "MESSAGE_DOC") { | ||
420 | 102 | |||
421 | 103 | body = "sent you a document"; | ||
422 | 104 | |||
423 | 105 | } else if (key == "MESSAGE_AUDIO") { | ||
424 | 106 | |||
425 | 107 | body = "sent you a voice message"; | ||
426 | 108 | |||
427 | 109 | } else if (key == "MESSAGE_CONTACT") { | ||
428 | 110 | |||
429 | 111 | body = "shared a contact with you"; | ||
430 | 112 | |||
431 | 113 | } else if (key == "MESSAGE_GEO") { | ||
432 | 114 | |||
433 | 115 | body = "sent you a map"; | ||
434 | 116 | |||
435 | 117 | } else if (key == "CHAT_MESSAGE_TEXT") { | ||
436 | 118 | |||
437 | 119 | summary = args[1].toString(); | ||
438 | 120 | body = args[0].toString() + ": " + args[2].toString(); | ||
439 | 121 | |||
440 | 122 | } else if (key == "CHAT_MESSAGE_NOTEXT") { | ||
441 | 123 | |||
442 | 124 | summary = args[1].toString(); | ||
443 | 125 | body = args[0].toString() + " sent a message to the group"; | ||
444 | 126 | |||
445 | 127 | } else if (key == "CHAT_MESSAGE_PHOTO") { | ||
446 | 128 | |||
447 | 129 | summary = args[1].toString(); | ||
448 | 130 | body = args[0].toString() + " sent a photo to the group"; | ||
449 | 131 | |||
450 | 132 | } else if (key == "CHAT_MESSAGE_VIDEO") { | ||
451 | 133 | |||
452 | 134 | summary = args[1].toString(); | ||
453 | 135 | body = args[0].toString() + " sent a video to the group"; | ||
454 | 136 | |||
455 | 137 | } else if (key == "CHAT_MESSAGE_DOC") { | ||
456 | 138 | |||
457 | 139 | summary = args[1].toString(); | ||
458 | 140 | body = args[0].toString() + " sent a document to the group"; | ||
459 | 141 | |||
460 | 142 | } else if (key == "CHAT_MESSAGE_AUDIO") { | ||
461 | 143 | |||
462 | 144 | summary = args[1].toString(); | ||
463 | 145 | body = args[0].toString() + " sent a voice message to the group"; | ||
464 | 146 | |||
465 | 147 | } else if (key == "CHAT_MESSAGE_CONTACT") { | ||
466 | 148 | |||
467 | 149 | summary = args[1].toString(); | ||
468 | 150 | body = args[0].toString() + " sent a contact to the group"; | ||
469 | 151 | |||
470 | 152 | } else if (key == "CHAT_MESSAGE_GEO") { | ||
471 | 153 | |||
472 | 154 | summary = args[1].toString(); | ||
473 | 155 | body = args[0].toString() + " sent a map to the group"; | ||
474 | 156 | |||
475 | 157 | } else if (key == "CHAT_CREATED") { | ||
476 | 158 | |||
477 | 159 | summary = args[1].toString(); | ||
478 | 160 | body = args[0].toString() + " invited you to the group"; | ||
479 | 161 | |||
480 | 162 | } else if (key == "CHAT_TITLE_EDITED") { | ||
481 | 163 | |||
482 | 164 | summary = args[1].toString(); | ||
483 | 165 | body = args[0].toString() + " changed group name"; | ||
484 | 166 | |||
485 | 167 | } else if (key == "CHAT_PHOTO_EDITED") { | ||
486 | 168 | |||
487 | 169 | summary = args[1].toString(); | ||
488 | 170 | body = args[0].toString() + " changed group photo"; | ||
489 | 171 | |||
490 | 172 | } else if (key == "CHAT_ADD_MEMBER") { | ||
491 | 173 | |||
492 | 174 | summary = args[1].toString(); | ||
493 | 175 | body = args[0].toString() + " invited " + args[2].toString(); | ||
494 | 176 | |||
495 | 177 | } else if (key == "CHAT_ADD_YOU") { | ||
496 | 178 | |||
497 | 179 | summary = args[1].toString(); | ||
498 | 180 | body = args[0].toString() + " invited you to the group"; | ||
499 | 181 | |||
500 | 182 | } else if (key == "CHAT_DELETE_MEMBER") { | ||
501 | 183 | |||
502 | 184 | summary = args[1].toString(); | ||
503 | 185 | body = args[0].toString() + " kicked " + args[2].toString(); | ||
504 | 186 | |||
505 | 187 | } else if (key == "CHAT_DELETE_YOU") { | ||
506 | 188 | |||
507 | 189 | summary = args[1].toString(); | ||
508 | 190 | body = args[0].toString() + " kicked you from the group"; | ||
509 | 191 | |||
510 | 192 | } else if (key == "CHAT_LEFT") { | ||
511 | 193 | |||
512 | 194 | summary = args[1].toString(); | ||
513 | 195 | body = args[0].toString() + " has left the group"; | ||
514 | 196 | |||
515 | 197 | } else if (key == "CHAT_RETURNED") { | ||
516 | 198 | |||
517 | 199 | summary = args[1].toString(); | ||
518 | 200 | body = args[0].toString() + " has returned to the group"; | ||
519 | 201 | |||
520 | 202 | } else if (key == "GEOCHAT_CHECKIN") { | ||
521 | 203 | |||
522 | 204 | summary = "@ " + args[1].toString(); | ||
523 | 205 | body = args[0].toString() + " has checked-in"; | ||
524 | 206 | |||
525 | 207 | } else if (key == "CONTACT_JOINED") { | ||
526 | 208 | |||
527 | 209 | summary = tg; | ||
528 | 210 | body = args[0].toString() + " joined Telegram!"; | ||
529 | 211 | |||
530 | 212 | } else if (key == "AUTH_UNKNOWN") { | ||
531 | 213 | |||
532 | 214 | summary = args[0].toString(); | ||
533 | 215 | body = "New login from unrecognized device"; | ||
534 | 216 | |||
535 | 217 | } else if (key == "AUTH_REGION") { | ||
536 | 218 | |||
537 | 219 | summary = args[0].toString() + " @ " + args[1].toString(); | ||
538 | 220 | body = "New login from unrecognized device"; | ||
539 | 221 | |||
540 | 222 | } else if (key == "CONTACT_PHOTO") { | ||
541 | 223 | |||
542 | 224 | body = "updated profile photo"; | ||
543 | 225 | |||
544 | 226 | } else if (key == "ENCRYPTION_REQUEST") { | ||
545 | 227 | |||
546 | 228 | summary = tg; | ||
547 | 229 | body = "You have a new message"; | ||
548 | 230 | |||
549 | 231 | } else if (key == "ENCRYPTION_ACCEPT") { | ||
550 | 232 | |||
551 | 233 | summary = tg; | ||
552 | 234 | body = "You have a new message"; | ||
553 | 235 | |||
554 | 236 | } else if (key == "ENCRYPTED_MESSAGE") { | ||
555 | 237 | |||
556 | 238 | summary = tg; | ||
557 | 239 | body = "You have a new message"; | ||
558 | 240 | |||
559 | 241 | } else { | ||
560 | 242 | qDebug() << "Unhandled push type: " << key; | ||
561 | 243 | return QJsonObject(); | ||
562 | 244 | } | ||
563 | 245 | |||
564 | 246 | QJsonArray actions = QJsonArray(); | ||
565 | 247 | QString actionUri = QString("telegram://chat/%1").arg(chatId); | ||
566 | 248 | actions.append(actionUri); | ||
567 | 249 | |||
568 | 250 | if (message.keys().contains("badge")) { | ||
569 | 251 | count = message["badge"].toInt(); | ||
570 | 252 | } else if (push.keys().contains("notification")) { | ||
571 | 253 | // Legacy. Notification section is only used to retrieve the unread count. | ||
572 | 254 | count = push["notification"] | ||
573 | 255 | .toObject()["emblem-counter"] | ||
574 | 256 | .toObject()["count"] | ||
575 | 257 | .toInt(); | ||
576 | 258 | } | ||
577 | 259 | |||
578 | 260 | tag = chatId; | ||
579 | 261 | |||
580 | 262 | QJsonObject card; | ||
581 | 263 | card["summary"] = summary; | ||
582 | 264 | card["body"] = body; | ||
583 | 265 | card["actions"] = actions; | ||
584 | 266 | card["popup"] = true; // TODO make setting | ||
585 | 267 | card["persist"] = true; // TODO make setting | ||
586 | 268 | |||
587 | 269 | QJsonObject emblem; | ||
588 | 270 | emblem["count"] = count; | ||
589 | 271 | emblem["visible"] = count > 0; | ||
590 | 272 | |||
591 | 273 | QJsonObject notification; | ||
592 | 274 | notification["tag"] = tag; | ||
593 | 275 | notification["card"] = card; | ||
594 | 276 | notification["emblem-counter"] = emblem; | ||
595 | 277 | notification["sound"] = true; // TODO make setting | ||
596 | 278 | notification["vibrate"] = true; // TODO make setting | ||
597 | 279 | |||
598 | 280 | QJsonObject postalMessage = QJsonObject(); | ||
599 | 281 | postalMessage["notification"] = notification; | ||
600 | 282 | |||
601 | 283 | return postalMessage; | ||
602 | 284 | } | ||
603 | 285 | |||
604 | 286 | void PushHelper::dismissNotification(const QString &tag) { | ||
605 | 287 | QStringList tags; | ||
606 | 288 | tags << tag; | ||
607 | 289 | mPushClient.clearPersistent(tags); | ||
608 | 290 | } | ||
609 | 0 | 291 | ||
610 | === added file 'pushhelper.h' | |||
611 | --- pushhelper.h 1970-01-01 00:00:00 +0000 | |||
612 | +++ pushhelper.h 2015-02-24 16:42:37 +0000 | |||
613 | @@ -0,0 +1,41 @@ | |||
614 | 1 | #ifndef PUSH_HELPER_H | ||
615 | 2 | #define PUSH_HELPER_H | ||
616 | 3 | |||
617 | 4 | #include <QObject> | ||
618 | 5 | #include <QString> | ||
619 | 6 | #include <QJsonObject> | ||
620 | 7 | |||
621 | 8 | #include "pushclient.h" | ||
622 | 9 | |||
623 | 10 | /** | ||
624 | 11 | * See: https://core.telegram.org/api/push-updates | ||
625 | 12 | */ | ||
626 | 13 | class PushHelper : public QObject { | ||
627 | 14 | Q_OBJECT | ||
628 | 15 | |||
629 | 16 | public: | ||
630 | 17 | PushHelper(QString appId, QString infile, QString outfile, QObject *parent = 0); | ||
631 | 18 | ~PushHelper(); | ||
632 | 19 | void process(); | ||
633 | 20 | |||
634 | 21 | Q_SIGNALS: | ||
635 | 22 | void done(); | ||
636 | 23 | |||
637 | 24 | public Q_SLOTS: | ||
638 | 25 | void notificationDismissed(); | ||
639 | 26 | |||
640 | 27 | protected: | ||
641 | 28 | QJsonObject readPushMessage(const QString &filename); | ||
642 | 29 | void writePostalMessage(const QJsonObject &postalMessage, const QString &filename); | ||
643 | 30 | QJsonObject pushToPostalMessage(const QJsonObject &push, QString &tag); | ||
644 | 31 | void dismissNotification(const QString &tag); | ||
645 | 32 | |||
646 | 33 | private: | ||
647 | 34 | PushClient mPushClient; | ||
648 | 35 | QString mInfile; | ||
649 | 36 | QString mOutfile; | ||
650 | 37 | |||
651 | 38 | QJsonObject mPostalMessage; | ||
652 | 39 | }; | ||
653 | 40 | |||
654 | 41 | #endif | ||
655 | 0 | 42 | ||
656 | === added file 'scripts/pushlog.sh' | |||
657 | --- scripts/pushlog.sh 1970-01-01 00:00:00 +0000 | |||
658 | +++ scripts/pushlog.sh 2015-02-24 16:42:37 +0000 | |||
659 | @@ -0,0 +1,3 @@ | |||
660 | 1 | #!/bin/bash | ||
661 | 2 | |||
662 | 3 | adb shell "tail -f /home/phablet/.cache/upstart/ubuntu-push-client.log" | ||
663 | 0 | 4 | ||
664 | === removed directory 'src.moved' | |||
665 | === removed file 'src.moved/_sctelegram.ini' | |||
666 | --- src.moved/_sctelegram.ini 2014-11-21 19:07:32 +0000 | |||
667 | +++ src.moved/_sctelegram.ini 1970-01-01 00:00:00 +0000 | |||
668 | @@ -1,8 +0,0 @@ | |||
669 | 1 | [ScopeConfig] | ||
670 | 2 | DisplayName=Telegram | ||
671 | 3 | Description=This is a Telegram scope | ||
672 | 4 | Author=Victor Palau | ||
673 | 5 | Art=contacts.Art | ||
674 | 6 | Icon=./tasks.png | ||
675 | 7 | SearchHint=search for a message | ||
676 | 8 | HotKey=tasks.HotKey | ||
677 | 9 | 0 | ||
678 | === modified file 'telegram.qml' | |||
679 | --- telegram.qml 2015-02-23 19:56:40 +0000 | |||
680 | +++ telegram.qml 2015-02-24 16:42:37 +0000 | |||
681 | @@ -573,6 +573,9 @@ | |||
682 | 573 | showIntro = false; | 573 | showIntro = false; |
683 | 574 | } | 574 | } |
684 | 575 | 575 | ||
685 | 576 | pushClient.count = 0; | ||
686 | 577 | pushClient.clearPersistent([]); | ||
687 | 578 | |||
688 | 576 | logoutResetSession(showIntro); | 579 | logoutResetSession(showIntro); |
689 | 577 | logoutResetUI(showIntro); | 580 | logoutResetUI(showIntro); |
690 | 578 | } | 581 | } |
691 | @@ -695,6 +698,9 @@ | |||
692 | 695 | 698 | ||
693 | 696 | onUnreadCountChanged: { | 699 | onUnreadCountChanged: { |
694 | 697 | pushClient.count = unreadCount; | 700 | pushClient.count = unreadCount; |
695 | 701 | if (unreadCount === 0) { | ||
696 | 702 | pushClient.clearPersistent([]); | ||
697 | 703 | } | ||
698 | 698 | } | 704 | } |
699 | 699 | 705 | ||
700 | 700 | // We need to clean-up and streamline our APIs ;) | 706 | // We need to clean-up and streamline our APIs ;) |
Roberto, any idea why I need to use line 101 instead of 97 (which doesn't work)?