fix: partial fix to allow list tasks in ios reminders app (#2717)
All checks were successful
continuous-integration/drone/push Build is passing

This PR introduces a partial fix for the CalDAV task listing bug (#753) when handling PROPFIND requests with `Depth: 1`, improving task visibility in the iOS Reminders app.

Notes:
* This might make Thunderbird somewhat usable when interacting with tasks using the `/dav/projects/{id} url`.
* This does not fully resolve the issue where the Reminders app will only display the last project after some time when adding the URL.

This is my first time working with Golang and CalDAV, so I’d really appreciate any feedback or suggestions on the code structure, style, or any improvements I could make.

Co-authored-by: JD <43763092+jdw1023@users.noreply.github.com>
Reviewed-on: #2717
Reviewed-by: konrad <k@knt.li>
Co-authored-by: jd <jd@noreply.kolaente.dev>
Co-committed-by: jd <jd@noreply.kolaente.dev>
This commit is contained in:
jd 2024-09-28 09:06:32 +00:00 committed by konrad
parent 4d8c957f75
commit 84dbc5fd84

View File

@ -52,7 +52,7 @@ type VikunjaCaldavProjectStorage struct {
}
// GetResources returns either all projects, links to the principal, or only one project, depending on the request
func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, _ bool) ([]data.Resource, error) {
func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, withChildren bool) ([]data.Resource, error) {
// It looks like we need to have the same handler for returning both the calendar home set and the user principal
// Since the client seems to ignore the whatever is being returned in the first request and just makes a second one
@ -92,6 +92,24 @@ func (vcls *VikunjaCaldavProjectStorage) GetResources(rpath string, _ bool) ([]d
}
r := data.NewResource(rpath, &rr)
r.Name = vcls.project.Title
// If the request is withChildren (Depth: 1), we need to return all tasks of the project
if withChildren {
resources := []data.Resource{r}
// Check if there are tasks to iterate over
if vcls.project.Tasks != nil {
for i := range vcls.project.Tasks {
taskResource := VikunjaProjectResourceAdapter{
project: vcls.project,
task: &vcls.project.Tasks[i].Task,
isCollection: false,
}
addTaskResource(&vcls.project.Tasks[i].Task, &taskResource, &resources)
}
}
return resources, nil
}
return []data.Resource{r}, nil
}
@ -163,9 +181,7 @@ func (vcls *VikunjaCaldavProjectStorage) GetResourcesByList(rpaths []string) (re
rr := VikunjaProjectResourceAdapter{
task: t,
}
r := data.NewResource(getTaskURL(t), &rr)
r.Name = t.Title
resources = append(resources, r)
addTaskResource(t, &rr, &resources)
}
return
@ -671,3 +687,9 @@ func (vcls *VikunjaCaldavProjectStorage) getProjectRessource(isCollection bool)
return
}
func addTaskResource(task *models.Task, rr *VikunjaProjectResourceAdapter, resources *[]data.Resource) {
taskResourceInstance := data.NewResource(getTaskURL(task), rr)
taskResourceInstance.Name = task.Title
*resources = append(*resources, taskResourceInstance)
}