Merge lp:~mzanetti/reminders-app/fix-enable-push into lp:reminders-app
- fix-enable-push
- Merge into trunk
Proposed by
Michael Zanetti
Status: | Merged |
---|---|
Approved by: | Riccardo Padovani |
Approved revision: | 459 |
Merged at revision: | 460 |
Proposed branch: | lp:~mzanetti/reminders-app/fix-enable-push |
Merge into: | lp:reminders-app |
Diff against target: |
616 lines (+175/-106) 13 files modified
src/account-plugin/qml/evernote/Main.qml.in (+2/-2) src/app/preferences.cpp (+16/-0) src/app/preferences.h (+3/-0) src/app/qml/reminders.qml (+33/-15) src/libqtevernote/jobs/fetchusernamejob.cpp (+2/-4) src/libqtevernote/jobs/fetchusernamejob.h (+2/-2) src/libqtevernote/notesstore.cpp (+59/-40) src/libqtevernote/notesstore.h (+3/-1) src/libqtevernote/userstore.cpp (+17/-9) src/libqtevernote/userstore.h (+8/-5) src/push-helper/core.cpp (+28/-26) src/push-helper/core.h (+1/-2) src/push-helper/main.cpp (+1/-0) |
To merge this branch: | bzr merge lp:~mzanetti/reminders-app/fix-enable-push |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Riccardo Padovani | Approve | ||
Review via email: mp+262541@code.launchpad.net |
Commit message
Fix the remaining issues in the push notification integration and enable it.
Description of the change
To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
review:
Needs Fixing
(continuous-integration)
- 457. By Michael Zanetti
-
drop unused included
- 458. By Michael Zanetti
-
drop unused method declaration
- 459. By Michael Zanetti
-
only try to register push on remote users
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote : | # |
PASSED: Continuous integration, rev:459
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
review:
Approve
(continuous-integration)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'src/account-plugin/qml/evernote/Main.qml.in' | |||
2 | --- src/account-plugin/qml/evernote/Main.qml.in 2015-02-20 21:18:01 +0000 | |||
3 | +++ src/account-plugin/qml/evernote/Main.qml.in 2015-06-22 08:14:09 +0000 | |||
4 | @@ -24,7 +24,7 @@ | |||
5 | 24 | creationComponent: OAuth { | 24 | creationComponent: OAuth { |
6 | 25 | Connections { | 25 | Connections { |
7 | 26 | target: UserStore | 26 | target: UserStore |
9 | 27 | onUsernameChanged: saveUsername() | 27 | onUserChanged: saveUsername() |
10 | 28 | } | 28 | } |
11 | 29 | 29 | ||
12 | 30 | function completeCreation(reply) { | 30 | function completeCreation(reply) { |
13 | @@ -37,7 +37,7 @@ | |||
14 | 37 | } | 37 | } |
15 | 38 | 38 | ||
16 | 39 | function saveUsername() { | 39 | function saveUsername() { |
18 | 40 | account.updateDisplayName(UserStore.username) | 40 | account.updateDisplayName(UserStore.userName) |
19 | 41 | account.synced.connect(finished) | 41 | account.synced.connect(finished) |
20 | 42 | account.sync() | 42 | account.sync() |
21 | 43 | } | 43 | } |
22 | 44 | 44 | ||
23 | === modified file 'src/app/preferences.cpp' | |||
24 | --- src/app/preferences.cpp 2015-02-23 18:00:46 +0000 | |||
25 | +++ src/app/preferences.cpp 2015-06-22 08:14:09 +0000 | |||
26 | @@ -80,3 +80,19 @@ | |||
27 | 80 | m_settings.endGroup(); | 80 | m_settings.endGroup(); |
28 | 81 | return colorName; | 81 | return colorName; |
29 | 82 | } | 82 | } |
30 | 83 | |||
31 | 84 | QString Preferences::tokenForUser(const QString &user) | ||
32 | 85 | { | ||
33 | 86 | QString token; | ||
34 | 87 | m_settings.beginGroup("accounts"); | ||
35 | 88 | token = m_settings.value(user).toString(); | ||
36 | 89 | m_settings.endGroup(); | ||
37 | 90 | return token; | ||
38 | 91 | } | ||
39 | 92 | |||
40 | 93 | void Preferences::setTokenForUser(const QString &user, const QString &token) | ||
41 | 94 | { | ||
42 | 95 | m_settings.beginGroup("accounts"); | ||
43 | 96 | m_settings.setValue(user, token); | ||
44 | 97 | m_settings.endGroup(); | ||
45 | 98 | } | ||
46 | 83 | 99 | ||
47 | === modified file 'src/app/preferences.h' | |||
48 | --- src/app/preferences.h 2015-03-06 00:47:45 +0000 | |||
49 | +++ src/app/preferences.h 2015-06-22 08:14:09 +0000 | |||
50 | @@ -45,6 +45,9 @@ | |||
51 | 45 | 45 | ||
52 | 46 | Q_INVOKABLE QString colorForNotebook(const QString ¬ebookGuid); | 46 | Q_INVOKABLE QString colorForNotebook(const QString ¬ebookGuid); |
53 | 47 | 47 | ||
54 | 48 | Q_INVOKABLE QString tokenForUser(const QString &user); | ||
55 | 49 | Q_INVOKABLE void setTokenForUser(const QString &user, const QString &token); | ||
56 | 50 | |||
57 | 48 | signals: | 51 | signals: |
58 | 49 | void accountNameChanged(); | 52 | void accountNameChanged(); |
59 | 50 | void haveLocalUserChanged(); | 53 | void haveLocalUserChanged(); |
60 | 51 | 54 | ||
61 | === modified file 'src/app/qml/reminders.qml' | |||
62 | --- src/app/qml/reminders.qml 2015-06-12 09:48:22 +0000 | |||
63 | +++ src/app/qml/reminders.qml 2015-06-22 08:14:09 +0000 | |||
64 | @@ -280,9 +280,13 @@ | |||
65 | 280 | } | 280 | } |
66 | 281 | 281 | ||
67 | 282 | function registerPushClient() { | 282 | function registerPushClient() { |
69 | 283 | console.log("Registering push client"); | 283 | console.log("Registering push client", JSON.stringify({ |
70 | 284 | "userId" : "" + UserStore.userId, | ||
71 | 285 | "appId": root.applicationName + "_reminders", | ||
72 | 286 | "token": pushClient.token | ||
73 | 287 | })); | ||
74 | 284 | var req = new XMLHttpRequest(); | 288 | var req = new XMLHttpRequest(); |
76 | 285 | req.open("post", "http://162.213.35.108/register", true); | 289 | req.open("post", "https://push.ubuntu.com/gateway/register", true); |
77 | 286 | req.setRequestHeader("content-type", "application/json"); | 290 | req.setRequestHeader("content-type", "application/json"); |
78 | 287 | req.onreadystatechange = function() {//Call a function when the state changes. | 291 | req.onreadystatechange = function() {//Call a function when the state changes. |
79 | 288 | print("push client register response") | 292 | print("push client register response") |
80 | @@ -295,7 +299,7 @@ | |||
81 | 295 | } | 299 | } |
82 | 296 | } | 300 | } |
83 | 297 | req.send(JSON.stringify({ | 301 | req.send(JSON.stringify({ |
85 | 298 | "userId" : UserStore.username, | 302 | "userId" : "" + UserStore.userId, |
86 | 299 | "appId": root.applicationName + "_reminders", | 303 | "appId": root.applicationName + "_reminders", |
87 | 300 | "token": pushClient.token | 304 | "token": pushClient.token |
88 | 301 | })) | 305 | })) |
89 | @@ -324,18 +328,30 @@ | |||
90 | 324 | onNotificationsChanged: { | 328 | onNotificationsChanged: { |
91 | 325 | print("PushClient notification:", notifications) | 329 | print("PushClient notification:", notifications) |
92 | 326 | var notification = JSON.parse(notifications)["payload"]; | 330 | var notification = JSON.parse(notifications)["payload"]; |
96 | 327 | print("user", notification["userId"]) | 331 | |
97 | 328 | if (notification["userId"] !== UserStore.username) { | 332 | if (notification["userId"] != UserStore.userId) { // Yes, we want type coercion here. |
98 | 329 | console.warn("user mismatch:", notification["userId"], "!=", UserStore.username) | 333 | console.warn("user mismatch:", notification["userId"], "!=", UserStore.userId) |
99 | 330 | return; | 334 | return; |
100 | 331 | } | 335 | } |
101 | 332 | 336 | ||
103 | 333 | if (notification["notebookGUID"] !== undefined) { | 337 | switch(notification["reason"]) { |
104 | 338 | case "update": | ||
105 | 339 | print("Note updated on server:", notification["guid"]) | ||
106 | 340 | if (NotesStore.note(notification["guid"]) === null) { | ||
107 | 341 | NotesStore.refreshNotes(); | ||
108 | 342 | } else { | ||
109 | 343 | NotesStore.refreshNoteContent(notification["guid"]); | ||
110 | 344 | } | ||
111 | 345 | break; | ||
112 | 346 | case "create": | ||
113 | 347 | print("New note appeared on server:", notification["guid"]) | ||
114 | 348 | NotesStore.refreshNotes(); | ||
115 | 349 | break; | ||
116 | 350 | case "notebook_update": | ||
117 | 334 | NotesStore.refreshNotebooks(); | 351 | NotesStore.refreshNotebooks(); |
122 | 335 | NotesStore.refreshNotes(notification["notebookGUID"]); | 352 | break; |
123 | 336 | } | 353 | default: |
124 | 337 | if (notification["noteGUID"] !== undefined) { | 354 | console.warn("Unhandled push notification:", notification["reason"]) |
121 | 338 | NotesStore.refreshNoteContent(notification["noteGUID"]); | ||
125 | 339 | } | 355 | } |
126 | 340 | } | 356 | } |
127 | 341 | 357 | ||
128 | @@ -412,10 +428,12 @@ | |||
129 | 412 | 428 | ||
130 | 413 | Connections { | 429 | Connections { |
131 | 414 | target: UserStore | 430 | target: UserStore |
136 | 415 | onUsernameChanged: { | 431 | onUserChanged: { |
137 | 416 | print("Logged in as user:", UserStore.username); | 432 | print("Logged in as user:", UserStore.userId, UserStore.userName); |
138 | 417 | // Disabling push notifications as we haven't had a chance to properly test that yet | 433 | preferences.setTokenForUser(UserStore.userId, EvernoteConnection.token); |
139 | 418 | //registerPushClient(); | 434 | if (UserStore.userId >= 0) { |
140 | 435 | registerPushClient(); | ||
141 | 436 | } | ||
142 | 419 | } | 437 | } |
143 | 420 | } | 438 | } |
144 | 421 | 439 | ||
145 | 422 | 440 | ||
146 | === modified file 'src/libqtevernote/jobs/fetchusernamejob.cpp' | |||
147 | --- src/libqtevernote/jobs/fetchusernamejob.cpp 2014-09-19 21:31:39 +0000 | |||
148 | +++ src/libqtevernote/jobs/fetchusernamejob.cpp 2015-06-22 08:14:09 +0000 | |||
149 | @@ -42,12 +42,10 @@ | |||
150 | 42 | 42 | ||
151 | 43 | void FetchUsernameJob::startJob() | 43 | void FetchUsernameJob::startJob() |
152 | 44 | { | 44 | { |
156 | 45 | evernote::edam::User user; | 45 | client()->getUser(m_user, token().toStdString()); |
154 | 46 | client()->getUser(user, token().toStdString()); | ||
155 | 47 | m_result = QString::fromStdString(user.username); | ||
157 | 48 | } | 46 | } |
158 | 49 | 47 | ||
159 | 50 | void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) | 48 | void FetchUsernameJob::emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage) |
160 | 51 | { | 49 | { |
162 | 52 | emit jobDone(errorCode, errorMessage, m_result); | 50 | emit jobDone(errorCode, errorMessage, m_user.id, QString::fromStdString(m_user.username)); |
163 | 53 | } | 51 | } |
164 | 54 | 52 | ||
165 | === modified file 'src/libqtevernote/jobs/fetchusernamejob.h' | |||
166 | --- src/libqtevernote/jobs/fetchusernamejob.h 2014-09-19 21:31:39 +0000 | |||
167 | +++ src/libqtevernote/jobs/fetchusernamejob.h 2015-06-22 08:14:09 +0000 | |||
168 | @@ -33,14 +33,14 @@ | |||
169 | 33 | virtual void attachToDuplicate(const EvernoteJob *other) override; | 33 | virtual void attachToDuplicate(const EvernoteJob *other) override; |
170 | 34 | 34 | ||
171 | 35 | signals: | 35 | signals: |
173 | 36 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result); | 36 | void jobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName); |
174 | 37 | 37 | ||
175 | 38 | protected: | 38 | protected: |
176 | 39 | void startJob(); | 39 | void startJob(); |
177 | 40 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); | 40 | void emitJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage); |
178 | 41 | 41 | ||
179 | 42 | private: | 42 | private: |
181 | 43 | QString m_result; | 43 | evernote::edam::User m_user; |
182 | 44 | }; | 44 | }; |
183 | 45 | 45 | ||
184 | 46 | #endif // FETCHUSERNAMEJOB_H | 46 | #endif // FETCHUSERNAMEJOB_H |
185 | 47 | 47 | ||
186 | === modified file 'src/libqtevernote/notesstore.cpp' | |||
187 | --- src/libqtevernote/notesstore.cpp 2015-06-12 09:48:22 +0000 | |||
188 | +++ src/libqtevernote/notesstore.cpp 2015-06-22 08:14:09 +0000 | |||
189 | @@ -61,7 +61,7 @@ | |||
190 | 61 | m_tagsLoading(false) | 61 | m_tagsLoading(false) |
191 | 62 | { | 62 | { |
192 | 63 | qCDebug(dcNotesStore) << "Creating NotesStore instance."; | 63 | qCDebug(dcNotesStore) << "Creating NotesStore instance."; |
194 | 64 | connect(UserStore::instance(), &UserStore::usernameChanged, this, &NotesStore::userStoreConnected); | 64 | connect(UserStore::instance(), &UserStore::userChanged, this, &NotesStore::userStoreConnected); |
195 | 65 | 65 | ||
196 | 66 | qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList"); | 66 | qRegisterMetaType<evernote::edam::NotesMetadataList>("evernote::edam::NotesMetadataList"); |
197 | 67 | qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note"); | 67 | qRegisterMetaType<evernote::edam::Note>("evernote::edam::Note"); |
198 | @@ -98,7 +98,7 @@ | |||
199 | 98 | // We don't accept an empty username. | 98 | // We don't accept an empty username. |
200 | 99 | return; | 99 | return; |
201 | 100 | } | 100 | } |
203 | 101 | if (!UserStore::instance()->username().isEmpty() && username != UserStore::instance()->username()) { | 101 | if (!UserStore::instance()->userName().isEmpty() && username != UserStore::instance()->userName()) { |
204 | 102 | qCWarning(dcNotesStore) << "Logged in to Evernote. Can't change account manually. User EvernoteConnection to log in to another account or log out and change this manually."; | 102 | qCWarning(dcNotesStore) << "Logged in to Evernote. Can't change account manually. User EvernoteConnection to log in to another account or log out and change this manually."; |
205 | 103 | return; | 103 | return; |
206 | 104 | } | 104 | } |
207 | @@ -118,8 +118,9 @@ | |||
208 | 118 | return QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/" + m_username + "/"; | 118 | return QStandardPaths::standardLocations(QStandardPaths::DataLocation).first() + "/" + m_username + "/"; |
209 | 119 | } | 119 | } |
210 | 120 | 120 | ||
212 | 121 | void NotesStore::userStoreConnected(const QString &username) | 121 | void NotesStore::userStoreConnected() |
213 | 122 | { | 122 | { |
214 | 123 | QString username = UserStore::instance()->userName(); | ||
215 | 123 | qCDebug(dcNotesStore) << "User store connected! Using username:" << username; | 124 | qCDebug(dcNotesStore) << "User store connected! Using username:" << username; |
216 | 124 | setUsername(username); | 125 | setUsername(username); |
217 | 125 | 126 | ||
218 | @@ -738,10 +739,12 @@ | |||
219 | 738 | connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone); | 739 | connect(job, &SaveNoteJob::jobDone, this, &NotesStore::saveNoteJobDone); |
220 | 739 | EvernoteConnection::instance()->enqueue(job); | 740 | EvernoteConnection::instance()->enqueue(job); |
221 | 740 | } else { | 741 | } else { |
226 | 741 | qCWarning(dcSync) << "CONFLICT: Note has been changed on server and locally!"; | 742 | qCWarning(dcSync) << "********************************************************"; |
227 | 742 | qCWarning(dcSync) << "local note sequence:" << note->updateSequenceNumber(); | 743 | qCWarning(dcSync) << "* CONFLICT: Note has been changed on server and locally!"; |
228 | 743 | qCWarning(dcSync) << "last synced sequence:" << note->lastSyncedSequenceNumber(); | 744 | qCWarning(dcSync) << "* local note sequence:" << note->updateSequenceNumber(); |
229 | 744 | qCWarning(dcSync) << "remote sequence:" << result.updateSequenceNum; | 745 | qCWarning(dcSync) << "* last synced sequence:" << note->lastSyncedSequenceNumber(); |
230 | 746 | qCWarning(dcSync) << "* remote update sequence:" << result.updateSequenceNum; | ||
231 | 747 | qCWarning(dcSync) << "********************************************************"; | ||
232 | 745 | note->setConflicting(true); | 748 | note->setConflicting(true); |
233 | 746 | changedRoles << RoleConflicting; | 749 | changedRoles << RoleConflicting; |
234 | 747 | 750 | ||
235 | @@ -826,19 +829,7 @@ | |||
236 | 826 | 829 | ||
237 | 827 | if (note->synced()) { | 830 | if (note->synced()) { |
238 | 828 | qCDebug(dcSync) << "Note has been deleted from the server and not changed locally. Deleting local note:" << note->guid(); | 831 | qCDebug(dcSync) << "Note has been deleted from the server and not changed locally. Deleting local note:" << note->guid(); |
252 | 829 | beginRemoveRows(QModelIndex(), idx, idx); | 832 | removeNote(note->guid()); |
240 | 830 | m_notes.removeAt(idx); | ||
241 | 831 | m_notesHash.remove(note->guid()); | ||
242 | 832 | endRemoveRows(); | ||
243 | 833 | emit noteRemoved(note->guid(), note->notebookGuid()); | ||
244 | 834 | emit countChanged(); | ||
245 | 835 | |||
246 | 836 | QSettings settings(m_cacheFile, QSettings::IniFormat); | ||
247 | 837 | settings.beginGroup("notes"); | ||
248 | 838 | settings.remove(note->guid()); | ||
249 | 839 | settings.endGroup(); | ||
250 | 840 | |||
251 | 841 | note->deleteLater(); | ||
253 | 842 | } else { | 833 | } else { |
254 | 843 | qCDebug(dcSync) << "CONFLICT: Note has been deleted from the server but we have unsynced local changes for note:" << note->guid(); | 834 | qCDebug(dcSync) << "CONFLICT: Note has been deleted from the server but we have unsynced local changes for note:" << note->guid(); |
255 | 844 | FetchNoteJob::LoadWhatFlags flags = 0x0; | 835 | FetchNoteJob::LoadWhatFlags flags = 0x0; |
256 | @@ -902,6 +893,12 @@ | |||
257 | 902 | return; | 893 | return; |
258 | 903 | } | 894 | } |
259 | 904 | 895 | ||
260 | 896 | if (result.deleted > 0) { | ||
261 | 897 | qCDebug(dcSync) << "Note has been deleted on server. Deleting locally."; | ||
262 | 898 | removeNote(note->guid()); | ||
263 | 899 | return; | ||
264 | 900 | } | ||
265 | 901 | |||
266 | 905 | if (note->notebookGuid() != QString::fromStdString(result.notebookGuid)) { | 902 | if (note->notebookGuid() != QString::fromStdString(result.notebookGuid)) { |
267 | 906 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); | 903 | note->setNotebookGuid(QString::fromStdString(result.notebookGuid)); |
268 | 907 | roles << RoleGuid; | 904 | roles << RoleGuid; |
269 | @@ -914,6 +911,18 @@ | |||
270 | 914 | note->setUpdated(QDateTime::fromMSecsSinceEpoch(result.updated)); | 911 | note->setUpdated(QDateTime::fromMSecsSinceEpoch(result.updated)); |
271 | 915 | roles << RoleUpdated << RoleUpdatedString; | 912 | roles << RoleUpdated << RoleUpdatedString; |
272 | 916 | } | 913 | } |
273 | 914 | QStringList tagGuids; | ||
274 | 915 | for (quint32 i = 0; i < result.tagGuids.size(); i++) { | ||
275 | 916 | QString tag = QString::fromStdString(result.tagGuids.at(i)); | ||
276 | 917 | if (m_tagsHash.contains(tag)) { | ||
277 | 918 | refreshTags(); | ||
278 | 919 | } | ||
279 | 920 | tagGuids << tag; | ||
280 | 921 | } | ||
281 | 922 | if (note->tagGuids() != tagGuids) { | ||
282 | 923 | note->setTagGuids(tagGuids); | ||
283 | 924 | roles << RoleTagGuids; | ||
284 | 925 | } | ||
285 | 917 | 926 | ||
286 | 918 | // Notes are fetched without resources by default. if we discover one or more resources where we don't have | 927 | // Notes are fetched without resources by default. if we discover one or more resources where we don't have |
287 | 919 | // data in the cache, let's refresh the note again with resource data. | 928 | // data in the cache, let's refresh the note again with resource data. |
288 | @@ -948,11 +957,14 @@ | |||
289 | 948 | if (what == FetchNoteJob::LoadContent) { | 957 | if (what == FetchNoteJob::LoadContent) { |
290 | 949 | note->setEnmlContent(QString::fromStdString(result.content)); | 958 | note->setEnmlContent(QString::fromStdString(result.content)); |
291 | 950 | note->setUpdateSequenceNumber(result.updateSequenceNum); | 959 | note->setUpdateSequenceNumber(result.updateSequenceNum); |
292 | 960 | note->setLastSyncedSequenceNumber(result.updateSequenceNum); | ||
293 | 951 | roles << RoleHtmlContent << RoleEnmlContent << RoleTagline << RolePlaintextContent; | 961 | roles << RoleHtmlContent << RoleEnmlContent << RoleTagline << RolePlaintextContent; |
294 | 952 | } | 962 | } |
295 | 963 | bool syncReminders = false; | ||
296 | 953 | if (note->reminderOrder() != result.attributes.reminderOrder) { | 964 | if (note->reminderOrder() != result.attributes.reminderOrder) { |
297 | 954 | note->setReminderOrder(result.attributes.reminderOrder); | 965 | note->setReminderOrder(result.attributes.reminderOrder); |
298 | 955 | roles << RoleReminder; | 966 | roles << RoleReminder; |
299 | 967 | syncReminders = true; | ||
300 | 956 | } | 968 | } |
301 | 957 | QDateTime reminderTime; | 969 | QDateTime reminderTime; |
302 | 958 | if (result.attributes.reminderTime > 0) { | 970 | if (result.attributes.reminderTime > 0) { |
303 | @@ -961,6 +973,7 @@ | |||
304 | 961 | if (note->reminderTime() != reminderTime) { | 973 | if (note->reminderTime() != reminderTime) { |
305 | 962 | note->setReminderTime(reminderTime); | 974 | note->setReminderTime(reminderTime); |
306 | 963 | roles << RoleReminderTime << RoleReminderTimeString; | 975 | roles << RoleReminderTime << RoleReminderTimeString; |
307 | 976 | syncReminders = true; | ||
308 | 964 | } | 977 | } |
309 | 965 | QDateTime reminderDoneTime; | 978 | QDateTime reminderDoneTime; |
310 | 966 | if (result.attributes.reminderDoneTime > 0) { | 979 | if (result.attributes.reminderDoneTime > 0) { |
311 | @@ -969,6 +982,10 @@ | |||
312 | 969 | if (note->reminderDoneTime() != reminderDoneTime) { | 982 | if (note->reminderDoneTime() != reminderDoneTime) { |
313 | 970 | note->setReminderDoneTime(reminderDoneTime); | 983 | note->setReminderDoneTime(reminderDoneTime); |
314 | 971 | roles << RoleReminderDone << RoleReminderDoneTime; | 984 | roles << RoleReminderDone << RoleReminderDoneTime; |
315 | 985 | syncReminders = true; | ||
316 | 986 | } | ||
317 | 987 | if (syncReminders) { | ||
318 | 988 | m_organizerAdapter->startSync(); | ||
319 | 972 | } | 989 | } |
320 | 973 | 990 | ||
321 | 974 | note->setLoading(false); | 991 | note->setLoading(false); |
322 | @@ -1456,14 +1473,7 @@ | |||
323 | 1456 | int idx = m_notes.indexOf(note); | 1473 | int idx = m_notes.indexOf(note); |
324 | 1457 | 1474 | ||
325 | 1458 | if (note->lastSyncedSequenceNumber() == 0) { | 1475 | if (note->lastSyncedSequenceNumber() == 0) { |
334 | 1459 | emit noteRemoved(note->guid(), note->notebookGuid()); | 1476 | removeNote(guid); |
327 | 1460 | beginRemoveRows(QModelIndex(), idx, idx); | ||
328 | 1461 | m_notes.takeAt(idx); | ||
329 | 1462 | m_notesHash.take(guid); | ||
330 | 1463 | endRemoveRows(); | ||
331 | 1464 | emit countChanged(); | ||
332 | 1465 | deleteFromCacheFile(note); | ||
333 | 1466 | note->deleteLater(); | ||
335 | 1467 | } else { | 1477 | } else { |
336 | 1468 | 1478 | ||
337 | 1469 | qCDebug(dcNotesStore) << "Setting note to deleted:" << note->guid(); | 1479 | qCDebug(dcNotesStore) << "Setting note to deleted:" << note->guid(); |
338 | @@ -1516,18 +1526,7 @@ | |||
339 | 1516 | qCWarning(dcSync) << "Cannot delete note from server:" << errorMessage; | 1526 | qCWarning(dcSync) << "Cannot delete note from server:" << errorMessage; |
340 | 1517 | return; | 1527 | return; |
341 | 1518 | } | 1528 | } |
354 | 1519 | Note *note = m_notesHash.value(guid); | 1529 | removeNote(guid); |
343 | 1520 | int noteIndex = m_notes.indexOf(note); | ||
344 | 1521 | |||
345 | 1522 | emit noteRemoved(guid, note->notebookGuid()); | ||
346 | 1523 | |||
347 | 1524 | beginRemoveRows(QModelIndex(), noteIndex, noteIndex); | ||
348 | 1525 | m_notes.takeAt(noteIndex); | ||
349 | 1526 | m_notesHash.take(guid); | ||
350 | 1527 | endRemoveRows(); | ||
351 | 1528 | emit countChanged(); | ||
352 | 1529 | deleteFromCacheFile(note); | ||
353 | 1530 | note->deleteLater(); | ||
355 | 1531 | } | 1530 | } |
356 | 1532 | 1531 | ||
357 | 1533 | void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid) | 1532 | void NotesStore::expungeNotebookJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &guid) |
358 | @@ -1786,6 +1785,26 @@ | |||
359 | 1786 | return true; | 1785 | return true; |
360 | 1787 | } | 1786 | } |
361 | 1788 | 1787 | ||
362 | 1788 | void NotesStore::removeNote(const QString &guid) | ||
363 | 1789 | { | ||
364 | 1790 | Note *note = m_notesHash.value(guid); | ||
365 | 1791 | int idx = m_notes.indexOf(note); | ||
366 | 1792 | |||
367 | 1793 | emit noteRemoved(note->guid(), note->notebookGuid()); | ||
368 | 1794 | |||
369 | 1795 | beginRemoveRows(QModelIndex(), idx, idx); | ||
370 | 1796 | m_notes.removeAt(idx); | ||
371 | 1797 | m_notesHash.remove(note->guid()); | ||
372 | 1798 | endRemoveRows(); | ||
373 | 1799 | emit countChanged(); | ||
374 | 1800 | |||
375 | 1801 | QSettings settings(m_cacheFile, QSettings::IniFormat); | ||
376 | 1802 | settings.beginGroup("notes"); | ||
377 | 1803 | settings.remove(note->guid()); | ||
378 | 1804 | settings.endGroup(); | ||
379 | 1805 | |||
380 | 1806 | note->deleteLater(); | ||
381 | 1807 | } | ||
382 | 1789 | 1808 | ||
383 | 1790 | void NotesStore::expungeTag(const QString &guid) | 1809 | void NotesStore::expungeTag(const QString &guid) |
384 | 1791 | { | 1810 | { |
385 | 1792 | 1811 | ||
386 | === modified file 'src/libqtevernote/notesstore.h' | |||
387 | --- src/libqtevernote/notesstore.h 2015-06-11 18:55:24 +0000 | |||
388 | +++ src/libqtevernote/notesstore.h 2015-06-22 08:14:09 +0000 | |||
389 | @@ -205,7 +205,7 @@ | |||
390 | 205 | void syncToCacheFile(Tag *tag); | 205 | void syncToCacheFile(Tag *tag); |
391 | 206 | void loadFromCacheFile(); | 206 | void loadFromCacheFile(); |
392 | 207 | 207 | ||
394 | 208 | void userStoreConnected(const QString &username); | 208 | void userStoreConnected(); |
395 | 209 | void emitDataChanged(); | 209 | void emitDataChanged(); |
396 | 210 | void clear(); | 210 | void clear(); |
397 | 211 | 211 | ||
398 | @@ -215,6 +215,8 @@ | |||
399 | 215 | 215 | ||
400 | 216 | bool handleUserError(EvernoteConnection::ErrorCode errorCode); | 216 | bool handleUserError(EvernoteConnection::ErrorCode errorCode); |
401 | 217 | 217 | ||
402 | 218 | void removeNote(const QString &guid); | ||
403 | 219 | |||
404 | 218 | private: | 220 | private: |
405 | 219 | explicit NotesStore(QObject *parent = 0); | 221 | explicit NotesStore(QObject *parent = 0); |
406 | 220 | static NotesStore *s_instance; | 222 | static NotesStore *s_instance; |
407 | 221 | 223 | ||
408 | === modified file 'src/libqtevernote/userstore.cpp' | |||
409 | --- src/libqtevernote/userstore.cpp 2015-03-06 00:47:45 +0000 | |||
410 | +++ src/libqtevernote/userstore.cpp 2015-06-22 08:14:09 +0000 | |||
411 | @@ -42,7 +42,8 @@ | |||
412 | 42 | UserStore* UserStore::s_instance = 0; | 42 | UserStore* UserStore::s_instance = 0; |
413 | 43 | 43 | ||
414 | 44 | UserStore::UserStore(QObject *parent) : | 44 | UserStore::UserStore(QObject *parent) : |
416 | 45 | QObject(parent) | 45 | QObject(parent), |
417 | 46 | m_userId(-1) | ||
418 | 46 | { | 47 | { |
419 | 47 | connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &UserStore::fetchUsername); | 48 | connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &UserStore::fetchUsername); |
420 | 48 | 49 | ||
421 | @@ -57,9 +58,13 @@ | |||
422 | 57 | return s_instance; | 58 | return s_instance; |
423 | 58 | } | 59 | } |
424 | 59 | 60 | ||
428 | 60 | QString UserStore::username() const | 61 | qint32 UserStore::userId() const |
429 | 61 | { | 62 | { |
430 | 62 | return m_username; | 63 | return m_userId; |
431 | 64 | } | ||
432 | 65 | QString UserStore::userName() const | ||
433 | 66 | { | ||
434 | 67 | return m_userName; | ||
435 | 63 | } | 68 | } |
436 | 64 | 69 | ||
437 | 65 | void UserStore::fetchUsername() | 70 | void UserStore::fetchUsername() |
438 | @@ -69,18 +74,21 @@ | |||
439 | 69 | connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone); | 74 | connect(job, &FetchUsernameJob::jobDone, this, &UserStore::fetchUsernameJobDone); |
440 | 70 | EvernoteConnection::instance()->enqueue(job); | 75 | EvernoteConnection::instance()->enqueue(job); |
441 | 71 | } else { | 76 | } else { |
444 | 72 | m_username.clear(); | 77 | m_userId = -1; |
445 | 73 | emit usernameChanged(m_username); | 78 | m_userName.clear(); |
446 | 79 | emit userChanged(); | ||
447 | 74 | } | 80 | } |
448 | 75 | } | 81 | } |
449 | 76 | 82 | ||
451 | 77 | void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result) | 83 | void UserStore::fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName) |
452 | 78 | { | 84 | { |
453 | 79 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { | 85 | if (errorCode != EvernoteConnection::ErrorCodeNoError) { |
454 | 80 | qCWarning(dcConnection) << "Error fetching username:" << errorMessage; | 86 | qCWarning(dcConnection) << "Error fetching username:" << errorMessage; |
455 | 81 | return; | 87 | return; |
456 | 82 | } | 88 | } |
457 | 83 | 89 | ||
460 | 84 | m_username = result; | 90 | qCDebug(dcConnection) << "FetchUsername done. User ID:" << userId << "User name:" << userName; |
461 | 85 | emit usernameChanged(m_username); | 91 | m_userId = userId; |
462 | 92 | m_userName = userName; | ||
463 | 93 | emit userChanged(); | ||
464 | 86 | } | 94 | } |
465 | 87 | 95 | ||
466 | === modified file 'src/libqtevernote/userstore.h' | |||
467 | --- src/libqtevernote/userstore.h 2014-12-08 10:25:48 +0000 | |||
468 | +++ src/libqtevernote/userstore.h 2015-06-22 08:14:09 +0000 | |||
469 | @@ -33,26 +33,29 @@ | |||
470 | 33 | Q_OBJECT | 33 | Q_OBJECT |
471 | 34 | 34 | ||
472 | 35 | // TODO: Once we need more than just the username, turn this into a class User | 35 | // TODO: Once we need more than just the username, turn this into a class User |
474 | 36 | Q_PROPERTY(QString username READ username NOTIFY usernameChanged) | 36 | Q_PROPERTY(qint32 userId READ userId NOTIFY userChanged) |
475 | 37 | Q_PROPERTY(QString userName READ userName NOTIFY userChanged) | ||
476 | 37 | 38 | ||
477 | 38 | public: | 39 | public: |
478 | 39 | static UserStore* instance(); | 40 | static UserStore* instance(); |
479 | 40 | 41 | ||
481 | 41 | QString username() const; | 42 | qint32 userId() const; |
482 | 43 | QString userName() const; | ||
483 | 42 | 44 | ||
484 | 43 | signals: | 45 | signals: |
486 | 44 | void usernameChanged(const QString &username); | 46 | void userChanged(); |
487 | 45 | 47 | ||
488 | 46 | private slots: | 48 | private slots: |
489 | 47 | void fetchUsername(); | 49 | void fetchUsername(); |
490 | 48 | 50 | ||
492 | 49 | void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const QString &result); | 51 | void fetchUsernameJobDone(EvernoteConnection::ErrorCode errorCode, const QString &errorMessage, const int userId, const QString &userName); |
493 | 50 | 52 | ||
494 | 51 | private: | 53 | private: |
495 | 52 | static UserStore* s_instance; | 54 | static UserStore* s_instance; |
496 | 53 | explicit UserStore(QObject *parent = 0); | 55 | explicit UserStore(QObject *parent = 0); |
497 | 54 | 56 | ||
499 | 55 | QString m_username; | 57 | qint32 m_userId; |
500 | 58 | QString m_userName; | ||
501 | 56 | }; | 59 | }; |
502 | 57 | 60 | ||
503 | 58 | #endif // USERSTORE_H | 61 | #endif // USERSTORE_H |
504 | 59 | 62 | ||
505 | === modified file 'src/push-helper/core.cpp' | |||
506 | --- src/push-helper/core.cpp 2014-12-08 10:25:48 +0000 | |||
507 | +++ src/push-helper/core.cpp 2015-06-22 08:14:09 +0000 | |||
508 | @@ -6,33 +6,43 @@ | |||
509 | 6 | 6 | ||
510 | 7 | #include <QDebug> | 7 | #include <QDebug> |
511 | 8 | #include <QOrganizerEvent> | 8 | #include <QOrganizerEvent> |
512 | 9 | #include <QStandardPaths> | ||
513 | 10 | #include <QJsonDocument> | ||
514 | 9 | 11 | ||
515 | 10 | Core::Core(QObject *parent): | 12 | Core::Core(QObject *parent): |
516 | 11 | QObject(parent) | 13 | QObject(parent) |
517 | 12 | { | 14 | { |
518 | 13 | qDebug() << "Core starting up"; | ||
519 | 14 | connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &Core::connectedChanged); | 15 | connect(EvernoteConnection::instance(), &EvernoteConnection::isConnectedChanged, this, &Core::connectedChanged); |
520 | 15 | qDebug() << "EvernoteConnection created"; | ||
521 | 16 | connect(NotesStore::instance(), &NotesStore::loadingChanged, this, &Core::notesLoaded); | 16 | connect(NotesStore::instance(), &NotesStore::loadingChanged, this, &Core::notesLoaded); |
532 | 17 | qDebug() << "notestore created"; | 17 | } |
533 | 18 | // connect(&m_oaSetup, &OnlineAccountsClient::Setup::finished, this, &Core::oaRequestFinished); | 18 | |
534 | 19 | 19 | bool Core::process(const QByteArray &pushNotification) | |
535 | 20 | 20 | { | |
536 | 21 | // m_oaSetup.setApplicationId("com.ubuntu.reminders_reminders"); | 21 | qDebug() << "should process:" << pushNotification; |
537 | 22 | // m_oaSetup.setServiceTypeId("evernote"); | 22 | |
538 | 23 | // m_oaSetup.exec(); | 23 | QJsonParseError error; |
539 | 24 | // qDebug() << "OA request started"; | 24 | QJsonDocument jsonDoc = QJsonDocument::fromJson(pushNotification, &error); |
540 | 25 | 25 | if (error.error != QJsonParseError::NoError) { | |
541 | 26 | EvernoteConnection::instance()->setToken("S=s358:U=39eb980:E=1516e9a3575:C=14a16e90690:P=185:A=canonicalis:V=2:H=737f36850d4943e61ff2fcf7b4c809e2"); | 26 | qDebug() << "Error parsing notification json:" << error.errorString(); |
542 | 27 | return false; | ||
543 | 28 | } | ||
544 | 29 | QVariantMap notification = jsonDoc.toVariant().toMap().value("payload").toMap(); | ||
545 | 30 | |||
546 | 31 | QSettings settings(QStandardPaths::standardLocations(QStandardPaths::ConfigLocation).first() + "/com.ubuntu.reminders/reminders.conf", QSettings::IniFormat); | ||
547 | 32 | settings.beginGroup("accounts"); | ||
548 | 33 | QString token = settings.value(notification.value("userId").toString()).toString(); | ||
549 | 34 | settings.endGroup(); | ||
550 | 35 | |||
551 | 36 | if (token.isEmpty()) { | ||
552 | 37 | qDebug() << "No token found for this userId in " + settings.fileName() + ". Discarding push notification..."; | ||
553 | 38 | return false; | ||
554 | 39 | } | ||
555 | 40 | |||
556 | 41 | EvernoteConnection::instance()->setToken(token); | ||
557 | 27 | EvernoteConnection::instance()->setHostname("www.evernote.com"); | 42 | EvernoteConnection::instance()->setHostname("www.evernote.com"); |
558 | 28 | EvernoteConnection::instance()->connectToEvernote(); | 43 | EvernoteConnection::instance()->connectToEvernote(); |
559 | 29 | 44 | ||
566 | 30 | qDebug() << "Core created"; | 45 | return true; |
561 | 31 | } | ||
562 | 32 | |||
563 | 33 | void Core::process(const QByteArray &pushNotification) | ||
564 | 34 | { | ||
565 | 35 | qDebug() << "should process:" << pushNotification; | ||
567 | 36 | } | 46 | } |
568 | 37 | 47 | ||
569 | 38 | void Core::connectedChanged() | 48 | void Core::connectedChanged() |
570 | @@ -48,13 +58,5 @@ | |||
571 | 48 | void Core::notesLoaded() | 58 | void Core::notesLoaded() |
572 | 49 | { | 59 | { |
573 | 50 | qDebug() << "notes loading changed:" << NotesStore::instance()->loading(); | 60 | qDebug() << "notes loading changed:" << NotesStore::instance()->loading(); |
574 | 51 | foreach (Note *note, NotesStore::instance()->notes()) { | ||
575 | 52 | qDebug() << "have note" << note->title(); | ||
576 | 53 | qDebug() << "content:" << note->plaintextContent(); | ||
577 | 54 | } | ||
578 | 55 | } | 61 | } |
579 | 56 | 62 | ||
580 | 57 | void Core::oaRequestFinished(const QVariantMap &reply) | ||
581 | 58 | { | ||
582 | 59 | qDebug() << "OA reply" << reply; | ||
583 | 60 | } | ||
584 | 61 | 63 | ||
585 | === modified file 'src/push-helper/core.h' | |||
586 | --- src/push-helper/core.h 2014-12-14 02:40:47 +0000 | |||
587 | +++ src/push-helper/core.h 2015-06-22 08:14:09 +0000 | |||
588 | @@ -9,7 +9,7 @@ | |||
589 | 9 | public: | 9 | public: |
590 | 10 | Core(QObject *parent = 0); | 10 | Core(QObject *parent = 0); |
591 | 11 | 11 | ||
593 | 12 | void process(const QByteArray &pushNotification); | 12 | bool process(const QByteArray &pushNotification); |
594 | 13 | 13 | ||
595 | 14 | 14 | ||
596 | 15 | signals: | 15 | signals: |
597 | @@ -17,7 +17,6 @@ | |||
598 | 17 | 17 | ||
599 | 18 | private slots: | 18 | private slots: |
600 | 19 | void connectedChanged(); | 19 | void connectedChanged(); |
601 | 20 | void oaRequestFinished(const QVariantMap &reply); | ||
602 | 21 | 20 | ||
603 | 22 | void notesLoaded(); | 21 | void notesLoaded(); |
604 | 23 | }; | 22 | }; |
605 | 24 | 23 | ||
606 | === modified file 'src/push-helper/main.cpp' | |||
607 | --- src/push-helper/main.cpp 2014-12-06 22:35:01 +0000 | |||
608 | +++ src/push-helper/main.cpp 2015-06-22 08:14:09 +0000 | |||
609 | @@ -23,6 +23,7 @@ | |||
610 | 23 | 23 | ||
611 | 24 | Core core; | 24 | Core core; |
612 | 25 | QObject::connect(&core, &Core::finished, &a, &QCoreApplication::exit); | 25 | QObject::connect(&core, &Core::finished, &a, &QCoreApplication::exit); |
613 | 26 | |||
614 | 26 | core.process(data); | 27 | core.process(data); |
615 | 27 | 28 | ||
616 | 28 | a.exec(); | 29 | a.exec(); |
FAILED: Continuous integration, rev:456 91.189. 93.70:8080/ job/reminders- app-ci/ 763/ 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2972/console 91.189. 93.70:8080/ job/reminders- app-utopic- amd64-ci/ 365/console 91.189. 93.70:8080/ job/reminders- app-vivid- amd64-ci/ 185/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/reminders- app-ci/ 763/rebuild
http://