From 540e38d20e945167a131f50344b3ae320cf667e8 Mon Sep 17 00:00:00 2001 From: Bob Trahan Date: Thu, 9 Apr 2015 14:02:35 -0700 Subject: [PATCH] Conpherence - fix recent participant cache Summary: Ref T7795. This fixes the behavior where you end up with a "a, b, c..." as the list of participants, and yet user a just left. Test Plan: joined and left a thread. verified database had correct values. observed correct behavior in messages dropdown Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T7795 Differential Revision: https://secure.phabricator.com/D12338 --- .../conpherence/editor/ConpherenceEditor.php | 26 +++++++++++++++---- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/applications/conpherence/editor/ConpherenceEditor.php b/src/applications/conpherence/editor/ConpherenceEditor.php index d896829ee0..166ad055b1 100644 --- a/src/applications/conpherence/editor/ConpherenceEditor.php +++ b/src/applications/conpherence/editor/ConpherenceEditor.php @@ -235,6 +235,7 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) { + $make_author_recent_participant = true; switch ($xaction->getTransactionType()) { case PhabricatorTransactions::TYPE_COMMENT: $object->setMessageCount((int)$object->getMessageCount() + 1); @@ -244,23 +245,38 @@ final class ConpherenceEditor extends PhabricatorApplicationTransactionEditor { break; case ConpherenceTransactionType::TYPE_PARTICIPANTS: if (!$this->getIsNewObject()) { - // if we added people, add them to the end of "recent" participants $old_map = array_fuse($xaction->getOldValue()); $new_map = array_fuse($xaction->getNewValue()); + // if we added people, add them to the end of "recent" participants $add = array_keys(array_diff_key($new_map, $old_map)); - if ($add) { + // if we remove people, then definintely remove them from "recent" + // participants + $del = array_keys(array_diff_key($old_map, $new_map)); + if ($add || $del) { $participants = $object->getRecentParticipantPHIDs(); - $participants = array_merge($participants, $add); + if ($add) { + $participants = array_merge($participants, $add); + } + if ($del) { + $participants = array_diff($participants, $del); + $actor = $this->requireActor(); + if (in_array($actor->getPHID(), $del)) { + $make_author_recent_participant = false; + } + } $participants = array_slice(array_unique($participants), 0, 10); $object->setRecentParticipantPHIDs($participants); } } break; } - $this->updateRecentParticipantPHIDs($object, $xaction); + + if ($make_author_recent_participant) { + $this->makeAuthorMostRecentParticipant($object, $xaction); + } } - private function updateRecentParticipantPHIDs( + private function makeAuthorMostRecentParticipant( PhabricatorLiskDAO $object, PhabricatorApplicationTransaction $xaction) {