summaryrefslogtreecommitdiffstats
path: root/apps/contactsinteraction
diff options
context:
space:
mode:
authorGeorg Ehrke <developer@georgehrke.com>2020-05-07 16:32:56 +0200
committerGeorg Ehrke <developer@georgehrke.com>2020-05-07 16:32:56 +0200
commitee0019cdf56e96d95599fc77b16a96695164049c (patch)
tree60de78edd3353d6cb1a78e479cfc05ffe7d4ef2b /apps/contactsinteraction
parent35a506d50b52bf7440ccb3e1b015da0319103c45 (diff)
downloadnextcloud-server-ee0019cdf56e96d95599fc77b16a96695164049c.tar.gz
nextcloud-server-ee0019cdf56e96d95599fc77b16a96695164049c.zip
Implement ctag and etag in ContactsInteraction
Signed-off-by: Georg Ehrke <developer@georgehrke.com>
Diffstat (limited to 'apps/contactsinteraction')
-rw-r--r--apps/contactsinteraction/lib/AddressBook.php5
-rw-r--r--apps/contactsinteraction/lib/Card.php2
-rw-r--r--apps/contactsinteraction/lib/Db/RecentContactMapper.php24
3 files changed, 28 insertions, 3 deletions
diff --git a/apps/contactsinteraction/lib/AddressBook.php b/apps/contactsinteraction/lib/AddressBook.php
index e8479cb186a..3e581c93021 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 6285025f1eb..2cacd7ad546 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 18a5bf6cedc..19cd30ea701 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();