From e07077ae4e75b5fbdeb07abd3648ca45f9ef1def Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Mon, 8 Apr 2013 13:41:34 -0700 Subject: [PATCH] Conpherence - fix JS and add code to repair old bad data Summary: the JS is fragile with respect to the tokenizer coming in from the people widget. make sure to always try to load this up. Note this generally needs to get cleaned up where the server should only send down the *exact* bits the client needs. This is all TODO as part of getting this on mobile perfectly. Also note this fragility exists still in that you can break conpherence by clicking quickly before the initial tokenizer load loads. For old bad data, at some point we weren't updating participation as well as we do today in the editor class. the result is with the migration and code change some conversation participants have bad "last seen message" counts. the simplest case is the test user talking to themselves -- threads before the editor code fixes / changes will have the entire thread as unread for these folks. The other buggy case I saw was where the "last reply" to a thread wasn't being count. These issues showed up for threads February and older which is old. Test Plan: edited conpherence meta data and no JS bugs. pontificated and no JS bugs. added a person and no JS bugs. Reviewers: chad, epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D5622 --- src/__celerity_resource_map__.php | 15 +++--- .../storage/ConpherenceParticipant.php | 11 ++-- .../application/conpherence/behavior-menu.js | 50 +++++++++++++------ .../conpherence/behavior-pontificate.js | 13 +++++ 4 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/__celerity_resource_map__.php b/src/__celerity_resource_map__.php index 0d98d4596b..cc504725b9 100644 --- a/src/__celerity_resource_map__.php +++ b/src/__celerity_resource_map__.php @@ -1289,23 +1289,24 @@ celerity_register_resource_map(array( ), 'javelin-behavior-conpherence-menu' => array( - 'uri' => '/res/e8479b8e/rsrc/js/application/conpherence/behavior-menu.js', + 'uri' => '/res/257f200d/rsrc/js/application/conpherence/behavior-menu.js', 'type' => 'js', 'requires' => array( 0 => 'javelin-behavior', 1 => 'javelin-dom', - 2 => 'javelin-request', - 3 => 'javelin-stratcom', - 4 => 'javelin-workflow', - 5 => 'javelin-behavior-device', - 6 => 'javelin-history', + 2 => 'javelin-util', + 3 => 'javelin-request', + 4 => 'javelin-stratcom', + 5 => 'javelin-workflow', + 6 => 'javelin-behavior-device', + 7 => 'javelin-history', ), 'disk' => '/rsrc/js/application/conpherence/behavior-menu.js', ), 'javelin-behavior-conpherence-pontificate' => array( - 'uri' => '/res/68f1e046/rsrc/js/application/conpherence/behavior-pontificate.js', + 'uri' => '/res/91d6418d/rsrc/js/application/conpherence/behavior-pontificate.js', 'type' => 'js', 'requires' => array( diff --git a/src/applications/conpherence/storage/ConpherenceParticipant.php b/src/applications/conpherence/storage/ConpherenceParticipant.php index 1dd78130f7..119d6e5cc8 100644 --- a/src/applications/conpherence/storage/ConpherenceParticipant.php +++ b/src/applications/conpherence/storage/ConpherenceParticipant.php @@ -28,7 +28,7 @@ final class ConpherenceParticipant extends ConpherenceDAO { public function markUpToDate( ConpherenceThread $conpherence, ConpherenceTransaction $xaction) { - if (!$this->isUpToDate()) { + if (!$this->isUpToDate($conpherence)) { $this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE); $this->setBehindTransactionPHID($xaction->getPHID()); $this->setSeenMessageCount($conpherence->getMessageCount()); @@ -37,9 +37,12 @@ final class ConpherenceParticipant extends ConpherenceDAO { return $this; } - public function isUpToDate() { - return $this->getParticipationStatus() == - ConpherenceParticipationStatus::UP_TO_DATE; + private function isUpToDate(ConpherenceThread $conpherence) { + return + ($this->getSeenMessageCount() == $conpherence->getMessageCount()) + && + ($this->getParticipationStatus() == + ConpherenceParticipationStatus::UP_TO_DATE); } } diff --git a/webroot/rsrc/js/application/conpherence/behavior-menu.js b/webroot/rsrc/js/application/conpherence/behavior-menu.js index 0c22e47201..ab2f12f000 100644 --- a/webroot/rsrc/js/application/conpherence/behavior-menu.js +++ b/webroot/rsrc/js/application/conpherence/behavior-menu.js @@ -2,6 +2,7 @@ * @provides javelin-behavior-conpherence-menu * @requires javelin-behavior * javelin-dom + * javelin-util * javelin-request * javelin-stratcom * javelin-workflow @@ -134,29 +135,48 @@ JX.behavior('conpherence-menu', function(config) { JX.Stratcom.listen('click', 'conpherence-edit-metadata', function (e) { e.kill(); - var root = JX.$(config.form_pane); - var form = JX.DOM.find(root, 'form'); + var root = e.getNode('conpherence-layout'); + var form = JX.DOM.find(root, 'form', 'conpherence-pontificate'); var data = e.getNodeData('conpherence-edit-metadata'); + var header = JX.DOM.find(root, 'div', 'conpherence-header'); + var peopleWidget = null; + try { + peopleWidget = JX.DOM.find(root, 'div', 'widgets-people'); + } catch (ex) { + // Ignore; maybe no people widget + } + new JX.Workflow.newFromForm(form, data) - .setHandler(function (r) { + .setHandler(JX.bind(this, function(r) { // update the header JX.DOM.setContent( - JX.$(config.header), + header, JX.$H(r.header) ); - // update the menu entry - JX.DOM.replace( - JX.$(r.conpherence_phid + '-nav-item'), - JX.$H(r.nav_item) - ); + try { + // update the menu entry + JX.DOM.replace( + JX.$(r.conpherence_phid + '-nav-item'), + JX.$H(r.nav_item) + ); + JX.Stratcom.invoke( + 'conpherence-selectthread', + null, + { id : r.conpherence_phid + '-nav-item' } + ); + } catch (ex) { + // Ignore; this view may not have a menu. + } - // update the people widget - JX.DOM.setContent( - JX.$(config.people_widget), - JX.$H(r.people_widget) - ); - }) + if (peopleWidget) { + // update the people widget + JX.DOM.setContent( + peopleWidget, + JX.$H(r.people_widget) + ); + } + })) .start(); }); diff --git a/webroot/rsrc/js/application/conpherence/behavior-pontificate.js b/webroot/rsrc/js/application/conpherence/behavior-pontificate.js index 1661e5a1d1..aecf159b01 100644 --- a/webroot/rsrc/js/application/conpherence/behavior-pontificate.js +++ b/webroot/rsrc/js/application/conpherence/behavior-pontificate.js @@ -22,6 +22,12 @@ JX.behavior('conpherence-pontificate', function(config) { } catch (ex) { // Ignore; maybe no files widget } + var peopleWidget = null; + try { + peopleWidget = JX.DOM.find(root, 'div', 'widgets-people'); + } catch (ex) { + // Ignore; maybe no peoples widget + } JX.Workflow.newFromForm(form) .setHandler(JX.bind(this, function(r) { @@ -51,6 +57,13 @@ JX.behavior('conpherence-pontificate', function(config) { ); } + if (peopleWidget) { + JX.DOM.setContent( + peopleWidget, + JX.$H(r.people_widget) + ); + } + var inputs = JX.DOM.scry(form, 'input'); for (var ii = 0; ii < inputs.length; ii++) { if (inputs[ii].name == 'latest_transaction_id') {