Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send iCal notifications task #452

Closed

Conversation

paulandm
Copy link
Contributor

Send iCal notifications task

Copy link
Collaborator

@jrchamp jrchamp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to incorporate some of the Moodle code standards fixes in my suggestions, but I don't think I was able to get them all. I'll try to commit them to see what remains.

Comment on lines 173 to 242
$hostaddress = str_replace('http://', '', $CFG->wwwroot);
$hostaddress = str_replace('https://', '', $hostaddress);

$ev = new \iCalendar_event; // To export in ical format.
$ev->add_property('uid', $zoom_event->id.'@'.$hostaddress);

// Set iCal event summary from event name.
$ev->add_property('summary', format_string($zoom_event->name, true, ['context' => $cal_event->context]));

$ev->add_property('description', html_to_text($description, 0));

$ev->add_property('class', 'PUBLIC'); // PUBLIC / PRIVATE / CONFIDENTIAL

// Since we don't cater for modified invites, the created and last modified dates are the same
$ev->add_property('created', \Bennu::timestamp_to_datetime($zoom_event->timemodified));
$ev->add_property('last-modified', \Bennu::timestamp_to_datetime($zoom_event->timemodified));

$no_reply_user = \core_user::get_noreply_user();
$ev->add_property('organizer', 'mailto:' . $no_reply_user->email, array('cn' => $this->get_lms_site_name()));
// Need to strip out the double quotations around the 'organizer' values - probably a bug in the core code
$ev->properties['ORGANIZER'][0]->value = substr($ev->properties['ORGANIZER'][0]->value, 1, -1);
$ev->properties['ORGANIZER'][0]->parameters['CN'] = substr($ev->properties['ORGANIZER'][0]->parameters['CN'], 1, -1);

$ev->add_property('dtstamp', \Bennu::timestamp_to_datetime()); // now
if ($zoom_event->timeduration > 0) {
//dtend is better than duration, because it works in Microsoft Outlook and works better in Korganizer
$ev->add_property('dtstart', \Bennu::timestamp_to_datetime($zoom_event->timestart)); // when event starts.
$ev->add_property('dtend', \Bennu::timestamp_to_datetime($zoom_event->timestart + $zoom_event->timeduration));
} else if ($zoom_event->timeduration == 0) {
// When no duration is present, the event is instantaneous event, ex - Due date of a module.
// Moodle doesn't support all day events yet. See MDL-56227.
$ev->add_property('dtstart', \Bennu::timestamp_to_datetime($zoom_event->timestart));
$ev->add_property('dtend', \Bennu::timestamp_to_datetime($zoom_event->timestart));
} else {
// This can be used to represent all day events in future.
throw new \coding_exception("Negative duration is not supported yet.");
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like most of these are already handled by the zoom_helper_icalendar_event() helper function. I would be interested to know if any of the properties that are not being set by the helper function are necessary (because we may want to consider adding them to the helper function itself).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regression testing done and no issues found

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrchamp Will do some tests to see if the zoom_helper_icalendar_event() helper function is sufficient.

classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
classes/task/send_ical_notifications.php Outdated Show resolved Hide resolved
mtrace('[Zoom ical Notifications] Checking to see if zoom ID ' . $zoom->id . ' was notified before.');
$executiontime = $this->get_notification_execution_time($zoom->id);
// Only run if it hasn't run before.
if ($executiontime === 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only sending when there is no entry in the notifications table, then this notifications task will never notify users about updated event information. Probably need to change this to something like $executiontime < $lasttaskcompletiontime not that that variable exists, but it's pseudo-code.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @jrchamp , yes, for our purposes we had that buffer time period (think it's 15 minutes or so) just after the Zoom activity was created before sending the ical invitation. However, please feel free to add this functionality for updated events as well. Please let me know if you require more information.

Copy link
Contributor Author

@paulandm paulandm Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @jrchamp
I hope you are doing well. I'm finally in the process of looking at this again. I'm in the process of creating a brand new PR for this ical notification functionality, but in the meantime I'd thought I try to give a better answer to your question above.
We give a buffer before sending out the ical event to avoid sending multiple event while the user is maybe making some last minute adjustments to the Zoom event.
After that initial buffer we thought it might not make sense to send additional updates, since we wouldn't have access to each users ical invite and it would result in another additional/duplicate invite being sent. But maybe that is unavoidable and would be the appropriate action to take.

@jrchamp jrchamp added the enhancement Adds new functionality label Jan 26, 2023
paulandm and others added 4 commits January 26, 2023 14:16
Send iCal notifications task
Make use of new 'registration' instead of 'registration_required'.
Fix task name catalog retrieval.
@jrchamp jrchamp force-pushed the OpenCollab-ical_email_feature branch from 3b17662 to bc22b3e Compare January 26, 2023 22:44
Comment on lines +113 to +117
$record = new \stdClass();
$record->zoomid = $zoomid;
$record->executiontime = time();

$DB->insert_record('zoom_ical_notifications', $record);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This handles inserting new records, but we may need it to be able to update existing records.

Copy link
Contributor Author

@paulandm paulandm Oct 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrchamp The same logic applies here in the sense that since we wouldn't have access to each user's ical object (after it has been sent to them) we wouldn't necessarily want sent an additional ical invite. But maybe that is unavoidable and the better approach.

Comment on lines +77 to +80
$sql = 'SELECT *
FROM {zoom}
WHERE timemodified >= ' . (time() - 3600) . '
AND timemodified <= ' . (time() - 600);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the goal here is to notify users about events, we may want to check for Zoom events instead and index the notifications based on the event IDs instead of the zoom IDs.

@jrchamp jrchamp added the help wanted We need your help to make this possible label Aug 3, 2023
@paulandm
Copy link
Contributor Author

paulandm commented Oct 2, 2024

This PR can be closed.
Version 2 of this work moved to separate PR:
#623

@jrchamp jrchamp closed this Oct 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Adds new functionality help wanted We need your help to make this possible
Projects
Status: No status
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants