Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Implement ctag and etag in ContactsInteraction
Signed-off-by: Georg Ehrke <[email protected]>
  • Loading branch information
georgehrke authored and backportbot[bot] committed May 8, 2020
commit d1909526fc47e0973e9b1507f991b1992c7e0dcc
5 changes: 3 additions & 2 deletions apps/contactsinteraction/lib/AddressBook.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ public function childExists($name) {
/**
* @inheritDoc
*/
public function getLastModified() {
throw new NotImplemented();
public function getLastModified(): ?int {
return $this->mapper->findLastUpdatedForUserId($this->getUid());
}

/**
Expand All @@ -149,6 +149,7 @@ public function getProperties($properties) {
'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),
];
}

Expand Down
2 changes: 1 addition & 1 deletion apps/contactsinteraction/lib/Card.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public function getContentType(): ?string {
* @inheritDoc
*/
public function getETag(): ?string {
return null;
return '"' . md5((string) $this->getLastModified()) . '"';
}

/**
Expand Down
24 changes: 24 additions & 0 deletions apps/contactsinteraction/lib/Db/RecentContactMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,30 @@ public function findMatch(IUser $user,
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();

Expand Down