@@ -34,93 +34,93 @@ |
||
34 | 34 | */ |
35 | 35 | abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { |
36 | 36 | |
37 | - /** @var string */ |
|
38 | - private const PREFIX = 'z-app-generated'; |
|
37 | + /** @var string */ |
|
38 | + private const PREFIX = 'z-app-generated'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var string |
|
42 | - * |
|
43 | - * Double dash is a valid delimiter, |
|
44 | - * because it will always split the URIs correctly: |
|
45 | - * - our prefix contains only one dash and won't be split |
|
46 | - * - appIds are not allowed to contain dashes as per spec: |
|
47 | - * > must contain only lowercase ASCII characters and underscore |
|
48 | - * - explode has a limit of three, so even if the app-generated |
|
49 | - * URI has double dashes, it won't be split |
|
50 | - */ |
|
51 | - private const DELIMITER = '--'; |
|
40 | + /** |
|
41 | + * @var string |
|
42 | + * |
|
43 | + * Double dash is a valid delimiter, |
|
44 | + * because it will always split the URIs correctly: |
|
45 | + * - our prefix contains only one dash and won't be split |
|
46 | + * - appIds are not allowed to contain dashes as per spec: |
|
47 | + * > must contain only lowercase ASCII characters and underscore |
|
48 | + * - explode has a limit of three, so even if the app-generated |
|
49 | + * URI has double dashes, it won't be split |
|
50 | + */ |
|
51 | + private const DELIMITER = '--'; |
|
52 | 52 | |
53 | - private string $appId; |
|
54 | - private string $uri; |
|
53 | + private string $appId; |
|
54 | + private string $uri; |
|
55 | 55 | |
56 | - public function __construct(string $appId, string $uri) { |
|
57 | - $this->appId = $appId; |
|
58 | - $this->uri = $uri; |
|
59 | - } |
|
56 | + public function __construct(string $appId, string $uri) { |
|
57 | + $this->appId = $appId; |
|
58 | + $this->uri = $uri; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @inheritDoc |
|
63 | - */ |
|
64 | - final public function getName() { |
|
65 | - return implode(self::DELIMITER, [ |
|
66 | - self::PREFIX, |
|
67 | - $this->appId, |
|
68 | - $this->uri, |
|
69 | - ]); |
|
70 | - } |
|
61 | + /** |
|
62 | + * @inheritDoc |
|
63 | + */ |
|
64 | + final public function getName() { |
|
65 | + return implode(self::DELIMITER, [ |
|
66 | + self::PREFIX, |
|
67 | + $this->appId, |
|
68 | + $this->uri, |
|
69 | + ]); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @inheritDoc |
|
74 | - */ |
|
75 | - final public function setName($name) { |
|
76 | - throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
77 | - } |
|
72 | + /** |
|
73 | + * @inheritDoc |
|
74 | + */ |
|
75 | + final public function setName($name) { |
|
76 | + throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @inheritDoc |
|
81 | - */ |
|
82 | - final public function createDirectory($name) { |
|
83 | - throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
84 | - } |
|
79 | + /** |
|
80 | + * @inheritDoc |
|
81 | + */ |
|
82 | + final public function createDirectory($name) { |
|
83 | + throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Checks whether the address book uri is app-generated |
|
88 | - * |
|
89 | - * @param string $uri |
|
90 | - * |
|
91 | - * @return bool |
|
92 | - */ |
|
93 | - public static function isAppGeneratedAddressBook(string $uri): bool { |
|
94 | - return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
95 | - } |
|
86 | + /** |
|
87 | + * Checks whether the address book uri is app-generated |
|
88 | + * |
|
89 | + * @param string $uri |
|
90 | + * |
|
91 | + * @return bool |
|
92 | + */ |
|
93 | + public static function isAppGeneratedAddressBook(string $uri): bool { |
|
94 | + return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Splits an app-generated uri into appId and uri |
|
99 | - * |
|
100 | - * @param string $uri |
|
101 | - * |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
105 | - $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
106 | - // Check the array has expected amount of elements |
|
107 | - // and none of them is an empty string |
|
108 | - if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
109 | - throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
110 | - } |
|
97 | + /** |
|
98 | + * Splits an app-generated uri into appId and uri |
|
99 | + * |
|
100 | + * @param string $uri |
|
101 | + * |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
105 | + $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
106 | + // Check the array has expected amount of elements |
|
107 | + // and none of them is an empty string |
|
108 | + if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
109 | + throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
110 | + } |
|
111 | 111 | |
112 | - return $array; |
|
113 | - } |
|
112 | + return $array; |
|
113 | + } |
|
114 | 114 | |
115 | - /** |
|
116 | - * Checks whether a address book name the user wants to create violates |
|
117 | - * the reserved name for URIs |
|
118 | - * |
|
119 | - * @param string $uri |
|
120 | - * |
|
121 | - * @return bool |
|
122 | - */ |
|
123 | - public static function doesViolateReservedName(string $uri): bool { |
|
124 | - return strpos($uri, self::PREFIX) === 0; |
|
125 | - } |
|
115 | + /** |
|
116 | + * Checks whether a address book name the user wants to create violates |
|
117 | + * the reserved name for URIs |
|
118 | + * |
|
119 | + * @param string $uri |
|
120 | + * |
|
121 | + * @return bool |
|
122 | + */ |
|
123 | + public static function doesViolateReservedName(string $uri): bool { |
|
124 | + return strpos($uri, self::PREFIX) === 0; |
|
125 | + } |
|
126 | 126 | } |
@@ -34,99 +34,99 @@ |
||
34 | 34 | use Sabre\DAVACL\IACL; |
35 | 35 | |
36 | 36 | class Card implements ICard, IACL { |
37 | - use ACLTrait; |
|
38 | - |
|
39 | - private RecentContact $contact; |
|
40 | - private string $principal; |
|
41 | - private array $acls; |
|
42 | - |
|
43 | - public function __construct(RecentContact $contact, string $principal, array $acls) { |
|
44 | - $this->contact = $contact; |
|
45 | - $this->principal = $principal; |
|
46 | - $this->acls = $acls; |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * @inheritDoc |
|
51 | - */ |
|
52 | - public function getOwner(): ?string { |
|
53 | - return $this->principal; |
|
54 | - } |
|
55 | - |
|
56 | - /** |
|
57 | - * @inheritDoc |
|
58 | - */ |
|
59 | - public function getACL(): array { |
|
60 | - return $this->acls; |
|
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * @inheritDoc |
|
65 | - */ |
|
66 | - public function setAcls(array $acls): void { |
|
67 | - throw new NotImplemented(); |
|
68 | - } |
|
69 | - |
|
70 | - /** |
|
71 | - * @inheritDoc |
|
72 | - */ |
|
73 | - public function put($data): ?string { |
|
74 | - throw new NotImplemented(); |
|
75 | - } |
|
76 | - |
|
77 | - /** |
|
78 | - * @inheritDoc |
|
79 | - */ |
|
80 | - public function get() { |
|
81 | - return $this->contact->getCard(); |
|
82 | - } |
|
83 | - |
|
84 | - /** |
|
85 | - * @inheritDoc |
|
86 | - */ |
|
87 | - public function getContentType(): ?string { |
|
88 | - return 'text/vcard; charset=utf-8'; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * @inheritDoc |
|
93 | - */ |
|
94 | - public function getETag(): ?string { |
|
95 | - return '"' . md5((string) $this->getLastModified()) . '"'; |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @inheritDoc |
|
100 | - */ |
|
101 | - public function getSize(): int { |
|
102 | - throw new NotImplemented(); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @inheritDoc |
|
107 | - */ |
|
108 | - public function delete(): void { |
|
109 | - throw new NotImplemented(); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * @inheritDoc |
|
114 | - */ |
|
115 | - public function getName(): string { |
|
116 | - return (string) $this->contact->getId(); |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * @inheritDoc |
|
121 | - */ |
|
122 | - public function setName($name): void { |
|
123 | - throw new NotImplemented(); |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * @inheritDoc |
|
128 | - */ |
|
129 | - public function getLastModified(): ?int { |
|
130 | - return $this->contact->getLastContact(); |
|
131 | - } |
|
37 | + use ACLTrait; |
|
38 | + |
|
39 | + private RecentContact $contact; |
|
40 | + private string $principal; |
|
41 | + private array $acls; |
|
42 | + |
|
43 | + public function __construct(RecentContact $contact, string $principal, array $acls) { |
|
44 | + $this->contact = $contact; |
|
45 | + $this->principal = $principal; |
|
46 | + $this->acls = $acls; |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * @inheritDoc |
|
51 | + */ |
|
52 | + public function getOwner(): ?string { |
|
53 | + return $this->principal; |
|
54 | + } |
|
55 | + |
|
56 | + /** |
|
57 | + * @inheritDoc |
|
58 | + */ |
|
59 | + public function getACL(): array { |
|
60 | + return $this->acls; |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * @inheritDoc |
|
65 | + */ |
|
66 | + public function setAcls(array $acls): void { |
|
67 | + throw new NotImplemented(); |
|
68 | + } |
|
69 | + |
|
70 | + /** |
|
71 | + * @inheritDoc |
|
72 | + */ |
|
73 | + public function put($data): ?string { |
|
74 | + throw new NotImplemented(); |
|
75 | + } |
|
76 | + |
|
77 | + /** |
|
78 | + * @inheritDoc |
|
79 | + */ |
|
80 | + public function get() { |
|
81 | + return $this->contact->getCard(); |
|
82 | + } |
|
83 | + |
|
84 | + /** |
|
85 | + * @inheritDoc |
|
86 | + */ |
|
87 | + public function getContentType(): ?string { |
|
88 | + return 'text/vcard; charset=utf-8'; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * @inheritDoc |
|
93 | + */ |
|
94 | + public function getETag(): ?string { |
|
95 | + return '"' . md5((string) $this->getLastModified()) . '"'; |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @inheritDoc |
|
100 | + */ |
|
101 | + public function getSize(): int { |
|
102 | + throw new NotImplemented(); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @inheritDoc |
|
107 | + */ |
|
108 | + public function delete(): void { |
|
109 | + throw new NotImplemented(); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * @inheritDoc |
|
114 | + */ |
|
115 | + public function getName(): string { |
|
116 | + return (string) $this->contact->getId(); |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * @inheritDoc |
|
121 | + */ |
|
122 | + public function setName($name): void { |
|
123 | + throw new NotImplemented(); |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * @inheritDoc |
|
128 | + */ |
|
129 | + public function getLastModified(): ?int { |
|
130 | + return $this->contact->getLastContact(); |
|
131 | + } |
|
132 | 132 | } |
@@ -31,21 +31,21 @@ |
||
31 | 31 | use OCP\BackgroundJob\TimedJob; |
32 | 32 | |
33 | 33 | class CleanupJob extends TimedJob { |
34 | - private RecentContactMapper $mapper; |
|
34 | + private RecentContactMapper $mapper; |
|
35 | 35 | |
36 | - public function __construct(ITimeFactory $time, |
|
37 | - RecentContactMapper $mapper) { |
|
38 | - parent::__construct($time); |
|
36 | + public function __construct(ITimeFactory $time, |
|
37 | + RecentContactMapper $mapper) { |
|
38 | + parent::__construct($time); |
|
39 | 39 | |
40 | - $this->setInterval(24 * 60 * 60); |
|
41 | - $this->setTimeSensitivity(IJob::TIME_INSENSITIVE); |
|
40 | + $this->setInterval(24 * 60 * 60); |
|
41 | + $this->setTimeSensitivity(IJob::TIME_INSENSITIVE); |
|
42 | 42 | |
43 | - $this->mapper = $mapper; |
|
44 | - } |
|
43 | + $this->mapper = $mapper; |
|
44 | + } |
|
45 | 45 | |
46 | - protected function run($argument) { |
|
47 | - $time = $this->time->getDateTime(); |
|
48 | - $time->modify('-7days'); |
|
49 | - $this->mapper->cleanUp($time->getTimestamp()); |
|
50 | - } |
|
46 | + protected function run($argument) { |
|
47 | + $time = $this->time->getDateTime(); |
|
48 | + $time->modify('-7days'); |
|
49 | + $this->mapper->cleanUp($time->getTimestamp()); |
|
50 | + } |
|
51 | 51 | } |
@@ -41,121 +41,121 @@ |
||
41 | 41 | use Throwable; |
42 | 42 | |
43 | 43 | class ContactInteractionListener implements IEventListener { |
44 | - private RecentContactMapper $mapper; |
|
45 | - private CardSearchDao $cardSearchDao; |
|
46 | - private IUserManager $userManager; |
|
47 | - private ITimeFactory $timeFactory; |
|
48 | - private IL10N $l10n; |
|
49 | - private LoggerInterface $logger; |
|
50 | - |
|
51 | - public function __construct(RecentContactMapper $mapper, |
|
52 | - CardSearchDao $cardSearchDao, |
|
53 | - IUserManager $userManager, |
|
54 | - ITimeFactory $timeFactory, |
|
55 | - IL10N $l10nFactory, |
|
56 | - LoggerInterface $logger) { |
|
57 | - $this->mapper = $mapper; |
|
58 | - $this->cardSearchDao = $cardSearchDao; |
|
59 | - $this->userManager = $userManager; |
|
60 | - $this->timeFactory = $timeFactory; |
|
61 | - $this->l10n = $l10nFactory; |
|
62 | - $this->logger = $logger; |
|
63 | - } |
|
64 | - |
|
65 | - public function handle(Event $event): void { |
|
66 | - if (!($event instanceof ContactInteractedWithEvent)) { |
|
67 | - return; |
|
68 | - } |
|
69 | - |
|
70 | - if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) { |
|
71 | - $this->logger->warning("Contact interaction event has no user identifier set"); |
|
72 | - return; |
|
73 | - } |
|
74 | - |
|
75 | - if ($event->getUid() !== null && $event->getUid() === $event->getActor()->getUID()) { |
|
76 | - $this->logger->info("Ignoring contact interaction with self"); |
|
77 | - return; |
|
78 | - } |
|
79 | - |
|
80 | - $existing = $this->mapper->findMatch( |
|
81 | - $event->getActor(), |
|
82 | - $event->getUid(), |
|
83 | - $event->getEmail(), |
|
84 | - $event->getFederatedCloudId() |
|
85 | - ); |
|
86 | - if (!empty($existing)) { |
|
87 | - $now = $this->timeFactory->getTime(); |
|
88 | - foreach ($existing as $c) { |
|
89 | - $c->setLastContact($now); |
|
90 | - $this->mapper->update($c); |
|
91 | - } |
|
92 | - |
|
93 | - return; |
|
94 | - } |
|
95 | - |
|
96 | - $contact = new RecentContact(); |
|
97 | - $contact->setActorUid($event->getActor()->getUID()); |
|
98 | - if ($event->getUid() !== null) { |
|
99 | - $contact->setUid($event->getUid()); |
|
100 | - } |
|
101 | - if ($event->getEmail() !== null) { |
|
102 | - $contact->setEmail($event->getEmail()); |
|
103 | - } |
|
104 | - if ($event->getFederatedCloudId() !== null) { |
|
105 | - $contact->setFederatedCloudId($event->getFederatedCloudId()); |
|
106 | - } |
|
107 | - $contact->setLastContact($this->timeFactory->getTime()); |
|
108 | - |
|
109 | - $copy = $this->cardSearchDao->findExisting( |
|
110 | - $event->getActor(), |
|
111 | - $event->getUid(), |
|
112 | - $event->getEmail(), |
|
113 | - $event->getFederatedCloudId() |
|
114 | - ); |
|
115 | - if ($copy !== null) { |
|
116 | - try { |
|
117 | - $parsed = Reader::read($copy, Reader::OPTION_FORGIVING); |
|
118 | - $parsed->CATEGORIES = $this->l10n->t('Recently contacted'); |
|
119 | - $contact->setCard($parsed->serialize()); |
|
120 | - } catch (Throwable $e) { |
|
121 | - $this->logger->warning( |
|
122 | - 'Could not parse card to add recent category: ' . $e->getMessage(), |
|
123 | - [ |
|
124 | - 'exception' => $e, |
|
125 | - ]); |
|
126 | - $contact->setCard($copy); |
|
127 | - } |
|
128 | - } else { |
|
129 | - $contact->setCard($this->generateCard($contact)); |
|
130 | - } |
|
131 | - $this->mapper->insert($contact); |
|
132 | - } |
|
133 | - |
|
134 | - private function getDisplayName(?string $uid): ?string { |
|
135 | - if ($uid === null) { |
|
136 | - return null; |
|
137 | - } |
|
138 | - if (($user = $this->userManager->get($uid)) === null) { |
|
139 | - return null; |
|
140 | - } |
|
141 | - |
|
142 | - return $user->getDisplayName(); |
|
143 | - } |
|
144 | - |
|
145 | - private function generateCard(RecentContact $contact): string { |
|
146 | - $props = [ |
|
147 | - 'URI' => UUIDUtil::getUUID(), |
|
148 | - 'FN' => $this->getDisplayName($contact->getUid()) ?? $contact->getEmail() ?? $contact->getFederatedCloudId(), |
|
149 | - 'CATEGORIES' => $this->l10n->t('Recently contacted'), |
|
150 | - ]; |
|
151 | - |
|
152 | - if ($contact->getEmail() !== null) { |
|
153 | - $props['EMAIL'] = $contact->getEmail(); |
|
154 | - } |
|
155 | - if ($contact->getFederatedCloudId() !== null) { |
|
156 | - $props['CLOUD'] = $contact->getFederatedCloudId(); |
|
157 | - } |
|
158 | - |
|
159 | - return (new VCard($props))->serialize(); |
|
160 | - } |
|
44 | + private RecentContactMapper $mapper; |
|
45 | + private CardSearchDao $cardSearchDao; |
|
46 | + private IUserManager $userManager; |
|
47 | + private ITimeFactory $timeFactory; |
|
48 | + private IL10N $l10n; |
|
49 | + private LoggerInterface $logger; |
|
50 | + |
|
51 | + public function __construct(RecentContactMapper $mapper, |
|
52 | + CardSearchDao $cardSearchDao, |
|
53 | + IUserManager $userManager, |
|
54 | + ITimeFactory $timeFactory, |
|
55 | + IL10N $l10nFactory, |
|
56 | + LoggerInterface $logger) { |
|
57 | + $this->mapper = $mapper; |
|
58 | + $this->cardSearchDao = $cardSearchDao; |
|
59 | + $this->userManager = $userManager; |
|
60 | + $this->timeFactory = $timeFactory; |
|
61 | + $this->l10n = $l10nFactory; |
|
62 | + $this->logger = $logger; |
|
63 | + } |
|
64 | + |
|
65 | + public function handle(Event $event): void { |
|
66 | + if (!($event instanceof ContactInteractedWithEvent)) { |
|
67 | + return; |
|
68 | + } |
|
69 | + |
|
70 | + if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) { |
|
71 | + $this->logger->warning("Contact interaction event has no user identifier set"); |
|
72 | + return; |
|
73 | + } |
|
74 | + |
|
75 | + if ($event->getUid() !== null && $event->getUid() === $event->getActor()->getUID()) { |
|
76 | + $this->logger->info("Ignoring contact interaction with self"); |
|
77 | + return; |
|
78 | + } |
|
79 | + |
|
80 | + $existing = $this->mapper->findMatch( |
|
81 | + $event->getActor(), |
|
82 | + $event->getUid(), |
|
83 | + $event->getEmail(), |
|
84 | + $event->getFederatedCloudId() |
|
85 | + ); |
|
86 | + if (!empty($existing)) { |
|
87 | + $now = $this->timeFactory->getTime(); |
|
88 | + foreach ($existing as $c) { |
|
89 | + $c->setLastContact($now); |
|
90 | + $this->mapper->update($c); |
|
91 | + } |
|
92 | + |
|
93 | + return; |
|
94 | + } |
|
95 | + |
|
96 | + $contact = new RecentContact(); |
|
97 | + $contact->setActorUid($event->getActor()->getUID()); |
|
98 | + if ($event->getUid() !== null) { |
|
99 | + $contact->setUid($event->getUid()); |
|
100 | + } |
|
101 | + if ($event->getEmail() !== null) { |
|
102 | + $contact->setEmail($event->getEmail()); |
|
103 | + } |
|
104 | + if ($event->getFederatedCloudId() !== null) { |
|
105 | + $contact->setFederatedCloudId($event->getFederatedCloudId()); |
|
106 | + } |
|
107 | + $contact->setLastContact($this->timeFactory->getTime()); |
|
108 | + |
|
109 | + $copy = $this->cardSearchDao->findExisting( |
|
110 | + $event->getActor(), |
|
111 | + $event->getUid(), |
|
112 | + $event->getEmail(), |
|
113 | + $event->getFederatedCloudId() |
|
114 | + ); |
|
115 | + if ($copy !== null) { |
|
116 | + try { |
|
117 | + $parsed = Reader::read($copy, Reader::OPTION_FORGIVING); |
|
118 | + $parsed->CATEGORIES = $this->l10n->t('Recently contacted'); |
|
119 | + $contact->setCard($parsed->serialize()); |
|
120 | + } catch (Throwable $e) { |
|
121 | + $this->logger->warning( |
|
122 | + 'Could not parse card to add recent category: ' . $e->getMessage(), |
|
123 | + [ |
|
124 | + 'exception' => $e, |
|
125 | + ]); |
|
126 | + $contact->setCard($copy); |
|
127 | + } |
|
128 | + } else { |
|
129 | + $contact->setCard($this->generateCard($contact)); |
|
130 | + } |
|
131 | + $this->mapper->insert($contact); |
|
132 | + } |
|
133 | + |
|
134 | + private function getDisplayName(?string $uid): ?string { |
|
135 | + if ($uid === null) { |
|
136 | + return null; |
|
137 | + } |
|
138 | + if (($user = $this->userManager->get($uid)) === null) { |
|
139 | + return null; |
|
140 | + } |
|
141 | + |
|
142 | + return $user->getDisplayName(); |
|
143 | + } |
|
144 | + |
|
145 | + private function generateCard(RecentContact $contact): string { |
|
146 | + $props = [ |
|
147 | + 'URI' => UUIDUtil::getUUID(), |
|
148 | + 'FN' => $this->getDisplayName($contact->getUid()) ?? $contact->getEmail() ?? $contact->getFederatedCloudId(), |
|
149 | + 'CATEGORIES' => $this->l10n->t('Recently contacted'), |
|
150 | + ]; |
|
151 | + |
|
152 | + if ($contact->getEmail() !== null) { |
|
153 | + $props['EMAIL'] = $contact->getEmail(); |
|
154 | + } |
|
155 | + if ($contact->getFederatedCloudId() !== null) { |
|
156 | + $props['CLOUD'] = $contact->getFederatedCloudId(); |
|
157 | + } |
|
158 | + |
|
159 | + return (new VCard($props))->serialize(); |
|
160 | + } |
|
161 | 161 | } |
@@ -40,133 +40,133 @@ |
||
40 | 40 | use Sabre\DAVACL\IACL; |
41 | 41 | |
42 | 42 | class AddressBook extends ExternalAddressBook implements IACL { |
43 | - use ACLTrait; |
|
44 | - |
|
45 | - public const URI = 'recent'; |
|
46 | - |
|
47 | - private RecentContactMapper $mapper; |
|
48 | - private IL10N $l10n; |
|
49 | - private string $principalUri; |
|
50 | - |
|
51 | - public function __construct(RecentContactMapper $mapper, |
|
52 | - IL10N $l10n, |
|
53 | - string $principalUri) { |
|
54 | - parent::__construct(Application::APP_ID, self::URI); |
|
55 | - |
|
56 | - $this->mapper = $mapper; |
|
57 | - $this->l10n = $l10n; |
|
58 | - $this->principalUri = $principalUri; |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * @inheritDoc |
|
63 | - */ |
|
64 | - public function delete(): void { |
|
65 | - throw new Exception("This addressbook is immutable"); |
|
66 | - } |
|
67 | - |
|
68 | - /** |
|
69 | - * @inheritDoc |
|
70 | - */ |
|
71 | - public function createFile($name, $data = null) { |
|
72 | - throw new Exception("This addressbook is immutable"); |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * @inheritDoc |
|
77 | - * @throws NotFound |
|
78 | - */ |
|
79 | - public function getChild($name): Card { |
|
80 | - try { |
|
81 | - return new Card( |
|
82 | - $this->mapper->find( |
|
83 | - $this->getUid(), |
|
84 | - (int)$name |
|
85 | - ), |
|
86 | - $this->principalUri, |
|
87 | - $this->getACL() |
|
88 | - ); |
|
89 | - } catch (DoesNotExistException $ex) { |
|
90 | - throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex); |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @inheritDoc |
|
96 | - */ |
|
97 | - public function getChildren(): array { |
|
98 | - return array_map( |
|
99 | - function (RecentContact $contact) { |
|
100 | - return new Card( |
|
101 | - $contact, |
|
102 | - $this->principalUri, |
|
103 | - $this->getACL() |
|
104 | - ); |
|
105 | - }, |
|
106 | - $this->mapper->findAll($this->getUid()) |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * @inheritDoc |
|
112 | - */ |
|
113 | - public function childExists($name): bool { |
|
114 | - try { |
|
115 | - $this->mapper->find( |
|
116 | - $this->getUid(), |
|
117 | - (int)$name |
|
118 | - ); |
|
119 | - return true; |
|
120 | - } catch (DoesNotExistException $e) { |
|
121 | - return false; |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @inheritDoc |
|
127 | - */ |
|
128 | - public function getLastModified(): ?int { |
|
129 | - return $this->mapper->findLastUpdatedForUserId($this->getUid()); |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * @inheritDoc |
|
134 | - */ |
|
135 | - public function propPatch(PropPatch $propPatch) { |
|
136 | - throw new Exception("This addressbook is immutable"); |
|
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * @inheritDoc |
|
141 | - */ |
|
142 | - public function getProperties($properties) { |
|
143 | - return [ |
|
144 | - 'principaluri' => $this->principalUri, |
|
145 | - '{DAV:}displayname' => $this->l10n->t('Recently contacted'), |
|
146 | - '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, |
|
147 | - '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), |
|
148 | - ]; |
|
149 | - } |
|
150 | - |
|
151 | - public function getOwner(): string { |
|
152 | - return $this->principalUri; |
|
153 | - } |
|
154 | - |
|
155 | - /** |
|
156 | - * @inheritDoc |
|
157 | - */ |
|
158 | - public function getACL(): array { |
|
159 | - return [ |
|
160 | - [ |
|
161 | - 'privilege' => '{DAV:}read', |
|
162 | - 'principal' => $this->getOwner(), |
|
163 | - 'protected' => true, |
|
164 | - ], |
|
165 | - ]; |
|
166 | - } |
|
167 | - |
|
168 | - private function getUid(): string { |
|
169 | - [, $uid] = \Sabre\Uri\split($this->principalUri); |
|
170 | - return $uid; |
|
171 | - } |
|
43 | + use ACLTrait; |
|
44 | + |
|
45 | + public const URI = 'recent'; |
|
46 | + |
|
47 | + private RecentContactMapper $mapper; |
|
48 | + private IL10N $l10n; |
|
49 | + private string $principalUri; |
|
50 | + |
|
51 | + public function __construct(RecentContactMapper $mapper, |
|
52 | + IL10N $l10n, |
|
53 | + string $principalUri) { |
|
54 | + parent::__construct(Application::APP_ID, self::URI); |
|
55 | + |
|
56 | + $this->mapper = $mapper; |
|
57 | + $this->l10n = $l10n; |
|
58 | + $this->principalUri = $principalUri; |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * @inheritDoc |
|
63 | + */ |
|
64 | + public function delete(): void { |
|
65 | + throw new Exception("This addressbook is immutable"); |
|
66 | + } |
|
67 | + |
|
68 | + /** |
|
69 | + * @inheritDoc |
|
70 | + */ |
|
71 | + public function createFile($name, $data = null) { |
|
72 | + throw new Exception("This addressbook is immutable"); |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * @inheritDoc |
|
77 | + * @throws NotFound |
|
78 | + */ |
|
79 | + public function getChild($name): Card { |
|
80 | + try { |
|
81 | + return new Card( |
|
82 | + $this->mapper->find( |
|
83 | + $this->getUid(), |
|
84 | + (int)$name |
|
85 | + ), |
|
86 | + $this->principalUri, |
|
87 | + $this->getACL() |
|
88 | + ); |
|
89 | + } catch (DoesNotExistException $ex) { |
|
90 | + throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex); |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @inheritDoc |
|
96 | + */ |
|
97 | + public function getChildren(): array { |
|
98 | + return array_map( |
|
99 | + function (RecentContact $contact) { |
|
100 | + return new Card( |
|
101 | + $contact, |
|
102 | + $this->principalUri, |
|
103 | + $this->getACL() |
|
104 | + ); |
|
105 | + }, |
|
106 | + $this->mapper->findAll($this->getUid()) |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * @inheritDoc |
|
112 | + */ |
|
113 | + public function childExists($name): bool { |
|
114 | + try { |
|
115 | + $this->mapper->find( |
|
116 | + $this->getUid(), |
|
117 | + (int)$name |
|
118 | + ); |
|
119 | + return true; |
|
120 | + } catch (DoesNotExistException $e) { |
|
121 | + return false; |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @inheritDoc |
|
127 | + */ |
|
128 | + public function getLastModified(): ?int { |
|
129 | + return $this->mapper->findLastUpdatedForUserId($this->getUid()); |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * @inheritDoc |
|
134 | + */ |
|
135 | + public function propPatch(PropPatch $propPatch) { |
|
136 | + throw new Exception("This addressbook is immutable"); |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * @inheritDoc |
|
141 | + */ |
|
142 | + public function getProperties($properties) { |
|
143 | + return [ |
|
144 | + 'principaluri' => $this->principalUri, |
|
145 | + '{DAV:}displayname' => $this->l10n->t('Recently contacted'), |
|
146 | + '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, |
|
147 | + '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), |
|
148 | + ]; |
|
149 | + } |
|
150 | + |
|
151 | + public function getOwner(): string { |
|
152 | + return $this->principalUri; |
|
153 | + } |
|
154 | + |
|
155 | + /** |
|
156 | + * @inheritDoc |
|
157 | + */ |
|
158 | + public function getACL(): array { |
|
159 | + return [ |
|
160 | + [ |
|
161 | + 'privilege' => '{DAV:}read', |
|
162 | + 'principal' => $this->getOwner(), |
|
163 | + 'protected' => true, |
|
164 | + ], |
|
165 | + ]; |
|
166 | + } |
|
167 | + |
|
168 | + private function getUid(): string { |
|
169 | + [, $uid] = \Sabre\Uri\split($this->principalUri); |
|
170 | + return $uid; |
|
171 | + } |
|
172 | 172 | } |
@@ -35,97 +35,97 @@ |
||
35 | 35 | * @template-extends QBMapper<RecentContact> |
36 | 36 | */ |
37 | 37 | class RecentContactMapper extends QBMapper { |
38 | - public const TABLE_NAME = 'recent_contact'; |
|
39 | - |
|
40 | - public function __construct(IDBConnection $db) { |
|
41 | - parent::__construct($db, self::TABLE_NAME); |
|
42 | - } |
|
43 | - |
|
44 | - /** |
|
45 | - * @return RecentContact[] |
|
46 | - */ |
|
47 | - public function findAll(string $uid): array { |
|
48 | - $qb = $this->db->getQueryBuilder(); |
|
49 | - |
|
50 | - $select = $qb |
|
51 | - ->select('*') |
|
52 | - ->from($this->getTableName()) |
|
53 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
54 | - |
|
55 | - return $this->findEntities($select); |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @throws DoesNotExistException |
|
60 | - */ |
|
61 | - public function find(string $uid, int $id): RecentContact { |
|
62 | - $qb = $this->db->getQueryBuilder(); |
|
63 | - |
|
64 | - $select = $qb |
|
65 | - ->select('*') |
|
66 | - ->from($this->getTableName()) |
|
67 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
68 | - ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
69 | - |
|
70 | - return $this->findEntity($select); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @return RecentContact[] |
|
75 | - */ |
|
76 | - public function findMatch(IUser $user, |
|
77 | - ?string $uid, |
|
78 | - ?string $email, |
|
79 | - ?string $cloudId): array { |
|
80 | - $qb = $this->db->getQueryBuilder(); |
|
81 | - |
|
82 | - $or = $qb->expr()->orX(); |
|
83 | - if ($uid !== null) { |
|
84 | - $or->add($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
85 | - } |
|
86 | - if ($email !== null) { |
|
87 | - $or->add($qb->expr()->eq('email', $qb->createNamedParameter($email))); |
|
88 | - } |
|
89 | - if ($cloudId !== null) { |
|
90 | - $or->add($qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId))); |
|
91 | - } |
|
92 | - |
|
93 | - $select = $qb |
|
94 | - ->select('*') |
|
95 | - ->from($this->getTableName()) |
|
96 | - ->where($or) |
|
97 | - ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
98 | - |
|
99 | - return $this->findEntities($select); |
|
100 | - } |
|
101 | - |
|
102 | - public function findLastUpdatedForUserId(string $uid): ?int { |
|
103 | - $qb = $this->db->getQueryBuilder(); |
|
104 | - |
|
105 | - $select = $qb |
|
106 | - ->select('last_contact') |
|
107 | - ->from($this->getTableName()) |
|
108 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
109 | - ->orderBy('last_contact', 'DESC') |
|
110 | - ->setMaxResults(1); |
|
111 | - |
|
112 | - $cursor = $select->executeQuery(); |
|
113 | - $row = $cursor->fetch(); |
|
114 | - |
|
115 | - if ($row === false) { |
|
116 | - return null; |
|
117 | - } |
|
118 | - |
|
119 | - return (int)$row['last_contact']; |
|
120 | - } |
|
121 | - |
|
122 | - public function cleanUp(int $olderThan): void { |
|
123 | - $qb = $this->db->getQueryBuilder(); |
|
124 | - |
|
125 | - $delete = $qb |
|
126 | - ->delete($this->getTableName()) |
|
127 | - ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
128 | - |
|
129 | - $delete->executeStatement(); |
|
130 | - } |
|
38 | + public const TABLE_NAME = 'recent_contact'; |
|
39 | + |
|
40 | + public function __construct(IDBConnection $db) { |
|
41 | + parent::__construct($db, self::TABLE_NAME); |
|
42 | + } |
|
43 | + |
|
44 | + /** |
|
45 | + * @return RecentContact[] |
|
46 | + */ |
|
47 | + public function findAll(string $uid): array { |
|
48 | + $qb = $this->db->getQueryBuilder(); |
|
49 | + |
|
50 | + $select = $qb |
|
51 | + ->select('*') |
|
52 | + ->from($this->getTableName()) |
|
53 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
54 | + |
|
55 | + return $this->findEntities($select); |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @throws DoesNotExistException |
|
60 | + */ |
|
61 | + public function find(string $uid, int $id): RecentContact { |
|
62 | + $qb = $this->db->getQueryBuilder(); |
|
63 | + |
|
64 | + $select = $qb |
|
65 | + ->select('*') |
|
66 | + ->from($this->getTableName()) |
|
67 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
68 | + ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
69 | + |
|
70 | + return $this->findEntity($select); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @return RecentContact[] |
|
75 | + */ |
|
76 | + public function findMatch(IUser $user, |
|
77 | + ?string $uid, |
|
78 | + ?string $email, |
|
79 | + ?string $cloudId): array { |
|
80 | + $qb = $this->db->getQueryBuilder(); |
|
81 | + |
|
82 | + $or = $qb->expr()->orX(); |
|
83 | + if ($uid !== null) { |
|
84 | + $or->add($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
85 | + } |
|
86 | + if ($email !== null) { |
|
87 | + $or->add($qb->expr()->eq('email', $qb->createNamedParameter($email))); |
|
88 | + } |
|
89 | + if ($cloudId !== null) { |
|
90 | + $or->add($qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId))); |
|
91 | + } |
|
92 | + |
|
93 | + $select = $qb |
|
94 | + ->select('*') |
|
95 | + ->from($this->getTableName()) |
|
96 | + ->where($or) |
|
97 | + ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
98 | + |
|
99 | + return $this->findEntities($select); |
|
100 | + } |
|
101 | + |
|
102 | + public function findLastUpdatedForUserId(string $uid): ?int { |
|
103 | + $qb = $this->db->getQueryBuilder(); |
|
104 | + |
|
105 | + $select = $qb |
|
106 | + ->select('last_contact') |
|
107 | + ->from($this->getTableName()) |
|
108 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
109 | + ->orderBy('last_contact', 'DESC') |
|
110 | + ->setMaxResults(1); |
|
111 | + |
|
112 | + $cursor = $select->executeQuery(); |
|
113 | + $row = $cursor->fetch(); |
|
114 | + |
|
115 | + if ($row === false) { |
|
116 | + return null; |
|
117 | + } |
|
118 | + |
|
119 | + return (int)$row['last_contact']; |
|
120 | + } |
|
121 | + |
|
122 | + public function cleanUp(int $olderThan): void { |
|
123 | + $qb = $this->db->getQueryBuilder(); |
|
124 | + |
|
125 | + $delete = $qb |
|
126 | + ->delete($this->getTableName()) |
|
127 | + ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
128 | + |
|
129 | + $delete->executeStatement(); |
|
130 | + } |
|
131 | 131 | } |
@@ -116,7 +116,7 @@ |
||
116 | 116 | return null; |
117 | 117 | } |
118 | 118 | |
119 | - return (int)$row['last_contact']; |
|
119 | + return (int) $row['last_contact']; |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | public function cleanUp(int $olderThan): void { |
@@ -32,63 +32,63 @@ |
||
32 | 32 | use function stream_get_contents; |
33 | 33 | |
34 | 34 | class CardSearchDao { |
35 | - private IDBConnection $db; |
|
35 | + private IDBConnection $db; |
|
36 | 36 | |
37 | - public function __construct(IDBConnection $db) { |
|
38 | - $this->db = $db; |
|
39 | - } |
|
37 | + public function __construct(IDBConnection $db) { |
|
38 | + $this->db = $db; |
|
39 | + } |
|
40 | 40 | |
41 | - public function findExisting(IUser $user, |
|
42 | - ?string $uid, |
|
43 | - ?string $email, |
|
44 | - ?string $cloudId): ?string { |
|
45 | - $addressbooksQuery = $this->db->getQueryBuilder(); |
|
46 | - $cardQuery = $this->db->getQueryBuilder(); |
|
47 | - $propQuery = $this->db->getQueryBuilder(); |
|
41 | + public function findExisting(IUser $user, |
|
42 | + ?string $uid, |
|
43 | + ?string $email, |
|
44 | + ?string $cloudId): ?string { |
|
45 | + $addressbooksQuery = $this->db->getQueryBuilder(); |
|
46 | + $cardQuery = $this->db->getQueryBuilder(); |
|
47 | + $propQuery = $this->db->getQueryBuilder(); |
|
48 | 48 | |
49 | - $propOr = $propQuery->expr()->orX(); |
|
50 | - if ($uid !== null) { |
|
51 | - $propOr->add($propQuery->expr()->andX( |
|
52 | - $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('UID')), |
|
53 | - $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($uid)) |
|
54 | - )); |
|
55 | - } |
|
56 | - if ($email !== null) { |
|
57 | - $propOr->add($propQuery->expr()->andX( |
|
58 | - $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('EMAIL')), |
|
59 | - $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($email)) |
|
60 | - )); |
|
61 | - } |
|
62 | - if ($cloudId !== null) { |
|
63 | - $propOr->add($propQuery->expr()->andX( |
|
64 | - $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('CLOUD')), |
|
65 | - $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($cloudId)) |
|
66 | - )); |
|
67 | - } |
|
68 | - $addressbooksQuery->selectDistinct('id') |
|
69 | - ->from('addressbooks') |
|
70 | - ->where($addressbooksQuery->expr()->eq('principaluri', $cardQuery->createNamedParameter("principals/users/" . $user->getUID()))); |
|
71 | - $propQuery->selectDistinct('cardid') |
|
72 | - ->from('cards_properties') |
|
73 | - ->where($propQuery->expr()->in('addressbookid', $propQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
74 | - ->andWhere($propOr) |
|
75 | - ->groupBy('cardid'); |
|
76 | - $cardQuery->select('carddata') |
|
77 | - ->from('cards') |
|
78 | - ->where($cardQuery->expr()->in('id', $cardQuery->createFunction($propQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
79 | - ->andWhere($cardQuery->expr()->in('addressbookid', $cardQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
80 | - ->setMaxResults(1); |
|
81 | - $result = $cardQuery->execute(); |
|
82 | - /** @var string|resource|false $card */ |
|
83 | - $card = $result->fetchOne(); |
|
49 | + $propOr = $propQuery->expr()->orX(); |
|
50 | + if ($uid !== null) { |
|
51 | + $propOr->add($propQuery->expr()->andX( |
|
52 | + $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('UID')), |
|
53 | + $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($uid)) |
|
54 | + )); |
|
55 | + } |
|
56 | + if ($email !== null) { |
|
57 | + $propOr->add($propQuery->expr()->andX( |
|
58 | + $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('EMAIL')), |
|
59 | + $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($email)) |
|
60 | + )); |
|
61 | + } |
|
62 | + if ($cloudId !== null) { |
|
63 | + $propOr->add($propQuery->expr()->andX( |
|
64 | + $propQuery->expr()->eq('name', $cardQuery->createNamedParameter('CLOUD')), |
|
65 | + $propQuery->expr()->eq('value', $cardQuery->createNamedParameter($cloudId)) |
|
66 | + )); |
|
67 | + } |
|
68 | + $addressbooksQuery->selectDistinct('id') |
|
69 | + ->from('addressbooks') |
|
70 | + ->where($addressbooksQuery->expr()->eq('principaluri', $cardQuery->createNamedParameter("principals/users/" . $user->getUID()))); |
|
71 | + $propQuery->selectDistinct('cardid') |
|
72 | + ->from('cards_properties') |
|
73 | + ->where($propQuery->expr()->in('addressbookid', $propQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
74 | + ->andWhere($propOr) |
|
75 | + ->groupBy('cardid'); |
|
76 | + $cardQuery->select('carddata') |
|
77 | + ->from('cards') |
|
78 | + ->where($cardQuery->expr()->in('id', $cardQuery->createFunction($propQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
79 | + ->andWhere($cardQuery->expr()->in('addressbookid', $cardQuery->createFunction($addressbooksQuery->getSQL()), IQueryBuilder::PARAM_INT_ARRAY)) |
|
80 | + ->setMaxResults(1); |
|
81 | + $result = $cardQuery->execute(); |
|
82 | + /** @var string|resource|false $card */ |
|
83 | + $card = $result->fetchOne(); |
|
84 | 84 | |
85 | - if ($card === false) { |
|
86 | - return null; |
|
87 | - } |
|
88 | - if (is_resource($card)) { |
|
89 | - return stream_get_contents($card); |
|
90 | - } |
|
85 | + if ($card === false) { |
|
86 | + return null; |
|
87 | + } |
|
88 | + if (is_resource($card)) { |
|
89 | + return stream_get_contents($card); |
|
90 | + } |
|
91 | 91 | |
92 | - return $card; |
|
93 | - } |
|
92 | + return $card; |
|
93 | + } |
|
94 | 94 | } |
@@ -42,19 +42,19 @@ |
||
42 | 42 | * @method int getLastContact() |
43 | 43 | */ |
44 | 44 | class RecentContact extends Entity { |
45 | - protected string $actorUid = ''; |
|
46 | - protected ?string $uid = null; |
|
47 | - protected ?string $email = null; |
|
48 | - protected ?string $federatedCloudId = null; |
|
49 | - protected string $card = ''; |
|
50 | - protected int $lastContact = -1; |
|
45 | + protected string $actorUid = ''; |
|
46 | + protected ?string $uid = null; |
|
47 | + protected ?string $email = null; |
|
48 | + protected ?string $federatedCloudId = null; |
|
49 | + protected string $card = ''; |
|
50 | + protected int $lastContact = -1; |
|
51 | 51 | |
52 | - public function __construct() { |
|
53 | - $this->addType('actorUid', 'string'); |
|
54 | - $this->addType('uid', 'string'); |
|
55 | - $this->addType('email', 'string'); |
|
56 | - $this->addType('federatedCloudId', 'string'); |
|
57 | - $this->addType('card', 'blob'); |
|
58 | - $this->addType('lastContact', 'int'); |
|
59 | - } |
|
52 | + public function __construct() { |
|
53 | + $this->addType('actorUid', 'string'); |
|
54 | + $this->addType('uid', 'string'); |
|
55 | + $this->addType('email', 'string'); |
|
56 | + $this->addType('federatedCloudId', 'string'); |
|
57 | + $this->addType('card', 'blob'); |
|
58 | + $this->addType('lastContact', 'int'); |
|
59 | + } |
|
60 | 60 | } |