From d1909526fc47e0973e9b1507f991b1992c7e0dcc Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 7 May 2020 16:32:56 +0200 Subject: [PATCH 1/2] Implement ctag and etag in ContactsInteraction Signed-off-by: Georg Ehrke --- apps/contactsinteraction/lib/AddressBook.php | 5 ++-- apps/contactsinteraction/lib/Card.php | 2 +- .../lib/Db/RecentContactMapper.php | 24 +++++++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/apps/contactsinteraction/lib/AddressBook.php b/apps/contactsinteraction/lib/AddressBook.php index e8479cb186..3e581c9302 100644 --- a/apps/contactsinteraction/lib/AddressBook.php +++ b/apps/contactsinteraction/lib/AddressBook.php @@ -130,8 +130,8 @@ class AddressBook extends ExternalAddressBook implements IACL { /** * @inheritDoc */ - public function getLastModified() { - throw new NotImplemented(); + public function getLastModified(): ?int { + return $this->mapper->findLastUpdatedForUserId($this->getUid()); } /** @@ -149,6 +149,7 @@ class AddressBook extends ExternalAddressBook implements IACL { 'principaluri' => $this->principalUri, '{DAV:}displayname' => $this->l10n->t('Recently contacted'), '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, + '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), ]; } diff --git a/apps/contactsinteraction/lib/Card.php b/apps/contactsinteraction/lib/Card.php index 6285025f1e..2cacd7ad54 100644 --- a/apps/contactsinteraction/lib/Card.php +++ b/apps/contactsinteraction/lib/Card.php @@ -95,7 +95,7 @@ class Card implements ICard, IACL { * @inheritDoc */ public function getETag(): ?string { - return null; + return '"' . md5((string) $this->getLastModified()) . '"'; } /** diff --git a/apps/contactsinteraction/lib/Db/RecentContactMapper.php b/apps/contactsinteraction/lib/Db/RecentContactMapper.php index 18a5bf6ced..19cd30ea70 100644 --- a/apps/contactsinteraction/lib/Db/RecentContactMapper.php +++ b/apps/contactsinteraction/lib/Db/RecentContactMapper.php @@ -104,6 +104,30 @@ class RecentContactMapper extends QBMapper { return $this->findEntities($select); } + /** + * @param string $uid + * @return int|null + */ + public function findLastUpdatedForUserId(string $uid):?int { + $qb = $this->db->getQueryBuilder(); + + $select = $qb + ->select('last_contact') + ->from($this->getTableName()) + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) + ->orderBy('last_contact', 'DESC') + ->setMaxResults(1); + + $cursor = $select->execute(); + $row = $cursor->fetch(); + + if ($row === false) { + return null; + } + + return (int)$row['last_contact']; + } + public function cleanUp(int $olderThan): void { $qb = $this->db->getQueryBuilder(); From e048bf8550a1be1fc46d101ee3c1426ad3d8cfe3 Mon Sep 17 00:00:00 2001 From: Georg Ehrke Date: Thu, 7 May 2020 16:33:36 +0200 Subject: [PATCH 2/2] Rename app-generated to z-app-generated, because macOS Contacts supports only one and will pick the first one alphabetically Signed-off-by: Georg Ehrke --- apps/contactsinteraction/lib/AddressBook.php | 1 - apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/contactsinteraction/lib/AddressBook.php b/apps/contactsinteraction/lib/AddressBook.php index 3e581c9302..55819380b9 100644 --- a/apps/contactsinteraction/lib/AddressBook.php +++ b/apps/contactsinteraction/lib/AddressBook.php @@ -34,7 +34,6 @@ use OCA\DAV\DAV\Sharing\Plugin; use OCP\AppFramework\Db\DoesNotExistException; use OCP\IL10N; use Sabre\DAV\Exception\NotFound; -use Sabre\DAV\Exception\NotImplemented; use Sabre\DAV\PropPatch; use Sabre\DAVACL\ACLTrait; use Sabre\DAVACL\IACL; diff --git a/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php b/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php index 0bd01184eb..ac52a44630 100644 --- a/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php +++ b/apps/dav/lib/CardDAV/Integration/ExternalAddressBook.php @@ -34,7 +34,7 @@ use Sabre\DAV; abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { /** @var string */ - private const PREFIX = 'app-generated'; + private const PREFIX = 'z-app-generated'; /** * @var string