1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Improve Calendar event behavior for group invites

Summary:
Ref T11816. Projects can be invited to an event, but the UI is currently fairly agnostic about them.

Instead, introduce the idea of "RSVPs", which are basically invites for you as an individual or for any group you're a part of. When we go to check if you're invited, we check for you individually first, then check for any groups you belong to if you haven't already accepted/declined.

On the calendar detail page:

  - Show the quick "Join" / "Decline" buttons if any project you're a member of is invited.
  - If you're invited, highlight any projects which you're a member of to make that more clear.

On other calendar views:

  - If you're invited as part of a project, show the "multiple users" icon.
  - If it's just you, continue showing the "add one user" icon.

Test Plan: Viewed month view, day view, detail view. Invited groups and individuals. Invited "Dog Project", accepted invite as user "Dog".

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11816

Differential Revision: https://secure.phabricator.com/D16868
This commit is contained in:
epriestley 2016-11-15 11:01:05 -08:00
parent 6464934cd6
commit edba4bb8d4
5 changed files with 178 additions and 17 deletions

View file

@ -309,16 +309,48 @@ final class PhabricatorCalendarEventViewController
$status_declined => 'red', $status_declined => 'red',
); );
$viewer_phid = $viewer->getPHID();
$is_rsvp_invited = $event->isRSVPInvited($viewer_phid);
$type_user = PhabricatorPeopleUserPHIDType::TYPECONST;
$head = array();
$tail = array();
foreach ($invitees as $invitee) { foreach ($invitees as $invitee) {
$item = new PHUIStatusItemView(); $item = new PHUIStatusItemView();
$invitee_phid = $invitee->getInviteePHID(); $invitee_phid = $invitee->getInviteePHID();
$status = $invitee->getStatus(); $status = $invitee->getStatus();
$target = $viewer->renderHandle($invitee_phid); $target = $viewer->renderHandle($invitee_phid);
$is_user = (phid_get_type($invitee_phid) == $type_user);
if (!$is_user) {
$icon = 'fa-users';
$icon_color = 'blue';
} else {
$icon = $icon_map[$status]; $icon = $icon_map[$status];
$icon_color = $icon_color_map[$status]; $icon_color = $icon_color_map[$status];
}
// Highlight invited groups which you're a member of if you have
// not RSVP'd to an event yet.
if ($is_rsvp_invited) {
if ($invitee_phid != $viewer_phid) {
if ($event->hasRSVPAuthority($viewer_phid, $invitee_phid)) {
$item->setHighlighted(true);
}
}
}
$item->setIcon($icon, $icon_color) $item->setIcon($icon, $icon_color)
->setTarget($target); ->setTarget($target);
if ($is_user) {
$tail[] = $item;
} else {
$head[] = $item;
}
}
foreach (array_merge($head, $tail) as $item) {
$invitee_list->addItem($item); $invitee_list->addItem($item);
} }
} else { } else {
@ -511,6 +543,7 @@ final class PhabricatorCalendarEventViewController
$event = id(new PhabricatorCalendarEventQuery()) $event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer) ->setViewer($viewer)
->withIDs(array($id)) ->withIDs(array($id))
->needRSVPs(array($viewer->getPHID()))
->executeOne(); ->executeOne();
if (!$event) { if (!$event) {
return null; return null;
@ -586,10 +619,8 @@ final class PhabricatorCalendarEventViewController
$viewer = $this->getViewer(); $viewer = $this->getViewer();
$id = $event->getID(); $id = $event->getID();
$invite_status = $event->getUserInviteStatus($viewer->getPHID()); $is_pending = $event->isRSVPInvited($viewer->getPHID());
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED; if (!$is_pending) {
$is_invite_pending = ($invite_status == $status_invited);
if (!$is_invite_pending) {
return array(); return array();
} }

View file

@ -43,7 +43,7 @@ final class PhabricatorCalendarEventInviteesPolicyRule
if (!isset($this->sourcePHIDs[$viewer_phid])) { if (!isset($this->sourcePHIDs[$viewer_phid])) {
$source_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( $source_phids = PhabricatorEdgeQuery::loadDestinationPHIDs(
$viewer_phid, $viewer_phid,
PhabricatorProjectMemberOfProjectEdgeType::EDGECONST); PhabricatorProjectMaterializedMemberEdgeType::EDGECONST);
$source_phids[] = $viewer_phid; $source_phids[] = $viewer_phid;
$this->sourcePHIDs[$viewer_phid] = $source_phids; $this->sourcePHIDs[$viewer_phid] = $source_phids;
} }

View file

@ -20,6 +20,7 @@ final class PhabricatorCalendarEventQuery
private $utcInitialEpochMin; private $utcInitialEpochMin;
private $utcInitialEpochMax; private $utcInitialEpochMax;
private $isImported; private $isImported;
private $needRSVPs;
private $generateGhosts = false; private $generateGhosts = false;
@ -109,6 +110,11 @@ final class PhabricatorCalendarEventQuery
return $this; return $this;
} }
public function needRSVPs(array $phids) {
$this->needRSVPs = $phids;
return $this;
}
protected function getDefaultOrderVector() { protected function getDefaultOrderVector() {
return array('start', 'id'); return array('start', 'id');
} }
@ -614,6 +620,70 @@ final class PhabricatorCalendarEventQuery
$events = msort($events, 'getStartDateTimeEpoch'); $events = msort($events, 'getStartDateTimeEpoch');
if ($this->needRSVPs) {
$rsvp_phids = $this->needRSVPs;
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST;
$project_phids = array();
foreach ($events as $event) {
foreach ($event->getInvitees() as $invitee) {
$invitee_phid = $invitee->getInviteePHID();
if (phid_get_type($invitee_phid) == $project_type) {
$project_phids[] = $invitee_phid;
}
}
}
if ($project_phids) {
$member_type = PhabricatorProjectMaterializedMemberEdgeType::EDGECONST;
$query = id(new PhabricatorEdgeQuery())
->withSourcePHIDs($project_phids)
->withEdgeTypes(array($member_type))
->withDestinationPHIDs($rsvp_phids);
$edges = $query->execute();
$project_map = array();
foreach ($edges as $src => $types) {
foreach ($types as $type => $dsts) {
foreach ($dsts as $dst => $edge) {
$project_map[$dst][] = $src;
}
}
}
} else {
$project_map = array();
}
$membership_map = array();
foreach ($rsvp_phids as $rsvp_phid) {
$membership_map[$rsvp_phid] = array();
$membership_map[$rsvp_phid][] = $rsvp_phid;
$project_phids = idx($project_map, $rsvp_phid);
if ($project_phids) {
foreach ($project_phids as $project_phid) {
$membership_map[$rsvp_phid][] = $project_phid;
}
}
}
foreach ($events as $event) {
$invitees = $event->getInvitees();
$invitees = mpull($invitees, null, 'getInviteePHID');
$rsvp_map = array();
foreach ($rsvp_phids as $rsvp_phid) {
$membership_phids = $membership_map[$rsvp_phid];
$rsvps = array_select_keys($invitees, $membership_phids);
$rsvp_map[$rsvp_phid] = $rsvps;
}
$event->attachRSVPs($rsvp_map);
}
}
return $events; return $events;
} }

View file

@ -16,7 +16,10 @@ final class PhabricatorCalendarEventSearchEngine
} }
public function newQuery() { public function newQuery() {
return new PhabricatorCalendarEventQuery(); $viewer = $this->requireViewer();
return id(new PhabricatorCalendarEventQuery())
->needRSVPs(array($viewer->getPHID()));
} }
protected function shouldShowOrderField() { protected function shouldShowOrderField() {

View file

@ -50,6 +50,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
private $parentEvent = self::ATTACHABLE; private $parentEvent = self::ATTACHABLE;
private $invitees = self::ATTACHABLE; private $invitees = self::ATTACHABLE;
private $importSource = self::ATTACHABLE; private $importSource = self::ATTACHABLE;
private $rsvps = self::ATTACHABLE;
private $viewerTimezone; private $viewerTimezone;
@ -643,7 +644,11 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
} }
if ($viewer->isLoggedIn()) { if ($viewer->isLoggedIn()) {
$status = $this->getUserInviteStatus($viewer->getPHID()); $viewer_phid = $viewer->getPHID();
if ($this->isRSVPInvited($viewer_phid)) {
return 'fa-users';
} else {
$status = $this->getUserInviteStatus($viewer_phid);
switch ($status) { switch ($status) {
case PhabricatorCalendarEventInvitee::STATUS_ATTENDING: case PhabricatorCalendarEventInvitee::STATUS_ATTENDING:
return 'fa-check-circle'; return 'fa-check-circle';
@ -653,6 +658,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return 'fa-times'; return 'fa-times';
} }
} }
}
if ($this->isImportedEvent()) { if ($this->isImportedEvent()) {
return 'fa-download'; return 'fa-download';
@ -671,7 +677,12 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
} }
if ($viewer->isLoggedIn()) { if ($viewer->isLoggedIn()) {
$status = $this->getUserInviteStatus($viewer->getPHID()); $viewer_phid = $viewer->getPHID();
if ($this->isRSVPInvited($viewer_phid)) {
return 'green';
}
$status = $this->getUserInviteStatus($viewer_phid);
switch ($status) { switch ($status) {
case PhabricatorCalendarEventInvitee::STATUS_ATTENDING: case PhabricatorCalendarEventInvitee::STATUS_ATTENDING:
return 'green'; return 'green';
@ -1121,6 +1132,52 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $phids; return $phids;
} }
public function getRSVPs($phid) {
return $this->assertAttachedKey($this->rsvps, $phid);
}
public function attachRSVPs(array $rsvps) {
$this->rsvps = $rsvps;
return $this;
}
public function isRSVPInvited($phid) {
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
return ($this->getRSVPStatus($phid) == $status_invited);
}
public function hasRSVPAuthority($phid, $other_phid) {
foreach ($this->getRSVPs($phid) as $rsvp) {
if ($rsvp->getInviteePHID() == $other_phid) {
return true;
}
}
return false;
}
public function getRSVPStatus($phid) {
// Check for an individual invitee record first.
$invitees = $this->invitees;
$invitees = mpull($invitees, null, 'getInviteePHID');
$invitee = idx($invitees, $phid);
if ($invitee) {
return $invitee->getStatus();
}
// If we don't have one, try to find an invited status for the user's
// projects.
$status_invited = PhabricatorCalendarEventInvitee::STATUS_INVITED;
foreach ($this->getRSVPs($phid) as $rsvp) {
if ($rsvp->getStatus() == $status_invited) {
return $status_invited;
}
}
return PhabricatorCalendarEventInvitee::STATUS_UNINVITED;
}
/* -( Markup Interface )--------------------------------------------------- */ /* -( Markup Interface )--------------------------------------------------- */