Skip to content

Commit 4647f61

Browse files
SebastianKrupinskiphil-davis
authored andcommitted
fix: send participation reply on fresh event
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent c08fd9b commit 4647f61

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

lib/ITip/Broker.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,29 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null)
240240
$baseCalendar = $oldCalendar;
241241
}
242242

243+
// Check if the user is the organizer
243244
if (in_array($eventInfo['organizer'], $userHref)) {
244245
return $this->parseEventForOrganizer($baseCalendar, $eventInfo, $oldEventInfo);
245-
} elseif ($oldCalendar) {
246-
// We need to figure out if the user is an attendee, but we're only
247-
// doing so if there's an oldCalendar, because we only want to
248-
// process updates, not creation of new events.
249-
foreach ($eventInfo['attendees'] as $attendee) {
250-
if (in_array($attendee['href'], $userHref)) {
246+
}
247+
248+
// Check if the user is an attendee
249+
foreach ($eventInfo['attendees'] as $attendee) {
250+
if (in_array($attendee['href'], $userHref)) {
251+
// If this is a event update, we always generate a reply
252+
if ($oldCalendar) {
251253
return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
252254
}
255+
256+
// If this is a new event, we only generate a reply if the participation status is set
257+
foreach ($attendee['instances'] as $instance) {
258+
if (isset($instance['partstat']) && 'NEEDS-ACTION' !== $instance['partstat']) {
259+
// Attendee has responded (ACCEPTED/DECLINED/TENTATIVE) - generate REPLY
260+
return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
261+
}
262+
}
263+
264+
// User is attendee but no response to process
265+
break;
253266
}
254267
}
255268

tests/VObject/ITip/BrokerAttendeeReplyTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,4 +1210,56 @@ public function testPartyCrasher()
12101210

12111211
$this->parse($oldMessage, $newMessage, $expected);
12121212
}
1213+
1214+
public function testNewEventWithReply(): void
1215+
{
1216+
$oldMessage = null;
1217+
1218+
$newMessage = <<<ICS
1219+
BEGIN:VCALENDAR
1220+
VERSION:2.0
1221+
BEGIN:VEVENT
1222+
UID:foobar
1223+
SUMMARY:Team meeting
1224+
SEQUENCE:1
1225+
ORGANIZER;CN=Strunk:mailto:strunk@example.org
1226+
ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1227+
DTSTART:20140716T120000Z
1228+
END:VEVENT
1229+
END:VCALENDAR
1230+
ICS;
1231+
1232+
$version = \Sabre\VObject\Version::VERSION;
1233+
1234+
$expected = [
1235+
[
1236+
'uid' => 'foobar',
1237+
'method' => 'REPLY',
1238+
'component' => 'VEVENT',
1239+
'sender' => 'mailto:one@example.org',
1240+
'senderName' => 'One',
1241+
'recipient' => 'mailto:strunk@example.org',
1242+
'recipientName' => 'Strunk',
1243+
'message' => <<<ICS
1244+
BEGIN:VCALENDAR
1245+
VERSION:2.0
1246+
PRODID:-//Sabre//Sabre VObject $version//EN
1247+
CALSCALE:GREGORIAN
1248+
METHOD:REPLY
1249+
BEGIN:VEVENT
1250+
UID:foobar
1251+
DTSTAMP:**ANY**
1252+
SEQUENCE:1
1253+
DTSTART:20140716T120000Z
1254+
SUMMARY:Team meeting
1255+
ORGANIZER;CN=Strunk:mailto:strunk@example.org
1256+
ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1257+
END:VEVENT
1258+
END:VCALENDAR
1259+
ICS,
1260+
],
1261+
];
1262+
1263+
$this->parse($oldMessage, $newMessage, $expected);
1264+
}
12131265
}

0 commit comments

Comments
 (0)