From 8e9c20c9ae63361bd2010f5ae3eb497f01d43ba6 Mon Sep 17 00:00:00 2001 From: epriestley Date: Thu, 27 Oct 2016 10:18:04 -0700 Subject: [PATCH] Make event invitees behave a little better for stub/ghost events Summary: Ref T11326. Currently: - The month view and day view (ghosts) don't show that you're invited to a child event. - The detail view copies the invite list, including attending status, but only //after// it shows the page for the first time. Instead, for now, just do this: - Ghosts/stubs use the parent invite list, but treat everyone as "invited". - Materializing a stub just saves the list as-is (i.e., invited, not a copy of attending/declined/etc). This behavior may need some refining eventually but is at least reasonable (not obviously bad/buggy). Test Plan: - Viewed month/day views, now shown as "invited". - Viewed detail view, now invitee list shows up properly. Reviewers: chad Reviewed By: chad Maniphest Tasks: T11326 Differential Revision: https://secure.phabricator.com/D16758 --- .../editor/PhabricatorCalendarEventEditor.php | 27 ++++++++--------- .../storage/PhabricatorCalendarEvent.php | 30 ++++++++++++++++++- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php index 655037c140..d22d34bee7 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php @@ -34,25 +34,22 @@ final class PhabricatorCalendarEventEditor } $actor = $this->getActor(); + + $invitees = $event->getInvitees(); + $event->copyFromParent($actor); $event->setIsStub(0); - $invitees = $event->getParentEvent()->getInvitees(); + $event->openTransaction(); + $event->save(); + foreach ($invitees as $invitee) { + $invitee + ->setEventPHID($event->getPHID()) + ->save(); + } + $event->saveTransaction(); - $new_invitees = array(); - foreach ($invitees as $invitee) { - $invitee = id(new PhabricatorCalendarEventInvitee()) - ->setEventPHID($event->getPHID()) - ->setInviteePHID($invitee->getInviteePHID()) - ->setInviterPHID($invitee->getInviterPHID()) - ->setStatus($invitee->getStatus()) - ->save(); - - $new_invitees[] = $invitee; - } - - $event->save(); - $event->attachInvitees($new_invitees); + $event->attachInvitees($invitees); } public function getTransactionTypes() { diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index ce9e28fa17..c5d5c898f9 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -27,7 +27,6 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO protected $isRecurring = 0; - private $isGhostEvent = false; protected $instanceOfEventPHID; protected $sequenceIndex; @@ -60,6 +59,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO protected $recurrenceEndDate; protected $recurrenceFrequency = array(); + private $isGhostEvent = false; + private $stubInvitees; + public static function initializeNewCalendarEvent(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) @@ -449,9 +451,34 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO } public function getInvitees() { + if ($this->getIsGhostEvent() || $this->getIsStub()) { + if ($this->stubInvitees === null) { + $this->stubInvitees = $this->newStubInvitees(); + } + return $this->stubInvitees; + } + return $this->assertAttached($this->invitees); } + private function newStubInvitees() { + $parent = $this->getParentEvent(); + + $parent_invitees = $parent->getInvitees(); + $stub_invitees = array(); + + foreach ($parent_invitees as $invitee) { + $stub_invitee = id(new PhabricatorCalendarEventInvitee()) + ->setInviteePHID($invitee->getInviteePHID()) + ->setInviterPHID($invitee->getInviterPHID()) + ->setStatus(PhabricatorCalendarEventInvitee::STATUS_INVITED); + + $stub_invitees[] = $stub_invitee; + } + + return $stub_invitees; + } + public function attachInvitees(array $invitees) { $this->invitees = $invitees; return $this; @@ -478,6 +505,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO if (!$invited) { return PhabricatorCalendarEventInvitee::STATUS_UNINVITED; } + $invited = $invited->getStatus(); return $invited; }