]> source.dussan.org Git - nextcloud-server.git/commitdiff
Fix: duplicating contacts with the Recently contacted feature 41046/head
authorhamza221 <hamzamahjoubi221@gmail.com>
Sun, 22 Oct 2023 14:37:44 +0000 (16:37 +0200)
committerhamza221 <hamzamahjoubi221@gmail.com>
Tue, 24 Oct 2023 11:03:59 +0000 (13:03 +0200)
Signed-off-by: hamza221 <hamzamahjoubi221@gmail.com>
apps/contactsinteraction/lib/Listeners/ContactInteractionListener.php

index 000954a901659a6476f4b971c44c7655abcf7a20..499a9f28ca57a7ecef3004bedbd8d7ee53afe8a1 100644 (file)
@@ -76,15 +76,25 @@ class ContactInteractionListener implements IEventListener {
                        $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);
                                }
@@ -104,29 +114,8 @@ class ContactInteractionListener implements IEventListener {
                                $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);
        }