Skip to content

Commit

Permalink
Fix: duplicating contacts with the Recently contacted feature
Browse files Browse the repository at this point in the history
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
  • Loading branch information
hamza221 authored and backportbot-nextcloud[bot] committed Oct 24, 2023
1 parent eb83fcb commit fa72f8e
Showing 1 changed file with 14 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,25 @@ public function handle(Event $event): void {
$uid = $event->getUid();
$email = $event->getEmail();
$federatedCloudId = $event->getFederatedCloudId();
$existing = $this->mapper->findMatch(

$existingContact = $this->cardSearchDao->findExisting(
$event->getActor(),
$uid,
$email,
$federatedCloudId);
if ($existingContact !== null) {
return;
}

$existingRecentlyContacted = $this->mapper->findMatch(
$event->getActor(),
$uid,
$email,
$federatedCloudId
);
if (!empty($existing)) {
if (!empty($existingRecentlyContacted)) {
$now = $this->timeFactory->getTime();
foreach ($existing as $c) {
foreach ($existingRecentlyContacted as $c) {
$c->setLastContact($now);
$this->mapper->update($c);
}
Expand All @@ -117,29 +127,8 @@ public function handle(Event $event): void {
$contact->setFederatedCloudId($federatedCloudId);
}
$contact->setLastContact($this->timeFactory->getTime());
$contact->setCard($this->generateCard($contact));

$copy = $this->cardSearchDao->findExisting(
$event->getActor(),
$uid,
$email,
$federatedCloudId
);
if ($copy !== null) {
try {
$parsed = Reader::read($copy, Reader::OPTION_FORGIVING);
$parsed->CATEGORIES = $this->l10n->t('Recently contacted');
$contact->setCard($parsed->serialize());
} catch (Throwable $e) {
$this->logger->warning(
'Could not parse card to add recent category: ' . $e->getMessage(),
[
'exception' => $e,
]);
$contact->setCard($copy);
}
} else {
$contact->setCard($this->generateCard($contact));
}
$this->mapper->insert($contact);
}, $this->dbConnection);
}
Expand Down

0 comments on commit fa72f8e

Please sign in to comment.