Add a Jitsi video conference to events on Core calendars
The event editor offers "Add Video Conference" on the calendars of a Federated Computer Core. It makes a room with an unguessable name, like BraveOttersSing-k3f9x2m7, on the Core's Jitsi at jitsi.<CORE_DOMAIN>, and shows its link with Copy and Remove buttons. The link goes at the end of the event's notes, which reach everyone invited whatever their mail app, and in an RFC 7986 CONFERENCE property. Saving puts the link back in the notes if it was taken out, and "All events" copies the conference to the whole series. Existing conferences are found in CONFERENCE, or as Jitsi links in the notes or location, so the editor doesn't offer a second one and the popover shows a Join button. The popover now keeps showing a place in the location alongside a meeting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,327 @@
|
||||
/* test-jitsi.c
|
||||
*
|
||||
* Copyright (C) 2026 David Young <david@federated.computer>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <glib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "gcal-event.h"
|
||||
#include "gcal-jitsi.h"
|
||||
#include "gcal-stub-calendar.h"
|
||||
#include "gcal-utils.h"
|
||||
|
||||
#define ROOM_URL "https://jitsi.example.com/BraveOttersSing-k3f9x2m7"
|
||||
|
||||
#define STUB_EVENT(extra) \
|
||||
"BEGIN:VEVENT\n" \
|
||||
"SUMMARY:Stub event\n" \
|
||||
"UID:example@uid\n" \
|
||||
"DTSTAMP:19970114T170000Z\n" \
|
||||
"DTSTART:20180714T170000Z\n" \
|
||||
"DTEND:20180715T035959Z\n" \
|
||||
extra \
|
||||
"END:VEVENT\n"
|
||||
|
||||
static GcalEvent *
|
||||
create_event_for_string (const gchar *string)
|
||||
{
|
||||
g_autoptr (ECalComponent) component = NULL;
|
||||
g_autoptr (GcalCalendar) calendar = NULL;
|
||||
g_autoptr (GError) error = NULL;
|
||||
GcalEvent *event;
|
||||
|
||||
component = e_cal_component_new_from_string (string);
|
||||
g_assert_nonnull (component);
|
||||
|
||||
calendar = gcal_stub_calendar_new (NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
event = gcal_event_new (calendar, component, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
return event;
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
static void
|
||||
jitsi_room_name (void)
|
||||
{
|
||||
g_autoptr (GHashTable) names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
||||
|
||||
for (gint i = 0; i < 1000; i++)
|
||||
{
|
||||
g_autofree gchar *name = gcal_jitsi_generate_room_name ();
|
||||
g_autofree gchar *url = NULL;
|
||||
const gchar *dash;
|
||||
|
||||
g_assert_nonnull (name);
|
||||
|
||||
/* Three capitalized words, a dash and a suffix of 8 */
|
||||
g_assert_true (g_regex_match_simple ("^([A-Z][a-z]+){3}-[a-km-np-z2-9]{8}$", name, 0, 0));
|
||||
|
||||
dash = strchr (name, '-');
|
||||
g_assert_cmpuint (strlen (dash + 1), ==, 8);
|
||||
|
||||
/* Room names are safe in a URL as they are */
|
||||
url = gcal_jitsi_build_room_url ("https://jitsi.example.com", name);
|
||||
g_assert_true (g_str_has_suffix (url, name));
|
||||
g_assert_true (gcal_jitsi_is_room_url (url));
|
||||
|
||||
g_assert_true (g_hash_table_add (names, g_steal_pointer (&name)));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_build_room_url (void)
|
||||
{
|
||||
g_autofree gchar *url = NULL;
|
||||
g_autofree gchar *slash_url = NULL;
|
||||
g_autofree gchar *escaped_url = NULL;
|
||||
|
||||
url = gcal_jitsi_build_room_url ("https://jitsi.example.com", "BraveOttersSing-k3f9x2m7");
|
||||
g_assert_cmpstr (url, ==, ROOM_URL);
|
||||
|
||||
slash_url = gcal_jitsi_build_room_url ("https://jitsi.example.com/", "BraveOttersSing-k3f9x2m7");
|
||||
g_assert_cmpstr (slash_url, ==, ROOM_URL);
|
||||
|
||||
escaped_url = gcal_jitsi_build_room_url ("https://jitsi.example.com", "Team meeting/1");
|
||||
g_assert_cmpstr (escaped_url, ==, "https://jitsi.example.com/Team%20meeting%2F1");
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_is_room_url (void)
|
||||
{
|
||||
g_assert_true (gcal_jitsi_is_room_url (ROOM_URL));
|
||||
g_assert_true (gcal_jitsi_is_room_url ("https://JITSI.Example.Org/Room"));
|
||||
g_assert_true (gcal_jitsi_is_room_url ("https://meet.jit.si/SomeRoom"));
|
||||
g_assert_true (gcal_jitsi_is_room_url ("https://8x8.vc/vpaas-magic-cookie-123/Room"));
|
||||
|
||||
/* A server, but not a room on it */
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://jitsi.example.com"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://jitsi.example.com/"));
|
||||
|
||||
/* Not Jitsi */
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://meet.google.com/abc-defg-hij"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://example.com/jitsi/Room"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://notjitsi.example.com/Room"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("https://jitsi/Room"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("ftp://jitsi.example.com/Room"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("jitsi.example.com/Room"));
|
||||
g_assert_false (gcal_jitsi_is_room_url ("Room 101"));
|
||||
g_assert_false (gcal_jitsi_is_room_url (""));
|
||||
g_assert_false (gcal_jitsi_is_room_url (NULL));
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_find_room_url (void)
|
||||
{
|
||||
struct {
|
||||
const gchar *text;
|
||||
const gchar *url;
|
||||
} texts[] = {
|
||||
{ ROOM_URL, ROOM_URL },
|
||||
{ "Join the video conference: " ROOM_URL, ROOM_URL },
|
||||
{ "Agenda\n\nJoin the video conference: " ROOM_URL "\n", ROOM_URL },
|
||||
{ "Meet at " ROOM_URL ". Bring notes.", ROOM_URL },
|
||||
{ "(" ROOM_URL ")", ROOM_URL },
|
||||
{ "<a href=\"" ROOM_URL "\">Join</a>", ROOM_URL },
|
||||
{ "<" ROOM_URL ">", ROOM_URL },
|
||||
{ "See https://example.com/agenda, then " ROOM_URL, ROOM_URL },
|
||||
{ "Rejoignez la visioconférence : https://meet.jit.si/Équipe", "https://meet.jit.si/Équipe" },
|
||||
{ "https://meet.google.com/abc-defg-hij", NULL },
|
||||
{ "https://jitsi.example.com/", NULL },
|
||||
{ "http", NULL },
|
||||
{ "", NULL },
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
for (gsize i = 0; i < G_N_ELEMENTS (texts); i++)
|
||||
{
|
||||
g_autofree gchar *url = gcal_jitsi_find_room_url (texts[i].text);
|
||||
|
||||
g_assert_cmpstr (url, ==, texts[i].url);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_find_event_conference (void)
|
||||
{
|
||||
struct {
|
||||
const gchar *event;
|
||||
const gchar *url;
|
||||
} events[] = {
|
||||
{ STUB_EVENT (""), NULL },
|
||||
{ STUB_EVENT ("LOCATION:Room 101\n"), NULL },
|
||||
{ STUB_EVENT ("LOCATION:https://meet.google.com/abc-defg-hij\n"), NULL },
|
||||
{ STUB_EVENT ("LOCATION:" ROOM_URL "\n"), ROOM_URL },
|
||||
{ STUB_EVENT ("DESCRIPTION:Agenda\\n\\nJoin the video conference: " ROOM_URL "\n"), ROOM_URL },
|
||||
{ STUB_EVENT ("CONFERENCE;VALUE=URI;FEATURE=VIDEO:" ROOM_URL "\n"), ROOM_URL },
|
||||
|
||||
/* Any conference in the CONFERENCE property comes first */
|
||||
{ STUB_EVENT ("CONFERENCE;VALUE=URI;FEATURE=VIDEO:https://zoom.us/j/123\n"
|
||||
"DESCRIPTION:" ROOM_URL "\n"), "https://zoom.us/j/123" },
|
||||
{ STUB_EVENT ("DESCRIPTION:https://meet.jit.si/Other\n"
|
||||
"LOCATION:" ROOM_URL "\n"), "https://meet.jit.si/Other" },
|
||||
};
|
||||
|
||||
for (gsize i = 0; i < G_N_ELEMENTS (events); i++)
|
||||
{
|
||||
g_autoptr (GcalEvent) event = create_event_for_string (events[i].event);
|
||||
g_autofree gchar *url = gcal_jitsi_find_event_conference (event);
|
||||
|
||||
g_assert_cmpstr (url, ==, events[i].url);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_add_to_description (void)
|
||||
{
|
||||
g_autofree gchar *empty = NULL;
|
||||
g_autofree gchar *null = NULL;
|
||||
g_autofree gchar *notes = NULL;
|
||||
g_autofree gchar *trailing = NULL;
|
||||
g_autofree gchar *again = NULL;
|
||||
|
||||
empty = gcal_jitsi_add_to_description ("", ROOM_URL);
|
||||
g_assert_cmpstr (empty, ==, "Join the video conference: " ROOM_URL);
|
||||
|
||||
null = gcal_jitsi_add_to_description (NULL, ROOM_URL);
|
||||
g_assert_cmpstr (null, ==, "Join the video conference: " ROOM_URL);
|
||||
|
||||
notes = gcal_jitsi_add_to_description ("Agenda", ROOM_URL);
|
||||
g_assert_cmpstr (notes, ==, "Agenda\n\nJoin the video conference: " ROOM_URL);
|
||||
|
||||
trailing = gcal_jitsi_add_to_description ("Agenda\n\n \n", ROOM_URL);
|
||||
g_assert_cmpstr (trailing, ==, "Agenda\n\nJoin the video conference: " ROOM_URL);
|
||||
|
||||
/* Only once, however often the event is saved */
|
||||
again = gcal_jitsi_add_to_description (notes, ROOM_URL);
|
||||
g_assert_cmpstr (again, ==, notes);
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_remove_from_description (void)
|
||||
{
|
||||
struct {
|
||||
const gchar *description;
|
||||
const gchar *result;
|
||||
} descriptions[] = {
|
||||
{ "Join the video conference: " ROOM_URL, "" },
|
||||
{ "Agenda\n\nJoin the video conference: " ROOM_URL, "Agenda" },
|
||||
{ "Agenda\n\nJoin the video conference: " ROOM_URL "\n", "Agenda" },
|
||||
{ "Agenda\n\nJoin the video conference: " ROOM_URL "\n\nBring notes", "Agenda\n\nBring notes" },
|
||||
{ "Agenda\nJoin the video conference: " ROOM_URL "\nBring notes", "Agenda\nBring notes" },
|
||||
{ "Agenda\n\nhttps://meet.jit.si/Other", "Agenda\n\nhttps://meet.jit.si/Other" },
|
||||
{ "", "" },
|
||||
{ NULL, "" },
|
||||
};
|
||||
|
||||
for (gsize i = 0; i < G_N_ELEMENTS (descriptions); i++)
|
||||
{
|
||||
g_autofree gchar *result = gcal_jitsi_remove_from_description (descriptions[i].description, ROOM_URL);
|
||||
|
||||
g_assert_cmpstr (result, ==, descriptions[i].result);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_add_and_remove_conference (void)
|
||||
{
|
||||
g_autoptr (GcalEvent) event = NULL;
|
||||
g_autoptr (GcalEvent) saved = NULL;
|
||||
g_autofree gchar *string = NULL;
|
||||
g_autofree gchar *url = NULL;
|
||||
|
||||
event = create_event_for_string (STUB_EVENT ("DESCRIPTION:Agenda\n"
|
||||
"LOCATION:Room 101\n"));
|
||||
|
||||
gcal_jitsi_add_conference (event, ROOM_URL);
|
||||
|
||||
url = gcal_event_dup_conference_url (event);
|
||||
g_assert_cmpstr (url, ==, ROOM_URL);
|
||||
g_assert_cmpstr (gcal_event_get_description (event), ==, "Agenda\n\nJoin the video conference: " ROOM_URL);
|
||||
g_assert_cmpstr (gcal_event_get_location (event), ==, "Room 101");
|
||||
|
||||
/* Saved and loaded again, the editor finds the same conference */
|
||||
string = e_cal_component_get_as_string (gcal_event_get_component (event));
|
||||
saved = create_event_for_string (string);
|
||||
|
||||
g_clear_pointer (&url, g_free);
|
||||
url = gcal_jitsi_find_event_conference (saved);
|
||||
g_assert_cmpstr (url, ==, ROOM_URL);
|
||||
g_assert_cmpstr (gcal_event_get_description (saved), ==, gcal_event_get_description (event));
|
||||
|
||||
/* Saving it again doesn't add the link twice */
|
||||
gcal_jitsi_ensure_description (saved);
|
||||
g_assert_cmpstr (gcal_event_get_description (saved), ==, gcal_event_get_description (event));
|
||||
|
||||
gcal_jitsi_remove_conference (saved, ROOM_URL);
|
||||
|
||||
g_assert_null (gcal_event_dup_conference_url (saved));
|
||||
g_assert_null (gcal_jitsi_find_event_conference (saved));
|
||||
g_assert_cmpstr (gcal_event_get_description (saved), ==, "Agenda");
|
||||
g_assert_cmpstr (gcal_event_get_location (saved), ==, "Room 101");
|
||||
}
|
||||
|
||||
static void
|
||||
jitsi_ensure_description (void)
|
||||
{
|
||||
g_autoptr (GcalEvent) edited = NULL;
|
||||
g_autoptr (GcalEvent) other = NULL;
|
||||
g_autoptr (GcalEvent) plain = NULL;
|
||||
|
||||
/* Someone took the link out of the description, but not the conference */
|
||||
edited = create_event_for_string (STUB_EVENT ("DESCRIPTION:Agenda\n"
|
||||
"CONFERENCE;VALUE=URI;FEATURE=AUDIO,VIDEO:" ROOM_URL "\n"));
|
||||
gcal_jitsi_ensure_description (edited);
|
||||
g_assert_cmpstr (gcal_event_get_description (edited), ==, "Agenda\n\nJoin the video conference: " ROOM_URL);
|
||||
|
||||
/* Other apps' conferences are left alone */
|
||||
other = create_event_for_string (STUB_EVENT ("DESCRIPTION:Agenda\n"
|
||||
"CONFERENCE;VALUE=URI;FEATURE=VIDEO:https://zoom.us/j/123\n"));
|
||||
gcal_jitsi_ensure_description (other);
|
||||
g_assert_cmpstr (gcal_event_get_description (other), ==, "Agenda");
|
||||
|
||||
plain = create_event_for_string (STUB_EVENT ("DESCRIPTION:Agenda\n"));
|
||||
gcal_jitsi_ensure_description (plain);
|
||||
g_assert_cmpstr (gcal_event_get_description (plain), ==, "Agenda");
|
||||
}
|
||||
|
||||
/*********************************************************************************************************************/
|
||||
|
||||
gint
|
||||
main (gint argc,
|
||||
gchar *argv[])
|
||||
{
|
||||
/* The descriptions are checked in English */
|
||||
g_setenv ("LANGUAGE", "C", TRUE);
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/jitsi/room-name", jitsi_room_name);
|
||||
g_test_add_func ("/jitsi/build-room-url", jitsi_build_room_url);
|
||||
g_test_add_func ("/jitsi/is-room-url", jitsi_is_room_url);
|
||||
g_test_add_func ("/jitsi/find-room-url", jitsi_find_room_url);
|
||||
g_test_add_func ("/jitsi/find-event-conference", jitsi_find_event_conference);
|
||||
g_test_add_func ("/jitsi/add-to-description", jitsi_add_to_description);
|
||||
g_test_add_func ("/jitsi/remove-from-description", jitsi_remove_from_description);
|
||||
g_test_add_func ("/jitsi/add-and-remove-conference", jitsi_add_and_remove_conference);
|
||||
g_test_add_func ("/jitsi/ensure-description", jitsi_ensure_description);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
Reference in New Issue
Block a user