Skip to content

Commit b6d80d0

Browse files
Merge pull request #743 from SebastianKrupinski/fix/send-reply-on-event-creation
fix: send participation reply on fresh event
2 parents 93f212c + 49d53f1 commit b6d80d0

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
@@ -246,16 +246,29 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null): array
246246
$baseCalendar = $oldCalendar;
247247
}
248248

249+
// Check if the user is the organizer
249250
if (in_array($eventInfo['organizer'], $userHref)) {
250251
return $this->parseEventForOrganizer($baseCalendar, $eventInfo, $oldEventInfo);
251-
} elseif ($oldCalendar) {
252-
// We need to figure out if the user is an attendee, but we're only
253-
// doing so if there's an oldCalendar, because we only want to
254-
// process updates, not creation of new events.
255-
foreach ($eventInfo['attendees'] as $attendee) {
256-
if (in_array($attendee['href'], $userHref)) {
252+
}
253+
254+
// Check if the user is an attendee
255+
foreach ($eventInfo['attendees'] as $attendee) {
256+
if (in_array($attendee['href'], $userHref)) {
257+
// If this is a event update, we always generate a reply
258+
if ($oldCalendar) {
257259
return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
258260
}
261+
262+
// If this is a new event, we only generate a reply if the participation status is set
263+
foreach ($attendee['instances'] as $instance) {
264+
if (isset($instance['partstat']) && 'NEEDS-ACTION' !== $instance['partstat']) {
265+
// Attendee has responded (ACCEPTED/DECLINED/TENTATIVE) - generate REPLY
266+
return $this->parseEventForAttendee($baseCalendar, $eventInfo, $oldEventInfo, $attendee['href']);
267+
}
268+
}
269+
270+
// User is attendee but no response to process
271+
break;
259272
}
260273
}
261274

tests/VObject/ITip/BrokerAttendeeReplyTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1198,6 +1198,58 @@ public function testPartyCrasher(): void
11981198
END:VEVENT
11991199
END:VCALENDAR
12001200
1201+
ICS,
1202+
],
1203+
];
1204+
1205+
$this->parse($oldMessage, $newMessage, $expected);
1206+
}
1207+
1208+
public function testNewEventWithReply(): void
1209+
{
1210+
$oldMessage = null;
1211+
1212+
$newMessage = <<<ICS
1213+
BEGIN:VCALENDAR
1214+
VERSION:2.0
1215+
BEGIN:VEVENT
1216+
UID:foobar
1217+
SUMMARY:Team meeting
1218+
SEQUENCE:1
1219+
ORGANIZER;CN=Strunk:mailto:strunk@example.org
1220+
ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1221+
DTSTART:20140716T120000Z
1222+
END:VEVENT
1223+
END:VCALENDAR
1224+
ICS;
1225+
1226+
$version = \Sabre\VObject\Version::VERSION;
1227+
1228+
$expected = [
1229+
[
1230+
'uid' => 'foobar',
1231+
'method' => 'REPLY',
1232+
'component' => 'VEVENT',
1233+
'sender' => 'mailto:one@example.org',
1234+
'senderName' => 'One',
1235+
'recipient' => 'mailto:strunk@example.org',
1236+
'recipientName' => 'Strunk',
1237+
'message' => <<<ICS
1238+
BEGIN:VCALENDAR
1239+
VERSION:2.0
1240+
PRODID:-//Sabre//Sabre VObject $version//EN
1241+
CALSCALE:GREGORIAN
1242+
METHOD:REPLY
1243+
BEGIN:VEVENT
1244+
UID:foobar
1245+
DTSTAMP:**ANY**
1246+
SEQUENCE:1
1247+
DTSTART:20140716T120000Z
1248+
SUMMARY:Team meeting
1249+
ORGANIZER;CN=Strunk:mailto:strunk@example.org
1250+
ATTENDEE;PARTSTAT=ACCEPTED;CN=One:mailto:one@example.org
1251+
END:VEVENT
1252+
END:VCALENDAR
12011253
ICS,
12021254
],
12031255
];

0 commit comments

Comments
 (0)