@@ -42,149 +42,149 @@ |
||
42 | 42 | * @deprecated 20.0.0 use the PSR-3 logger \Psr\Log\LoggerInterface |
43 | 43 | */ |
44 | 44 | interface ILogger { |
45 | - /** |
|
46 | - * @since 14.0.0 |
|
47 | - * @deprecated 20.0.0 |
|
48 | - */ |
|
49 | - public const DEBUG=0; |
|
50 | - /** |
|
51 | - * @since 14.0.0 |
|
52 | - * @deprecated 20.0.0 |
|
53 | - */ |
|
54 | - public const INFO=1; |
|
55 | - /** |
|
56 | - * @since 14.0.0 |
|
57 | - * @deprecated 20.0.0 |
|
58 | - */ |
|
59 | - public const WARN=2; |
|
60 | - /** |
|
61 | - * @since 14.0.0 |
|
62 | - * @deprecated 20.0.0 |
|
63 | - */ |
|
64 | - public const ERROR=3; |
|
65 | - /** |
|
66 | - * @since 14.0.0 |
|
67 | - * @deprecated 20.0.0 |
|
68 | - */ |
|
69 | - public const FATAL=4; |
|
45 | + /** |
|
46 | + * @since 14.0.0 |
|
47 | + * @deprecated 20.0.0 |
|
48 | + */ |
|
49 | + public const DEBUG=0; |
|
50 | + /** |
|
51 | + * @since 14.0.0 |
|
52 | + * @deprecated 20.0.0 |
|
53 | + */ |
|
54 | + public const INFO=1; |
|
55 | + /** |
|
56 | + * @since 14.0.0 |
|
57 | + * @deprecated 20.0.0 |
|
58 | + */ |
|
59 | + public const WARN=2; |
|
60 | + /** |
|
61 | + * @since 14.0.0 |
|
62 | + * @deprecated 20.0.0 |
|
63 | + */ |
|
64 | + public const ERROR=3; |
|
65 | + /** |
|
66 | + * @since 14.0.0 |
|
67 | + * @deprecated 20.0.0 |
|
68 | + */ |
|
69 | + public const FATAL=4; |
|
70 | 70 | |
71 | - /** |
|
72 | - * System is unusable. |
|
73 | - * |
|
74 | - * @param string $message |
|
75 | - * @param array $context |
|
76 | - * @return null |
|
77 | - * @since 7.0.0 |
|
78 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::emergency |
|
79 | - */ |
|
80 | - public function emergency(string $message, array $context = []); |
|
71 | + /** |
|
72 | + * System is unusable. |
|
73 | + * |
|
74 | + * @param string $message |
|
75 | + * @param array $context |
|
76 | + * @return null |
|
77 | + * @since 7.0.0 |
|
78 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::emergency |
|
79 | + */ |
|
80 | + public function emergency(string $message, array $context = []); |
|
81 | 81 | |
82 | - /** |
|
83 | - * Action must be taken immediately. |
|
84 | - * |
|
85 | - * @param string $message |
|
86 | - * @param array $context |
|
87 | - * @return null |
|
88 | - * @since 7.0.0 |
|
89 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::alert |
|
90 | - */ |
|
91 | - public function alert(string $message, array $context = []); |
|
82 | + /** |
|
83 | + * Action must be taken immediately. |
|
84 | + * |
|
85 | + * @param string $message |
|
86 | + * @param array $context |
|
87 | + * @return null |
|
88 | + * @since 7.0.0 |
|
89 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::alert |
|
90 | + */ |
|
91 | + public function alert(string $message, array $context = []); |
|
92 | 92 | |
93 | - /** |
|
94 | - * Critical conditions. |
|
95 | - * |
|
96 | - * @param string $message |
|
97 | - * @param array $context |
|
98 | - * @return null |
|
99 | - * @since 7.0.0 |
|
100 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::critical |
|
101 | - */ |
|
102 | - public function critical(string $message, array $context = []); |
|
93 | + /** |
|
94 | + * Critical conditions. |
|
95 | + * |
|
96 | + * @param string $message |
|
97 | + * @param array $context |
|
98 | + * @return null |
|
99 | + * @since 7.0.0 |
|
100 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::critical |
|
101 | + */ |
|
102 | + public function critical(string $message, array $context = []); |
|
103 | 103 | |
104 | - /** |
|
105 | - * Runtime errors that do not require immediate action but should typically |
|
106 | - * be logged and monitored. |
|
107 | - * |
|
108 | - * @param string $message |
|
109 | - * @param array $context |
|
110 | - * @return null |
|
111 | - * @since 7.0.0 |
|
112 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::error |
|
113 | - */ |
|
114 | - public function error(string $message, array $context = []); |
|
104 | + /** |
|
105 | + * Runtime errors that do not require immediate action but should typically |
|
106 | + * be logged and monitored. |
|
107 | + * |
|
108 | + * @param string $message |
|
109 | + * @param array $context |
|
110 | + * @return null |
|
111 | + * @since 7.0.0 |
|
112 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::error |
|
113 | + */ |
|
114 | + public function error(string $message, array $context = []); |
|
115 | 115 | |
116 | - /** |
|
117 | - * Exceptional occurrences that are not errors. |
|
118 | - * |
|
119 | - * @param string $message |
|
120 | - * @param array $context |
|
121 | - * @return null |
|
122 | - * @since 7.0.0 |
|
123 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::warning |
|
124 | - */ |
|
125 | - public function warning(string $message, array $context = []); |
|
116 | + /** |
|
117 | + * Exceptional occurrences that are not errors. |
|
118 | + * |
|
119 | + * @param string $message |
|
120 | + * @param array $context |
|
121 | + * @return null |
|
122 | + * @since 7.0.0 |
|
123 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::warning |
|
124 | + */ |
|
125 | + public function warning(string $message, array $context = []); |
|
126 | 126 | |
127 | - /** |
|
128 | - * Normal but significant events. |
|
129 | - * |
|
130 | - * @param string $message |
|
131 | - * @param array $context |
|
132 | - * @return null |
|
133 | - * @since 7.0.0 |
|
134 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::notice |
|
135 | - */ |
|
136 | - public function notice(string $message, array $context = []); |
|
127 | + /** |
|
128 | + * Normal but significant events. |
|
129 | + * |
|
130 | + * @param string $message |
|
131 | + * @param array $context |
|
132 | + * @return null |
|
133 | + * @since 7.0.0 |
|
134 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::notice |
|
135 | + */ |
|
136 | + public function notice(string $message, array $context = []); |
|
137 | 137 | |
138 | - /** |
|
139 | - * Interesting events. |
|
140 | - * |
|
141 | - * @param string $message |
|
142 | - * @param array $context |
|
143 | - * @return null |
|
144 | - * @since 7.0.0 |
|
145 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::info |
|
146 | - */ |
|
147 | - public function info(string $message, array $context = []); |
|
138 | + /** |
|
139 | + * Interesting events. |
|
140 | + * |
|
141 | + * @param string $message |
|
142 | + * @param array $context |
|
143 | + * @return null |
|
144 | + * @since 7.0.0 |
|
145 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::info |
|
146 | + */ |
|
147 | + public function info(string $message, array $context = []); |
|
148 | 148 | |
149 | - /** |
|
150 | - * Detailed debug information. |
|
151 | - * |
|
152 | - * @param string $message |
|
153 | - * @param array $context |
|
154 | - * @return null |
|
155 | - * @since 7.0.0 |
|
156 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::debug |
|
157 | - */ |
|
158 | - public function debug(string $message, array $context = []); |
|
149 | + /** |
|
150 | + * Detailed debug information. |
|
151 | + * |
|
152 | + * @param string $message |
|
153 | + * @param array $context |
|
154 | + * @return null |
|
155 | + * @since 7.0.0 |
|
156 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::debug |
|
157 | + */ |
|
158 | + public function debug(string $message, array $context = []); |
|
159 | 159 | |
160 | - /** |
|
161 | - * Logs with an arbitrary level. |
|
162 | - * |
|
163 | - * @param int $level |
|
164 | - * @param string $message |
|
165 | - * @param array $context |
|
166 | - * @return mixed |
|
167 | - * @since 7.0.0 |
|
168 | - * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::log |
|
169 | - */ |
|
170 | - public function log(int $level, string $message, array $context = []); |
|
160 | + /** |
|
161 | + * Logs with an arbitrary level. |
|
162 | + * |
|
163 | + * @param int $level |
|
164 | + * @param string $message |
|
165 | + * @param array $context |
|
166 | + * @return mixed |
|
167 | + * @since 7.0.0 |
|
168 | + * @deprecated 20.0.0 use \Psr\Log\LoggerInterface::log |
|
169 | + */ |
|
170 | + public function log(int $level, string $message, array $context = []); |
|
171 | 171 | |
172 | - /** |
|
173 | - * Logs an exception very detailed |
|
174 | - * An additional message can we written to the log by adding it to the |
|
175 | - * context. |
|
176 | - * |
|
177 | - * <code> |
|
178 | - * $logger->logException($ex, [ |
|
179 | - * 'message' => 'Exception during background job execution' |
|
180 | - * ]); |
|
181 | - * </code> |
|
182 | - * |
|
183 | - * @param \Exception|\Throwable $exception |
|
184 | - * @param array $context |
|
185 | - * @return void |
|
186 | - * @since 8.2.0 |
|
187 | - * @deprecated 20.0.0 use the `exception` entry in the context of any method in \Psr\Log\LoggerInterface |
|
188 | - */ |
|
189 | - public function logException(\Throwable $exception, array $context = []); |
|
172 | + /** |
|
173 | + * Logs an exception very detailed |
|
174 | + * An additional message can we written to the log by adding it to the |
|
175 | + * context. |
|
176 | + * |
|
177 | + * <code> |
|
178 | + * $logger->logException($ex, [ |
|
179 | + * 'message' => 'Exception during background job execution' |
|
180 | + * ]); |
|
181 | + * </code> |
|
182 | + * |
|
183 | + * @param \Exception|\Throwable $exception |
|
184 | + * @param array $context |
|
185 | + * @return void |
|
186 | + * @since 8.2.0 |
|
187 | + * @deprecated 20.0.0 use the `exception` entry in the context of any method in \Psr\Log\LoggerInterface |
|
188 | + */ |
|
189 | + public function logException(\Throwable $exception, array $context = []); |
|
190 | 190 | } |
@@ -46,27 +46,27 @@ |
||
46 | 46 | * @since 14.0.0 |
47 | 47 | * @deprecated 20.0.0 |
48 | 48 | */ |
49 | - public const DEBUG=0; |
|
49 | + public const DEBUG = 0; |
|
50 | 50 | /** |
51 | 51 | * @since 14.0.0 |
52 | 52 | * @deprecated 20.0.0 |
53 | 53 | */ |
54 | - public const INFO=1; |
|
54 | + public const INFO = 1; |
|
55 | 55 | /** |
56 | 56 | * @since 14.0.0 |
57 | 57 | * @deprecated 20.0.0 |
58 | 58 | */ |
59 | - public const WARN=2; |
|
59 | + public const WARN = 2; |
|
60 | 60 | /** |
61 | 61 | * @since 14.0.0 |
62 | 62 | * @deprecated 20.0.0 |
63 | 63 | */ |
64 | - public const ERROR=3; |
|
64 | + public const ERROR = 3; |
|
65 | 65 | /** |
66 | 66 | * @since 14.0.0 |
67 | 67 | * @deprecated 20.0.0 |
68 | 68 | */ |
69 | - public const FATAL=4; |
|
69 | + public const FATAL = 4; |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * System is unusable. |
@@ -33,95 +33,95 @@ |
||
33 | 33 | */ |
34 | 34 | class Logger implements ILogger { |
35 | 35 | |
36 | - /** @var ILogger */ |
|
37 | - private $logger; |
|
38 | - |
|
39 | - /** @var string */ |
|
40 | - private $appName; |
|
41 | - |
|
42 | - /** |
|
43 | - * @deprecated |
|
44 | - */ |
|
45 | - public function __construct(ILogger $logger, string $appName) { |
|
46 | - $this->logger = $logger; |
|
47 | - $this->appName = $appName; |
|
48 | - } |
|
49 | - |
|
50 | - private function extendContext(array $context): array { |
|
51 | - if (!isset($context['app'])) { |
|
52 | - $context['app'] = $this->appName; |
|
53 | - } |
|
54 | - |
|
55 | - return $context; |
|
56 | - } |
|
57 | - |
|
58 | - /** |
|
59 | - * @deprecated |
|
60 | - */ |
|
61 | - public function emergency(string $message, array $context = []) { |
|
62 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @deprecated |
|
67 | - */ |
|
68 | - public function alert(string $message, array $context = []) { |
|
69 | - $this->logger->alert($message, $this->extendContext($context)); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @deprecated |
|
74 | - */ |
|
75 | - public function critical(string $message, array $context = []) { |
|
76 | - $this->logger->critical($message, $this->extendContext($context)); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @deprecated |
|
81 | - */ |
|
82 | - public function error(string $message, array $context = []) { |
|
83 | - $this->logger->emergency($message, $this->extendContext($context)); |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @deprecated |
|
88 | - */ |
|
89 | - public function warning(string $message, array $context = []) { |
|
90 | - $this->logger->warning($message, $this->extendContext($context)); |
|
91 | - } |
|
92 | - |
|
93 | - /** |
|
94 | - * @deprecated |
|
95 | - */ |
|
96 | - public function notice(string $message, array $context = []) { |
|
97 | - $this->logger->notice($message, $this->extendContext($context)); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * @deprecated |
|
102 | - */ |
|
103 | - public function info(string $message, array $context = []) { |
|
104 | - $this->logger->info($message, $this->extendContext($context)); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @deprecated |
|
109 | - */ |
|
110 | - public function debug(string $message, array $context = []) { |
|
111 | - $this->logger->debug($message, $this->extendContext($context)); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @deprecated |
|
116 | - */ |
|
117 | - public function log(int $level, string $message, array $context = []) { |
|
118 | - $this->logger->log($level, $message, $this->extendContext($context)); |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * @deprecated |
|
123 | - */ |
|
124 | - public function logException(\Throwable $exception, array $context = []) { |
|
125 | - $this->logger->logException($exception, $this->extendContext($context)); |
|
126 | - } |
|
36 | + /** @var ILogger */ |
|
37 | + private $logger; |
|
38 | + |
|
39 | + /** @var string */ |
|
40 | + private $appName; |
|
41 | + |
|
42 | + /** |
|
43 | + * @deprecated |
|
44 | + */ |
|
45 | + public function __construct(ILogger $logger, string $appName) { |
|
46 | + $this->logger = $logger; |
|
47 | + $this->appName = $appName; |
|
48 | + } |
|
49 | + |
|
50 | + private function extendContext(array $context): array { |
|
51 | + if (!isset($context['app'])) { |
|
52 | + $context['app'] = $this->appName; |
|
53 | + } |
|
54 | + |
|
55 | + return $context; |
|
56 | + } |
|
57 | + |
|
58 | + /** |
|
59 | + * @deprecated |
|
60 | + */ |
|
61 | + public function emergency(string $message, array $context = []) { |
|
62 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @deprecated |
|
67 | + */ |
|
68 | + public function alert(string $message, array $context = []) { |
|
69 | + $this->logger->alert($message, $this->extendContext($context)); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @deprecated |
|
74 | + */ |
|
75 | + public function critical(string $message, array $context = []) { |
|
76 | + $this->logger->critical($message, $this->extendContext($context)); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @deprecated |
|
81 | + */ |
|
82 | + public function error(string $message, array $context = []) { |
|
83 | + $this->logger->emergency($message, $this->extendContext($context)); |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @deprecated |
|
88 | + */ |
|
89 | + public function warning(string $message, array $context = []) { |
|
90 | + $this->logger->warning($message, $this->extendContext($context)); |
|
91 | + } |
|
92 | + |
|
93 | + /** |
|
94 | + * @deprecated |
|
95 | + */ |
|
96 | + public function notice(string $message, array $context = []) { |
|
97 | + $this->logger->notice($message, $this->extendContext($context)); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * @deprecated |
|
102 | + */ |
|
103 | + public function info(string $message, array $context = []) { |
|
104 | + $this->logger->info($message, $this->extendContext($context)); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @deprecated |
|
109 | + */ |
|
110 | + public function debug(string $message, array $context = []) { |
|
111 | + $this->logger->debug($message, $this->extendContext($context)); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @deprecated |
|
116 | + */ |
|
117 | + public function log(int $level, string $message, array $context = []) { |
|
118 | + $this->logger->log($level, $message, $this->extendContext($context)); |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * @deprecated |
|
123 | + */ |
|
124 | + public function logException(\Throwable $exception, array $context = []) { |
|
125 | + $this->logger->logException($exception, $this->extendContext($context)); |
|
126 | + } |
|
127 | 127 | } |
@@ -42,130 +42,130 @@ |
||
42 | 42 | |
43 | 43 | class ContactInteractionListener implements IEventListener { |
44 | 44 | |
45 | - /** @var RecentContactMapper */ |
|
46 | - private $mapper; |
|
47 | - |
|
48 | - /** @var CardSearchDao */ |
|
49 | - private $cardSearchDao; |
|
50 | - |
|
51 | - /** @var IUserManager */ |
|
52 | - private $userManager; |
|
53 | - |
|
54 | - /** @var ITimeFactory */ |
|
55 | - private $timeFactory; |
|
56 | - |
|
57 | - /** @var IL10N */ |
|
58 | - private $l10n; |
|
59 | - |
|
60 | - /** @var LoggerInterface */ |
|
61 | - private $logger; |
|
62 | - |
|
63 | - public function __construct(RecentContactMapper $mapper, |
|
64 | - CardSearchDao $cardSearchDao, |
|
65 | - IUserManager $userManager, |
|
66 | - ITimeFactory $timeFactory, |
|
67 | - IL10N $l10nFactory, |
|
68 | - LoggerInterface $logger) { |
|
69 | - $this->mapper = $mapper; |
|
70 | - $this->cardSearchDao = $cardSearchDao; |
|
71 | - $this->userManager = $userManager; |
|
72 | - $this->timeFactory = $timeFactory; |
|
73 | - $this->l10n = $l10nFactory; |
|
74 | - $this->logger = $logger; |
|
75 | - } |
|
76 | - |
|
77 | - public function handle(Event $event): void { |
|
78 | - if (!($event instanceof ContactInteractedWithEvent)) { |
|
79 | - return; |
|
80 | - } |
|
81 | - |
|
82 | - if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) { |
|
83 | - $this->logger->warning("Contact interaction event has no user identifier set"); |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $existing = $this->mapper->findMatch( |
|
88 | - $event->getActor(), |
|
89 | - $event->getUid(), |
|
90 | - $event->getEmail(), |
|
91 | - $event->getFederatedCloudId() |
|
92 | - ); |
|
93 | - if (!empty($existing)) { |
|
94 | - $now = $this->timeFactory->getTime(); |
|
95 | - foreach ($existing as $c) { |
|
96 | - $c->setLastContact($now); |
|
97 | - $this->mapper->update($c); |
|
98 | - } |
|
99 | - |
|
100 | - return; |
|
101 | - } |
|
102 | - |
|
103 | - $contact = new RecentContact(); |
|
104 | - $contact->setActorUid($event->getActor()->getUID()); |
|
105 | - if ($event->getUid() !== null) { |
|
106 | - $contact->setUid($event->getUid()); |
|
107 | - } |
|
108 | - if ($event->getEmail() !== null) { |
|
109 | - $contact->setEmail($event->getEmail()); |
|
110 | - } |
|
111 | - if ($event->getFederatedCloudId() !== null) { |
|
112 | - $contact->setFederatedCloudId($event->getFederatedCloudId()); |
|
113 | - } |
|
114 | - $contact->setLastContact($this->timeFactory->getTime()); |
|
115 | - |
|
116 | - $copy = $this->cardSearchDao->findExisting( |
|
117 | - $event->getActor(), |
|
118 | - $event->getUid(), |
|
119 | - $event->getEmail(), |
|
120 | - $event->getFederatedCloudId() |
|
121 | - ); |
|
122 | - if ($copy !== null) { |
|
123 | - try { |
|
124 | - $parsed = Reader::read($copy, Reader::OPTION_FORGIVING); |
|
125 | - $parsed->CATEGORIES = $this->l10n->t('Recently contacted'); |
|
126 | - $contact->setCard($parsed->serialize()); |
|
127 | - } catch (Throwable $e) { |
|
128 | - $this->logger->warning( |
|
129 | - 'Could not parse card to add recent category: ' . $e->getMessage(), |
|
130 | - [ |
|
131 | - 'exception' => $e, |
|
132 | - ]); |
|
133 | - $contact->setCard($copy); |
|
134 | - } |
|
135 | - } else { |
|
136 | - $contact->setCard($this->generateCard($contact)); |
|
137 | - } |
|
138 | - $this->mapper->insert($contact); |
|
139 | - } |
|
140 | - |
|
141 | - private function getDisplayName(?string $uid): ?string { |
|
142 | - if ($uid === null) { |
|
143 | - return null; |
|
144 | - } |
|
145 | - if (($user = $this->userManager->get($uid)) === null) { |
|
146 | - return null; |
|
147 | - } |
|
148 | - |
|
149 | - return $user->getDisplayName(); |
|
150 | - } |
|
151 | - |
|
152 | - private function generateCard(RecentContact $contact): string { |
|
153 | - $props = [ |
|
154 | - 'URI' => UUIDUtil::getUUID(), |
|
155 | - 'FN' => $this->getDisplayName($contact->getUid()) ?? $contact->getEmail() ?? $contact->getFederatedCloudId(), |
|
156 | - 'CATEGORIES' => $this->l10n->t('Recently contacted'), |
|
157 | - ]; |
|
158 | - |
|
159 | - if ($contact->getUid() !== null) { |
|
160 | - $props['X-NEXTCLOUD-UID'] = $contact->getUid(); |
|
161 | - } |
|
162 | - if ($contact->getEmail() !== null) { |
|
163 | - $props['EMAIL'] = $contact->getEmail(); |
|
164 | - } |
|
165 | - if ($contact->getFederatedCloudId() !== null) { |
|
166 | - $props['CLOUD'] = $contact->getFederatedCloudId(); |
|
167 | - } |
|
168 | - |
|
169 | - return (new VCard($props))->serialize(); |
|
170 | - } |
|
45 | + /** @var RecentContactMapper */ |
|
46 | + private $mapper; |
|
47 | + |
|
48 | + /** @var CardSearchDao */ |
|
49 | + private $cardSearchDao; |
|
50 | + |
|
51 | + /** @var IUserManager */ |
|
52 | + private $userManager; |
|
53 | + |
|
54 | + /** @var ITimeFactory */ |
|
55 | + private $timeFactory; |
|
56 | + |
|
57 | + /** @var IL10N */ |
|
58 | + private $l10n; |
|
59 | + |
|
60 | + /** @var LoggerInterface */ |
|
61 | + private $logger; |
|
62 | + |
|
63 | + public function __construct(RecentContactMapper $mapper, |
|
64 | + CardSearchDao $cardSearchDao, |
|
65 | + IUserManager $userManager, |
|
66 | + ITimeFactory $timeFactory, |
|
67 | + IL10N $l10nFactory, |
|
68 | + LoggerInterface $logger) { |
|
69 | + $this->mapper = $mapper; |
|
70 | + $this->cardSearchDao = $cardSearchDao; |
|
71 | + $this->userManager = $userManager; |
|
72 | + $this->timeFactory = $timeFactory; |
|
73 | + $this->l10n = $l10nFactory; |
|
74 | + $this->logger = $logger; |
|
75 | + } |
|
76 | + |
|
77 | + public function handle(Event $event): void { |
|
78 | + if (!($event instanceof ContactInteractedWithEvent)) { |
|
79 | + return; |
|
80 | + } |
|
81 | + |
|
82 | + if ($event->getUid() === null && $event->getEmail() === null && $event->getFederatedCloudId() === null) { |
|
83 | + $this->logger->warning("Contact interaction event has no user identifier set"); |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $existing = $this->mapper->findMatch( |
|
88 | + $event->getActor(), |
|
89 | + $event->getUid(), |
|
90 | + $event->getEmail(), |
|
91 | + $event->getFederatedCloudId() |
|
92 | + ); |
|
93 | + if (!empty($existing)) { |
|
94 | + $now = $this->timeFactory->getTime(); |
|
95 | + foreach ($existing as $c) { |
|
96 | + $c->setLastContact($now); |
|
97 | + $this->mapper->update($c); |
|
98 | + } |
|
99 | + |
|
100 | + return; |
|
101 | + } |
|
102 | + |
|
103 | + $contact = new RecentContact(); |
|
104 | + $contact->setActorUid($event->getActor()->getUID()); |
|
105 | + if ($event->getUid() !== null) { |
|
106 | + $contact->setUid($event->getUid()); |
|
107 | + } |
|
108 | + if ($event->getEmail() !== null) { |
|
109 | + $contact->setEmail($event->getEmail()); |
|
110 | + } |
|
111 | + if ($event->getFederatedCloudId() !== null) { |
|
112 | + $contact->setFederatedCloudId($event->getFederatedCloudId()); |
|
113 | + } |
|
114 | + $contact->setLastContact($this->timeFactory->getTime()); |
|
115 | + |
|
116 | + $copy = $this->cardSearchDao->findExisting( |
|
117 | + $event->getActor(), |
|
118 | + $event->getUid(), |
|
119 | + $event->getEmail(), |
|
120 | + $event->getFederatedCloudId() |
|
121 | + ); |
|
122 | + if ($copy !== null) { |
|
123 | + try { |
|
124 | + $parsed = Reader::read($copy, Reader::OPTION_FORGIVING); |
|
125 | + $parsed->CATEGORIES = $this->l10n->t('Recently contacted'); |
|
126 | + $contact->setCard($parsed->serialize()); |
|
127 | + } catch (Throwable $e) { |
|
128 | + $this->logger->warning( |
|
129 | + 'Could not parse card to add recent category: ' . $e->getMessage(), |
|
130 | + [ |
|
131 | + 'exception' => $e, |
|
132 | + ]); |
|
133 | + $contact->setCard($copy); |
|
134 | + } |
|
135 | + } else { |
|
136 | + $contact->setCard($this->generateCard($contact)); |
|
137 | + } |
|
138 | + $this->mapper->insert($contact); |
|
139 | + } |
|
140 | + |
|
141 | + private function getDisplayName(?string $uid): ?string { |
|
142 | + if ($uid === null) { |
|
143 | + return null; |
|
144 | + } |
|
145 | + if (($user = $this->userManager->get($uid)) === null) { |
|
146 | + return null; |
|
147 | + } |
|
148 | + |
|
149 | + return $user->getDisplayName(); |
|
150 | + } |
|
151 | + |
|
152 | + private function generateCard(RecentContact $contact): string { |
|
153 | + $props = [ |
|
154 | + 'URI' => UUIDUtil::getUUID(), |
|
155 | + 'FN' => $this->getDisplayName($contact->getUid()) ?? $contact->getEmail() ?? $contact->getFederatedCloudId(), |
|
156 | + 'CATEGORIES' => $this->l10n->t('Recently contacted'), |
|
157 | + ]; |
|
158 | + |
|
159 | + if ($contact->getUid() !== null) { |
|
160 | + $props['X-NEXTCLOUD-UID'] = $contact->getUid(); |
|
161 | + } |
|
162 | + if ($contact->getEmail() !== null) { |
|
163 | + $props['EMAIL'] = $contact->getEmail(); |
|
164 | + } |
|
165 | + if ($contact->getFederatedCloudId() !== null) { |
|
166 | + $props['CLOUD'] = $contact->getFederatedCloudId(); |
|
167 | + } |
|
168 | + |
|
169 | + return (new VCard($props))->serialize(); |
|
170 | + } |
|
171 | 171 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | $contact->setCard($parsed->serialize()); |
127 | 127 | } catch (Throwable $e) { |
128 | 128 | $this->logger->warning( |
129 | - 'Could not parse card to add recent category: ' . $e->getMessage(), |
|
129 | + 'Could not parse card to add recent category: '.$e->getMessage(), |
|
130 | 130 | [ |
131 | 131 | 'exception' => $e, |
132 | 132 | ]); |