From 22ce74c5a88d7e88a04becfe0f3c59d622ef946c Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Sat, 26 Jan 2013 18:53:30 -0800 Subject: [PATCH] Conpherence - fix unread counts Summary: we weren't updating the "latest seen transaction PHID" properly. do that and ONLY do it from the view handler so we know the user got a real good chance of actually seeing the message. also we weren't searching through the transactions correctly; fix that. Test Plan: sent a test user some messages. noted the proper count of unread messages. Reviewers: epriestley, chad Reviewed By: chad CC: aran, Korvin Maniphest Tasks: T2399 Differential Revision: https://secure.phabricator.com/D4677 --- .../controller/ConpherenceListController.php | 4 ---- .../controller/ConpherenceViewController.php | 4 +++- .../conpherence/storage/ConpherenceParticipant.php | 3 ++- .../conpherence/storage/ConpherenceThread.php | 11 +++++++---- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/applications/conpherence/controller/ConpherenceListController.php b/src/applications/conpherence/controller/ConpherenceListController.php index 80ef89d66a..916d044e86 100644 --- a/src/applications/conpherence/controller/ConpherenceListController.php +++ b/src/applications/conpherence/controller/ConpherenceListController.php @@ -41,11 +41,7 @@ final class ConpherenceListController extends } $this->setSelectedConpherencePHID($conpherence->getPHID()); - $read_status = ConpherenceParticipationStatus::UP_TO_DATE; $participant = $conpherence->getParticipant($user->getPHID()); - $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites(); - $participant->markUpToDate(); - unset($write_guard); $current_selection_epoch = $participant->getDateTouched(); } diff --git a/src/applications/conpherence/controller/ConpherenceViewController.php b/src/applications/conpherence/controller/ConpherenceViewController.php index 284d237802..d615edac50 100644 --- a/src/applications/conpherence/controller/ConpherenceViewController.php +++ b/src/applications/conpherence/controller/ConpherenceViewController.php @@ -49,8 +49,10 @@ final class ConpherenceViewController extends $this->setConpherence($conpherence); $participant = $conpherence->getParticipant($user->getPHID()); + $transactions = $conpherence->getTransactions(); + $latest_transaction = end($transactions); $write_guard = AphrontWriteGuard::beginScopedUnguardedWrites(); - $participant->markUpToDate(); + $participant->markUpToDate($latest_transaction); unset($write_guard); $header = $this->renderHeaderPaneContent(); diff --git a/src/applications/conpherence/storage/ConpherenceParticipant.php b/src/applications/conpherence/storage/ConpherenceParticipant.php index e21d6204ad..be897c11fe 100644 --- a/src/applications/conpherence/storage/ConpherenceParticipant.php +++ b/src/applications/conpherence/storage/ConpherenceParticipant.php @@ -11,9 +11,10 @@ final class ConpherenceParticipant extends ConpherenceDAO { protected $behindTransactionPHID; protected $dateTouched; - public function markUpToDate() { + public function markUpToDate(ConpherenceTransaction $xaction) { if (!$this->isUpToDate()) { $this->setParticipationStatus(ConpherenceParticipationStatus::UP_TO_DATE); + $this->setBehindTransactionPHID($xaction->getPHID()); $this->save(); } return $this; diff --git a/src/applications/conpherence/storage/ConpherenceThread.php b/src/applications/conpherence/storage/ConpherenceThread.php index c5c2c4723a..1b80aec1a5 100644 --- a/src/applications/conpherence/storage/ConpherenceThread.php +++ b/src/applications/conpherence/storage/ConpherenceThread.php @@ -189,15 +189,18 @@ final class ConpherenceThread extends ConpherenceDAO } // fallthrough intentionally here case ConpherenceTransactionType::TYPE_FILES: - default: - if ($behind_transaction_phid && - $transaction->getPHID() != $behind_transaction_phid) { - $unread_count++; + if ($behind_transaction_phid) { + $unread_count++; + if ($transaction->getPHID() == $behind_transaction_phid) { + break 2; } + } if ($unread_count > $max_count) { break 2; } break; + default: + continue 2; } if ($snippet && !$behind_transaction_phid) { break;