Merge lp:~alecu/unity-lens-music/silence-notifications into lp:unity-lens-music

Proposed by Alejandro J. Cura
Status: Needs review
Proposed branch: lp:~alecu/unity-lens-music/silence-notifications
Merge into: lp:unity-lens-music
Diff against target: 157 lines (+75/-15)
3 files modified
src/musicstore-scope.vala (+38/-15)
src/ubuntuone-webservices.vala (+14/-0)
tests/unit/test-ubuntuone-purchases.vala (+23/-0)
To merge this branch: bzr merge lp:~alecu/unity-lens-music/silence-notifications
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Unity Team Pending
Review via email: mp+167874@code.launchpad.net

Commit message

Update the text of the notifications on error

Description of the change

Update the text of the notifications on error

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alejandro J. Cura (alecu) wrote :

This branch changes the text of the "performing purchase" notification, right at the moment any error happens:

When the purchase fails:
http://ubuntuone.com/5n1T5viEW9ttNOCwcFG4Lx

When the password is wrong:
http://ubuntuone.com/0eF2usg4CRunxko5SCcfcI

141. By Alejandro J. Cura

merged with trunk

142. By Alejandro J. Cura

merge lp:~alecu/unity-lens-music/sign-opened-urls

143. By Alejandro J. Cura

merged from sign-open-urls

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Unmerged revisions

143. By Alejandro J. Cura

merged from sign-open-urls

142. By Alejandro J. Cura

merge lp:~alecu/unity-lens-music/sign-opened-urls

141. By Alejandro J. Cura

merged with trunk

140. By Alejandro J. Cura

update notifications on error

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/musicstore-scope.vala'
2--- src/musicstore-scope.vala 2013-06-20 13:23:37 +0000
3+++ src/musicstore-scope.vala 2013-07-11 01:18:29 +0000
4@@ -28,6 +28,9 @@
5 private const string ERROR_MESSAGE_NOT_LOGGED_IN = _("It seems you don't have an Ubuntu One account, or you are not logged in. To continue, please login and visit the Ubuntu One online store.");
6 private const string ERROR_MESSAGE_NO_PAYMENT_METHOD = _("It seems you haven't set yet your preferred Ubuntu One payment method. To add a payment method, please visit the Ubuntu One online store.");
7 private const string ERROR_MESSAGE_TECHNICAL_PROBLEM = _("Sorry, we have encountered a technical problem. No money has been taken from your account. To try your purchase again, please visit the Ubuntu One online store.");
8+ private const string ERROR_MESSAGE_SHORT_TECHNICAL_PROBLEM = _("To try your purchase again, please visit the Ubuntu One online store.");
9+ private const string ERROR_MESSAGE_WRONG_PASSWORD = _("Wrong password");
10+ private const string NOTIFICATION_TITLE_PURCHASE_FAILED = _("Purchase failed");
11 private const string UBUNTUONE_MUSIC_LOGIN = Config.LIBEXECDIR + "/ubuntuone-credentials/ubuntuone-music-login";
12
13 public class MusicStoreScopeProxy : SimpleScope
14@@ -89,11 +92,19 @@
15 public Unity.ActivationResponse open_uri (string uri)
16 {
17 /* launch the music store streaming client or the webstore or whatevz */
18- try {
19- AppInfo.launch_default_for_uri (uri, null);
20- } catch (GLib.Error e) {
21- warning ("Failed to open uri %s. %s", uri, e.message);
22- }
23+ purchase_service.build_logged_url.begin(uri, (obj, res) => {
24+ try {
25+ var full_url = purchase_service.build_logged_url.end (res);
26+ if (uri.has_prefix ("https://one.ubuntu.com/") || uri.has_prefix ("http://musicsearch.ubuntu.com/")) {
27+ AppInfo.launch_default_for_uri (full_url, null);
28+ } else {
29+ AppInfo.launch_default_for_uri (uri, null);
30+ }
31+ } catch (PurchaseError e) {
32+ debug ("Can't fetch credentials: %s to open url: %s", e.message, uri);
33+ AppInfo.launch_default_for_uri (uri, null);
34+ }
35+ });
36 return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
37 }
38
39@@ -133,7 +144,7 @@
40 else if (album.price == 0)
41 download_action.extra_text = _("Free");
42
43- download_action.activated.connect (open_uri);
44+ download_action.activated.connect (show_purchase_preview);
45
46 music_preview.add_action (download_action);
47 }
48@@ -344,25 +355,37 @@
49 debug ("Error while showing notification: %s", e.message);
50 }
51
52+ Unity.ActivationResponse response;
53+ string reason;
54+
55 try {
56 purchase_service.purchase (album.purchase_sku, password);
57 debug ("purchase completed.");
58 notification.update (album.title, _("Purchase completed"), "");
59- try {
60- notification.show ();
61- } catch (GLib.Error e) {
62- debug ("Error while showing notification: %s", e.message);
63- }
64- return new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
65+ reason = "purchase completed";
66+ response = new Unity.ActivationResponse (Unity.HandledType.HIDE_DASH);
67+
68 } catch (PurchaseError e) {
69+
70 if (e is PurchaseError.WRONG_PASSWORD_ERROR) {
71 debug ("wrong password error: %s", e.message);
72- return new Unity.ActivationResponse.with_preview (purchase_preview (uri, _("Wrong password")));
73+ reason = ERROR_MESSAGE_WRONG_PASSWORD;
74+ response = new Unity.ActivationResponse.with_preview (purchase_preview (uri, ERROR_MESSAGE_WRONG_PASSWORD));
75 } else {
76 debug ("got purchase error: %s", e.message);
77- return build_error_preview (uri, ERROR_MESSAGE_TECHNICAL_PROBLEM, album.formatted_price, _("Continue"), open_uri);
78+ reason = ERROR_MESSAGE_SHORT_TECHNICAL_PROBLEM;
79+ response = build_error_preview (uri, ERROR_MESSAGE_TECHNICAL_PROBLEM, album.formatted_price, _("Continue"), open_uri);
80 }
81- }
82+ notification.update (NOTIFICATION_TITLE_PURCHASE_FAILED, reason, "");
83+ }
84+
85+ try {
86+ notification.show ();
87+ debug ("Showing updated notification: %s", reason);
88+ } catch (GLib.Error e) {
89+ debug ("Error while updating notification: %s", e.message);
90+ }
91+ return response;
92 }
93
94 public Unity.Preview purchase_preview (string uri, string? error_message)
95
96=== modified file 'src/ubuntuone-webservices.vala'
97--- src/ubuntuone-webservices.vala 2013-05-29 15:04:08 +0000
98+++ src/ubuntuone-webservices.vala 2013-07-11 01:18:29 +0000
99@@ -336,5 +336,19 @@
100 purchase_with_default_payment (album_id, purchase_token);
101 debug ("purchase completed.");
102 }
103+
104+ public virtual async string build_logged_url (string dest_url) throws PurchaseError
105+ {
106+ const string U1_OAUTH_LOGIN = "https://one.ubuntu.com/api/1.0/from_oauth/?next=";
107+ if (!got_credentials ()) {
108+ yield fetch_credentials();
109+ }
110+ if (got_credentials ()) {
111+ var full_url = U1_OAUTH_LOGIN + Soup.URI.encode(dest_url, null);
112+ return oauth_sign(full_url);
113+ } else {
114+ return dest_url;
115+ }
116+ }
117 }
118 }
119
120=== modified file 'tests/unit/test-ubuntuone-purchases.vala'
121--- tests/unit/test-ubuntuone-purchases.vala 2013-05-29 15:04:08 +0000
122+++ tests/unit/test-ubuntuone-purchases.vala 2013-07-11 01:18:29 +0000
123@@ -128,6 +128,7 @@
124 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseDefaultPaymentBroken", test_purchase_with_default_payment_broken_json);
125 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseConnectionFails", test_purchase_with_default_payment_connection_fails);
126 Test.add_data_func ("/Unit/PurchaseChecker/PurchaseDefaultPaymentFails", test_purchase_with_default_payment_fails);
127+ Test.add_data_func ("/Unit/PurchaseChecker/SignUbuntuoneUrls", test_sign_ubuntuone_urls);
128
129 return Test.run ();
130 }
131@@ -716,4 +717,26 @@
132 assert (e is PurchaseError.PURCHASE_ERROR);
133 }
134 }
135+
136+ private static void test_sign_ubuntuone_urls ()
137+ {
138+ string dest = "https://one.ubuntu.com/contacts/";
139+ var purchase_service = new BaseTestPurchaseService ();
140+
141+ MainLoop mainloop = new MainLoop ();
142+ purchase_service.build_logged_url.begin(dest, (obj, res) => {
143+ mainloop.quit ();
144+ try {
145+ var full_url = purchase_service.build_logged_url.end (res);
146+ debug (full_url);
147+ assert (full_url.contains("oauth_consumer_key"));
148+ //GLib.Process.spawn_command_line_sync ("chromium-browser --incognito " + full_url);
149+ } catch (PurchaseError e) {
150+ warning ("Can't fetch credentials: %s", e.message);
151+ assert_not_reached ();
152+ }
153+ });
154+ assert (run_with_timeout (mainloop, 1000));
155+ //assert (purchase_service._ubuntuone_credentials != null);
156+ }
157 }

Subscribers

People subscribed via source and target branches

to all changes: