diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 2068c5646d..69f8738855 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -779,16 +779,17 @@ celerity_register_resource_map(array( ), 'javelin-behavior-aphlict-listen' => array( - 'uri' => '/res/4b1dc678/rsrc/js/application/aphlict/behavior-aphlict-listen.js', + 'uri' => '/res/204f141a/rsrc/js/application/aphlict/behavior-aphlict-listen.js', 'type' => 'js', 'requires' => array( 0 => 'javelin-behavior', 1 => 'javelin-aphlict', - 2 => 'javelin-util', - 3 => 'javelin-stratcom', - 4 => 'javelin-behavior-aphlict-dropdown', - 5 => 'phabricator-notification', + 2 => 'javelin-stratcom', + 3 => 'javelin-request', + 4 => 'javelin-uri', + 5 => 'javelin-dom', + 6 => 'phabricator-notification', ), 'disk' => '/rsrc/js/application/aphlict/behavior-aphlict-listen.js', ), diff --git a/src/view/page/PhabricatorStandardPageView.php b/src/view/page/PhabricatorStandardPageView.php index 562169074d..52b9e27bb8 100644 --- a/src/view/page/PhabricatorStandardPageView.php +++ b/src/view/page/PhabricatorStandardPageView.php @@ -404,12 +404,11 @@ final class PhabricatorStandardPageView extends AphrontPageView { 'id' => $aphlict_object_id, 'server' => $client_uri->getDomain(), 'port' => $client_uri->getPort(), - 'pageObjects' => $this->pageObjects, + 'pageObjects' => array_fill_keys($this->pageObjects, true), )); Javelin::initBehavior('aphlict-dropdown', array()); - $notification_count = id(new PhabricatorFeedStoryNotification()) ->countUnread($user); diff --git a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js index 585fd30fd3..0ef07ffed5 100644 --- a/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js +++ b/webroot/rsrc/js/application/aphlict/behavior-aphlict-listen.js @@ -2,42 +2,66 @@ * @provides javelin-behavior-aphlict-listen * @requires javelin-behavior * javelin-aphlict - * javelin-util * javelin-stratcom - * javelin-behavior-aphlict-dropdown + * javelin-request + * javelin-uri + * javelin-dom * phabricator-notification */ JX.behavior('aphlict-listen', function(config) { + + var showing_reload = false; + function onready() { - var client = new JX.Aphlict(config.id, config.server, config.port) - .setHandler(function(type, message) { - if (message) { - if (type == 'receive') { - var request = new JX.Request('/notification/individual/', - function(response) { - if (response.pertinent) { - if (config.pageObjects.indexOf(response.primaryObjectPHID) - > -1) { - var notification = new JX.Notification() - .setContent('Page updated. Please refresh.') - .setDuration(0) // never timeout - .show(); - } - - JX.Stratcom.invoke('notification-panel-update', null, {}); - } - }); - request.addData({ "key": message.key }); - request.send(); - } - } - }) + .setHandler(onaphlictmessage) .start(); } + // Respond to a notification from the Aphlict notification server. We send + // a request to Phabricator to get notification details. + function onaphlictmessage(type, message) { + if (!message) { + return; + } + + if (type != 'receive') { + return; + } + + var request = new JX.Request('/notification/individual/', onnotification) + .addData({key: message.key}) + .send(); + } + + + // Respond to a response from Phabricator about a specific notification. + function onnotification(response) { + if (!response.pertinent) { + return; + } + + JX.Stratcom.invoke('notification-panel-update', null, {}); + + // If the notification affected an object on this page, show a + // permanent reload notification if we aren't already. + + if ((response.primaryObjectPHID in config.pageObjects) && + !showing_reload) { + var reload = new JX.Notification() + .setContent('Page updated, click to reload.') + .setClassName('jx-notification-alert') + .setDuration(0); + reload.listen('activate', function(e) { JX.$U().go(); }) + reload.show(); + + showing_reload = true; + } + } + + // Wait for the element to load, and don't do anything if it never loads. // If we just go crazy and start making calls to it before it loads, its // interfaces won't be registered yet.