@@ -172,23 +172,49 @@ public class Services.CalDAV.CalDAVClient : Services.CalDAV.WebDAVClient {
172172 < d: sync- token / >
173173 < ical: calendar- color / >
174174 < cal: supported- calendar- component- set / >
175+ < x3: deleted- at xmlns: x3= " http://nextcloud.com/ns" / >
175176 < / d: prop>
176177 < / d: propfind>
177178 " " " ;
178179
179180 var multi_status = yield propfind (source.caldav_data.calendar_home_url, xml, " 1 " , cancellable);
180181
181- // TODO: Implement check for deleted calendars
182+
183+ // Delete CalDAV Generic
184+ var server_urls = new Gee.HashSet<string> ();
185+ foreach (var response in multi_status.responses ()) {
186+ if (response.href != null) {
187+ server_urls.add (get_absolute_url (response.href));
188+ }
189+ }
190+
191+ var local_projects = Services.Store.instance ().get_projects_by_source (source.id);
192+ foreach (var local_project in local_projects) {
193+ if (!server_urls.contains (local_project.calendar_url)) {
194+ Services.Store.instance ().delete_project (local_project);
195+ }
196+ }
182197
183198 foreach (var response in multi_status.responses ()) {
184199 string? href = response.href;
185200
186201 foreach (var propstat in response.propstats ()) {
187- if (propstat.status != Soup.Status.OK) continue;
202+ if (propstat.status != Soup.Status.OK) {
203+ continue;
204+ }
188205
189206 var resourcetype = propstat.get_first_prop_with_tagname (" resourcetype" );
190207 var supported_calendar = propstat.get_first_prop_with_tagname (" supported- calendar- component- set " );
191208
209+ if (is_deleted_calendar (resourcetype)) {
210+ Objects.Project ? project = Services.Store.instance ().get_project_via_url (get_absolute_url (href));
211+ if (project != null) {
212+ Services.Store.instance ().delete_project (project);
213+ }
214+
215+ continue;
216+ }
217+
192218 if (is_vtodo_calendar (resourcetype, supported_calendar)) {
193219 var name = propstat.get_first_prop_with_tagname (" displayname" );
194220
@@ -597,4 +623,12 @@ public class Services.CalDAV.CalDAVClient : Services.CalDAV.WebDAVClient {
597623
598624 return false;
599625 }
600- }
626+
627+ public bool is_deleted_calendar (GXml.DomElement? resourcetype) {
628+ if (resourcetype == null) {
629+ return false;
630+ }
631+
632+ return resourcetype.get_elements_by_tag_name (" deleted- calendar" ).length > 0;
633+ }
634+ }
0 commit comments