Implement ctag and etag in ContactsInteraction

Signed-off-by: Georg Ehrke <developer@georgehrke.com>
This commit is contained in:
Georg Ehrke 2020-05-07 16:32:56 +02:00 committed by backportbot[bot]
parent 76334c4c90
commit d1909526fc
3 changed files with 28 additions and 3 deletions

View File

@ -130,8 +130,8 @@ class AddressBook extends ExternalAddressBook implements IACL {
/** /**
* @inheritDoc * @inheritDoc
*/ */
public function getLastModified() { public function getLastModified(): ?int {
throw new NotImplemented(); return $this->mapper->findLastUpdatedForUserId($this->getUid());
} }
/** /**
@ -149,6 +149,7 @@ class AddressBook extends ExternalAddressBook implements IACL {
'principaluri' => $this->principalUri, 'principaluri' => $this->principalUri,
'{DAV:}displayname' => $this->l10n->t('Recently contacted'), '{DAV:}displayname' => $this->l10n->t('Recently contacted'),
'{' . Plugin::NS_OWNCLOUD . '}read-only' => true, '{' . Plugin::NS_OWNCLOUD . '}read-only' => true,
'{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0),
]; ];
} }

View File

@ -95,7 +95,7 @@ class Card implements ICard, IACL {
* @inheritDoc * @inheritDoc
*/ */
public function getETag(): ?string { public function getETag(): ?string {
return null; return '"' . md5((string) $this->getLastModified()) . '"';
} }
/** /**

View File

@ -104,6 +104,30 @@ class RecentContactMapper extends QBMapper {
return $this->findEntities($select); 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 { public function cleanUp(int $olderThan): void {
$qb = $this->db->getQueryBuilder(); $qb = $this->db->getQueryBuilder();