@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create separate "Accept" and "Decline" transactions for Calendar

Summary:
Ref T9275. Currently, there's a single "invite" transaction type for managing Calendar invites, and it takes a map of invitees to status.

This isn't great for EditEngine or API access, since it lets you set anyone else to any status and we can't reuse as much code as we can with a simpler API.

Make "Accept" and "Decline" separate actions which affect the actor's invite, so "invite" can be a simpler transaction which just invites or uninvites people.

Test Plan:
- Joined/accepted/declined an event invitation.
- Edited event invitees.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9275

Differential Revision: https://secure.phabricator.com/D16272

+82 -34
+21 -34
src/applications/calendar/controller/PhabricatorCalendarEventJoinController.php
··· 3 3 final class PhabricatorCalendarEventJoinController 4 4 extends PhabricatorCalendarController { 5 5 6 - const ACTION_ACCEPT = 'accept'; 7 - const ACTION_DECLINE = 'decline'; 8 - const ACTION_JOIN = 'join'; 9 - 10 6 public function handleRequest(AphrontRequest $request) { 7 + $viewer = $this->getViewer(); 11 8 $id = $request->getURIData('id'); 12 - $action = $request->getURIData('action'); 13 - 14 - $request = $this->getRequest(); 15 - $viewer = $request->getViewer(); 16 - $declined_status = PhabricatorCalendarEventInvitee::STATUS_DECLINED; 17 - $attending_status = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 18 9 19 10 $event = id(new PhabricatorCalendarEventQuery()) 20 11 ->setViewer($viewer) ··· 25 16 } 26 17 27 18 $cancel_uri = $event->getURI(); 28 - $validation_exception = null; 29 19 30 - $is_attending = $event->getIsUserAttending($viewer->getPHID()); 20 + $action = $request->getURIData('action'); 21 + switch ($action) { 22 + case 'accept': 23 + $is_join = true; 24 + break; 25 + case 'decline': 26 + $is_join = false; 27 + break; 28 + default: 29 + $is_join = !$event->getIsUserAttending($viewer->getPHID()); 30 + break; 31 + } 31 32 33 + $validation_exception = null; 32 34 if ($request->isFormPost()) { 33 - $new_status = null; 34 - 35 - switch ($action) { 36 - case self::ACTION_ACCEPT: 37 - $new_status = $attending_status; 38 - break; 39 - case self::ACTION_JOIN: 40 - if ($is_attending) { 41 - $new_status = $declined_status; 42 - } else { 43 - $new_status = $attending_status; 44 - } 45 - break; 46 - case self::ACTION_DECLINE: 47 - $new_status = $declined_status; 48 - break; 35 + if ($is_join) { 36 + $xaction_type = PhabricatorCalendarEventTransaction::TYPE_ACCEPT; 37 + } else { 38 + $xaction_type = PhabricatorCalendarEventTransaction::TYPE_DECLINE; 49 39 } 50 40 51 - $new_status = array($viewer->getPHID() => $new_status); 52 - 53 41 $xaction = id(new PhabricatorCalendarEventTransaction()) 54 - ->setTransactionType(PhabricatorCalendarEventTransaction::TYPE_INVITE) 55 - ->setNewValue($new_status); 42 + ->setTransactionType($xaction_type) 43 + ->setNewValue(true); 56 44 57 45 $editor = id(new PhabricatorCalendarEventEditor()) 58 46 ->setActor($viewer) ··· 68 56 } 69 57 } 70 58 71 - if (($action == self::ACTION_JOIN && !$is_attending) 72 - || $action == self::ACTION_ACCEPT) { 59 + if ($is_join) { 73 60 $title = pht('Join Event'); 74 61 $paragraph = pht('Would you like to join this event?'); 75 62 $submit = pht('Join');
+40
src/applications/calendar/editor/PhabricatorCalendarEventEditor.php
··· 68 68 $types[] = PhabricatorCalendarEventTransaction::TYPE_INVITE; 69 69 $types[] = PhabricatorCalendarEventTransaction::TYPE_ALL_DAY; 70 70 $types[] = PhabricatorCalendarEventTransaction::TYPE_ICON; 71 + $types[] = PhabricatorCalendarEventTransaction::TYPE_ACCEPT; 72 + $types[] = PhabricatorCalendarEventTransaction::TYPE_DECLINE; 71 73 72 74 $types[] = PhabricatorCalendarEventTransaction::TYPE_RECURRING; 73 75 $types[] = PhabricatorCalendarEventTransaction::TYPE_FREQUENCY; ··· 104 106 return (int)$object->getIsAllDay(); 105 107 case PhabricatorCalendarEventTransaction::TYPE_ICON: 106 108 return $object->getIcon(); 109 + case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: 110 + case PhabricatorCalendarEventTransaction::TYPE_DECLINE: 111 + $actor_phid = $this->getActingAsPHID(); 112 + return $object->getUserInviteStatus($actor_phid); 107 113 case PhabricatorCalendarEventTransaction::TYPE_INVITE: 108 114 $map = $xaction->getNewValue(); 109 115 $phids = array_keys($map); ··· 136 142 case PhabricatorCalendarEventTransaction::TYPE_INVITE: 137 143 case PhabricatorCalendarEventTransaction::TYPE_ICON: 138 144 return $xaction->getNewValue(); 145 + case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: 146 + return PhabricatorCalendarEventInvitee::STATUS_ATTENDING; 147 + case PhabricatorCalendarEventTransaction::TYPE_DECLINE: 148 + return PhabricatorCalendarEventInvitee::STATUS_DECLINED; 139 149 case PhabricatorCalendarEventTransaction::TYPE_ALL_DAY: 140 150 return (int)$xaction->getNewValue(); 141 151 case PhabricatorCalendarEventTransaction::TYPE_RECURRENCE_END_DATE: ··· 181 191 $object->setIcon($xaction->getNewValue()); 182 192 return; 183 193 case PhabricatorCalendarEventTransaction::TYPE_INVITE: 194 + case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: 195 + case PhabricatorCalendarEventTransaction::TYPE_DECLINE: 184 196 return; 185 197 } 186 198 ··· 223 235 } 224 236 $object->attachInvitees($invitees); 225 237 return; 238 + case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: 239 + case PhabricatorCalendarEventTransaction::TYPE_DECLINE: 240 + $acting_phid = $this->getActingAsPHID(); 241 + 242 + $invitees = $object->getInvitees(); 243 + $invitees = mpull($invitees, null, 'getInviteePHID'); 244 + 245 + $invitee = idx($invitees, $acting_phid); 246 + if (!$invitee) { 247 + $invitee = id(new PhabricatorCalendarEventInvitee()) 248 + ->setEventPHID($object->getPHID()) 249 + ->setInviteePHID($acting_phid) 250 + ->setInviterPHID($acting_phid); 251 + $invitees[$acting_phid] = $invitee; 252 + } 253 + 254 + $invitee 255 + ->setStatus($xaction->getNewValue()) 256 + ->save(); 257 + 258 + $object->attachInvitees($invitees); 259 + return; 226 260 } 227 261 228 262 return parent::applyCustomExternalTransaction($object, $xaction); ··· 251 285 // For these kinds of changes, we need to invalidate the availabilty 252 286 // caches for all attendees. 253 287 $invalidate_all = true; 288 + break; 289 + 290 + case PhabricatorCalendarEventTransaction::TYPE_ACCEPT: 291 + case PhabricatorCalendarEventTransaction::TYPE_DECLINE: 292 + $acting_phid = $this->getActingAsPHID(); 293 + $invalidate_phids[$acting_phid] = $acting_phid; 254 294 break; 255 295 case PhabricatorCalendarEventTransaction::TYPE_INVITE: 256 296 foreach ($xaction->getNewValue() as $phid => $ignored) {
+21
src/applications/calendar/storage/PhabricatorCalendarEventTransaction.php
··· 11 11 const TYPE_ALL_DAY = 'calendar.allday'; 12 12 const TYPE_ICON = 'calendar.icon'; 13 13 const TYPE_INVITE = 'calendar.invite'; 14 + const TYPE_ACCEPT = 'calendar.accept'; 15 + const TYPE_DECLINE = 'calendar.decline'; 14 16 15 17 const TYPE_RECURRING = 'calendar.recurring'; 16 18 const TYPE_FREQUENCY = 'calendar.frequency'; 17 19 const TYPE_RECURRENCE_END_DATE = 'calendar.recurrenceenddate'; 20 + 18 21 19 22 const MAILTAG_RESCHEDULE = 'calendar-reschedule'; 20 23 const MAILTAG_CONTENT = 'calendar-content'; ··· 163 166 '%s reinstated this event.', 164 167 $this->renderHandleLink($author_phid)); 165 168 } 169 + case self::TYPE_ACCEPT: 170 + return pht( 171 + '%s is attending this event.', 172 + $this->renderHandleLink($author_phid)); 173 + case self::TYPE_DECLINE: 174 + return pht( 175 + '%s declined this event.', 176 + $this->renderHandleLink($author_phid)); 166 177 case self::TYPE_INVITE: 167 178 $text = null; 168 179 ··· 363 374 $this->renderHandleLink($author_phid), 364 375 $this->renderHandleLink($object_phid)); 365 376 } 377 + case self::TYPE_ACCEPT: 378 + return pht( 379 + '%s is attending %s.', 380 + $this->renderHandleLink($author_phid), 381 + $this->renderHandleLink($object_phid)); 382 + case self::TYPE_DECLINE: 383 + return pht( 384 + '%s declined %s.', 385 + $this->renderHandleLink($author_phid), 386 + $this->renderHandleLink($object_phid)); 366 387 case self::TYPE_INVITE: 367 388 $text = null; 368 389