Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable27] Fix: duplicating contacts with the Recently contacted feature #41096

Merged
merged 1 commit into from
Nov 16, 2023
Merged
Changes from all commits
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
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
Loading