Skip to content

Commit d8ab5f5

Browse files
committedApr 20, 2015
Quicksand - make page object notifications work properly with quicksand
Summary: Fixes T7680. Make it so the listen behavior can be initialized multiple times from the server by having the behavior only update a few static data variables on subsequent initializations. Test Plan: visited TX with user A and left a comment with user B and got the "reload" and "TX updated" bubbles. Reloaded and navigated to /maniphest/ with user A and had user B leave another comment on TX - no "reload" bubble and correct "TX updated" bubble. Navigated to TX again with user A and had user B leave a comment and got the "reload" and "TX updated" bubbles. visited TX with user A and left a comment with user B and got the "reload" and "TX updated" bubbles. navigated away with user A and the "reload" bubble was automagically closed. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7680 Differential Revision: https://secure.phabricator.com/D12448
1 parent 1602858 commit d8ab5f5

File tree

4 files changed

+90
-39
lines changed

4 files changed

+90
-39
lines changed
 

‎resources/celerity/map.php

+26-26
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
return array(
99
'names' => array(
1010
'core.pkg.css' => 'a2a90172',
11-
'core.pkg.js' => 'dfea788f',
11+
'core.pkg.js' => '328a9980',
1212
'darkconsole.pkg.js' => '8ab24e01',
1313
'differential.pkg.css' => '3500921f',
1414
'differential.pkg.js' => 'c0506961',
@@ -349,9 +349,9 @@
349349
'rsrc/image/texture/table_header.png' => '5c433037',
350350
'rsrc/image/texture/table_header_hover.png' => '038ec3b9',
351351
'rsrc/image/texture/table_header_tall.png' => 'd56b434f',
352-
'rsrc/js/application/aphlict/Aphlict.js' => '2be71d56',
352+
'rsrc/js/application/aphlict/Aphlict.js' => '30a6303c',
353353
'rsrc/js/application/aphlict/behavior-aphlict-dropdown.js' => '00def500',
354-
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'bdf2226d',
354+
'rsrc/js/application/aphlict/behavior-aphlict-listen.js' => 'b1a59974',
355355
'rsrc/js/application/aphlict/behavior-aphlict-status.js' => 'ea681761',
356356
'rsrc/js/application/auth/behavior-persona-login.js' => '9414ff18',
357357
'rsrc/js/application/config/behavior-reorder-fields.js' => '14a827de',
@@ -548,10 +548,10 @@
548548
'herald-test-css' => '778b008e',
549549
'homepage-panel-css' => 'e34bf140',
550550
'inline-comment-summary-css' => 'eb5f8e8c',
551-
'javelin-aphlict' => '2be71d56',
551+
'javelin-aphlict' => '30a6303c',
552552
'javelin-behavior' => '61cbc29a',
553553
'javelin-behavior-aphlict-dropdown' => '00def500',
554-
'javelin-behavior-aphlict-listen' => 'bdf2226d',
554+
'javelin-behavior-aphlict-listen' => 'b1a59974',
555555
'javelin-behavior-aphlict-status' => 'ea681761',
556556
'javelin-behavior-aphront-basic-tokenizer' => 'b3a4b884',
557557
'javelin-behavior-aphront-crop' => 'fa0f4fc2',
@@ -1034,13 +1034,6 @@
10341034
'javelin-install',
10351035
'javelin-util',
10361036
),
1037-
'2be71d56' => array(
1038-
'javelin-install',
1039-
'javelin-util',
1040-
'javelin-websocket',
1041-
'javelin-leader',
1042-
'javelin-json',
1043-
),
10441037
'2bfa2836' => array(
10451038
'javelin-behavior',
10461039
'javelin-stratcom',
@@ -1056,6 +1049,13 @@
10561049
'javelin-install',
10571050
'javelin-event',
10581051
),
1052+
'30a6303c' => array(
1053+
'javelin-install',
1054+
'javelin-util',
1055+
'javelin-websocket',
1056+
'javelin-leader',
1057+
'javelin-json',
1058+
),
10591059
'316b8fa1' => array(
10601060
'javelin-install',
10611061
'javelin-typeahead-source',
@@ -1689,6 +1689,20 @@
16891689
'javelin-util',
16901690
'phabricator-prefab',
16911691
),
1692+
'b1a59974' => array(
1693+
'javelin-behavior',
1694+
'javelin-aphlict',
1695+
'javelin-stratcom',
1696+
'javelin-request',
1697+
'javelin-uri',
1698+
'javelin-dom',
1699+
'javelin-json',
1700+
'javelin-router',
1701+
'javelin-util',
1702+
'javelin-leader',
1703+
'javelin-sound',
1704+
'phabricator-notification',
1705+
),
16921706
'b1f0ccee' => array(
16931707
'javelin-install',
16941708
'javelin-dom',
@@ -1748,20 +1762,6 @@
17481762
'javelin-util',
17491763
'javelin-request',
17501764
),
1751-
'bdf2226d' => array(
1752-
'javelin-behavior',
1753-
'javelin-aphlict',
1754-
'javelin-stratcom',
1755-
'javelin-request',
1756-
'javelin-uri',
1757-
'javelin-dom',
1758-
'javelin-json',
1759-
'javelin-router',
1760-
'javelin-util',
1761-
'javelin-leader',
1762-
'javelin-sound',
1763-
'phabricator-notification',
1764-
),
17651765
'be807912' => array(
17661766
'javelin-behavior',
17671767
'javelin-dom',

‎src/view/page/PhabricatorStandardPageView.php

+13-9
Original file line numberDiff line numberDiff line change
@@ -461,11 +461,6 @@ protected function getTail() {
461461
$client_uri->setDomain($this_host->getDomain());
462462
}
463463

464-
$subscriptions = $this->pageObjects;
465-
if ($user) {
466-
$subscriptions[] = $user->getPHID();
467-
}
468-
469464
if ($request->isHTTPS()) {
470465
$client_uri->setProtocol('wss');
471466
} else {
@@ -476,9 +471,7 @@ protected function getTail() {
476471
'aphlict-listen',
477472
array(
478473
'websocketURI' => (string)$client_uri,
479-
'pageObjects' => array_fill_keys($this->pageObjects, true),
480-
'subscriptions' => $subscriptions,
481-
));
474+
) + $this->buildAphlictListenConfigData());
482475
}
483476
}
484477

@@ -590,7 +583,18 @@ public function renderForQuicksand() {
590583
}
591584

592585
private function buildQuicksandConfig() {
593-
return array();
586+
return $this->buildAphlictListenConfigData();
587+
}
588+
589+
private function buildAphlictListenConfigData() {
590+
$user = $this->getRequest()->getUser();
591+
$subscriptions = $this->pageObjects;
592+
$subscriptions[] = $user->getPHID();
593+
594+
return array(
595+
'pageObjects' => array_fill_keys($this->pageObjects, true),
596+
'subscriptions' => $subscriptions,
597+
);
594598
}
595599

596600
private function getQuicksandURIPatternBlacklist() {

‎webroot/rsrc/js/application/aphlict/Aphlict.js

+14
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ JX.install('Aphlict', {
4949
JX.Leader.call(JX.bind(this, this._begin));
5050
},
5151

52+
setSubscriptions: function(subscriptions) {
53+
this._subscriptions = subscriptions;
54+
JX.Leader.broadcast(
55+
null,
56+
{type: 'aphlict.subscribe', data: this._subscriptions});
57+
},
58+
59+
clearSubscriptions: function(subscriptions) {
60+
this._subscriptions = null;
61+
JX.Leader.broadcast(
62+
null,
63+
{type: 'aphlict.unsubscribe', data: subscriptions});
64+
},
65+
5266
getStatus: function() {
5367
return this._status;
5468
},

‎webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js

+37-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
*/
1616

1717
JX.behavior('aphlict-listen', function(config) {
18-
var showing_reload = false;
18+
var page_objects = config.pageObjects;
19+
var reload_notification = null;
1920

2021
JX.Stratcom.listen('aphlict-server-message', null, function(e) {
2122
var message = e.getData();
@@ -78,15 +79,28 @@ JX.behavior('aphlict-listen', function(config) {
7879

7980
// If the notification affected an object on this page, show a
8081
// permanent reload notification if we aren't already.
81-
if ((response.primaryObjectPHID in config.pageObjects) && !showing_reload) {
82+
if ((response.primaryObjectPHID in page_objects) &&
83+
reload_notification === null) {
84+
8285
var reload = new JX.Notification()
8386
.setContent('Page updated, click to reload.')
8487
.alterClassName('jx-notification-alert', true)
8588
.setDuration(0);
86-
reload.listen('activate', function() { JX.$U().go(); });
89+
reload.listen(
90+
'activate',
91+
function() {
92+
// double check we are still on the page where re-loading makes
93+
// sense...!
94+
if (response.primaryObjectPHID in page_objects) {
95+
JX.$U().go();
96+
}
97+
});
8798
reload.show();
8899

89-
showing_reload = true;
100+
reload_notification = {
101+
dialog: reload,
102+
phid: response.primaryObjectPHID
103+
};
90104
}
91105
});
92106

@@ -98,6 +112,25 @@ JX.behavior('aphlict-listen', function(config) {
98112
.setHandler(onAphlictMessage)
99113
.start();
100114

115+
JX.Stratcom.listen(
116+
'quicksand-redraw',
117+
null,
118+
function (e) {
119+
var old_data = e.getData().oldResponse;
120+
var new_data = e.getData().newResponse;
121+
client.clearSubscriptions(old_data.subscriptions);
122+
client.setSubscriptions(new_data.subscriptions);
123+
124+
page_objects = new_data.pageObjects;
125+
if (reload_notification) {
126+
if (reload_notification.phid in page_objects) {
127+
return;
128+
}
129+
reload_notification.dialog.hide();
130+
reload_notification = null;
131+
}
132+
});
133+
101134
JX.Leader.listen('onReceiveBroadcast', function(message, is_leader) {
102135
if (message.type !== 'sound') {
103136
return;

0 commit comments

Comments
 (0)
Failed to load comments.