From c56f0211adbe32419d27d5caccb3778e9c4bbe87 Mon Sep 17 00:00:00 2001 From: Torben Dannhauer Date: Mon, 22 Jun 2026 22:23:36 +0200 Subject: [PATCH] fix(nag): add completed filter to ActiveSync listUids API Extend tasks/listUids with an optional Nag::VIEW_* completed filter and add isComplete() for ActiveSync incomplete-task filtering. --- lib/Api.php | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/lib/Api.php b/lib/Api.php index 69393dc..13fb456 100644 --- a/lib/Api.php +++ b/lib/Api.php @@ -803,7 +803,9 @@ public function path_delete($path) * Returns an array of UIDs for all tasks that the current user is authorized * to see. * - * @param mixed $tasklists The tasklist or an array of taskslists to list. + * @param mixed $tasklists The tasklist or an array of taskslists to list. + * @param integer $completed Which tasks to retrieve. One of the + * Nag::VIEW_* constants. Defaults to all. * * @return array An array of UIDs for all tasks * the user can access. @@ -811,12 +813,16 @@ public function path_delete($path) * @throws Horde_Exception_PermissionDenied * @throws Nag_Exception */ - public function listUids($tasklists = null) + public function listUids($tasklists = null, $completed = null) { if (!isset($GLOBALS['conf']['storage']['driver'])) { throw new Nag_Exception(_("Not configured")); } + if ($completed === null) { + $completed = Nag::VIEW_ALL; + } + if (empty($tasklists)) { $tasklists = Nag::getSyncLists(); } else { @@ -833,7 +839,7 @@ public function listUids($tasklists = null) $tasks = Nag::listTasks( [ 'tasklists' => $tasklists, - 'completed' => Nag::VIEW_ALL, + 'completed' => $completed, 'include_history' => false] ); $uids = []; @@ -845,6 +851,31 @@ public function listUids($tasklists = null) return $uids; } + /** + * Returns whether the specified task is marked complete. + * + * @param string $uid The task uid. + * @param string $tasklist The tasklist id, or null to search sync lists. + * + * @return boolean + */ + public function isComplete($uid, $tasklist = null) + { + if ($tasklist === null) { + foreach (Nag::getSyncLists() as $list) { + try { + return Nag::getTask($list, $uid)->completed; + } catch (Horde_Exception $e) { + continue; + } + } + + return false; + } + + return Nag::getTask($tasklist, $uid)->completed; + } + /** * Returns an array of UIDs for tasks that have had $action happen since * $timestamp.