@@ -18,473 +18,473 @@ |
||
18 | 18 | * @since 9.0.0 |
19 | 19 | */ |
20 | 20 | interface ICommentsManager { |
21 | - /** |
|
22 | - * @const DELETED_USER type and id for a user that has been deleted |
|
23 | - * @see deleteReferencesOfActor |
|
24 | - * @since 9.0.0 |
|
25 | - * |
|
26 | - * To be used as replacement for user type actors in deleteReferencesOfActor(). |
|
27 | - * |
|
28 | - * User interfaces shall show "Deleted user" as display name, if needed. |
|
29 | - */ |
|
30 | - public const DELETED_USER = 'deleted_users'; |
|
31 | - |
|
32 | - /** |
|
33 | - * returns a comment instance |
|
34 | - * |
|
35 | - * @param string $id the ID of the comment |
|
36 | - * @return IComment |
|
37 | - * @throws NotFoundException |
|
38 | - * @since 9.0.0 |
|
39 | - */ |
|
40 | - public function get($id); |
|
41 | - |
|
42 | - /** |
|
43 | - * Returns the comment specified by the id and all it's child comments |
|
44 | - * |
|
45 | - * @param string $id |
|
46 | - * @param int $limit max number of entries to return, 0 returns all |
|
47 | - * @param int $offset the start entry |
|
48 | - * @return array{comment: IComment, replies: list<array{comment: IComment, replies: array<empty, empty>}>} |
|
49 | - * @since 9.0.0 |
|
50 | - * |
|
51 | - * The return array looks like this |
|
52 | - * [ |
|
53 | - * 'comment' => IComment, // root comment |
|
54 | - * 'replies' => |
|
55 | - * [ |
|
56 | - * 0 => |
|
57 | - * [ |
|
58 | - * 'comment' => IComment, |
|
59 | - * 'replies' => |
|
60 | - * [ |
|
61 | - * 0 => |
|
62 | - * [ |
|
63 | - * 'comment' => IComment, |
|
64 | - * 'replies' => [ … ] |
|
65 | - * ], |
|
66 | - * … |
|
67 | - * ] |
|
68 | - * ] |
|
69 | - * 1 => |
|
70 | - * [ |
|
71 | - * 'comment' => IComment, |
|
72 | - * 'replies'=> [ … ] |
|
73 | - * ], |
|
74 | - * … |
|
75 | - * ] |
|
76 | - * ] |
|
77 | - */ |
|
78 | - public function getTree($id, $limit = 0, $offset = 0); |
|
79 | - |
|
80 | - /** |
|
81 | - * returns comments for a specific object (e.g. a file). |
|
82 | - * |
|
83 | - * The sort order is always newest to oldest. |
|
84 | - * |
|
85 | - * @param string $objectType the object type, e.g. 'files' |
|
86 | - * @param string $objectId the id of the object |
|
87 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
88 | - * not specified, all comments are returned. |
|
89 | - * @param int $offset optional, starting point |
|
90 | - * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
91 | - * that may be returned |
|
92 | - * @return list<IComment> |
|
93 | - * @since 9.0.0 |
|
94 | - */ |
|
95 | - public function getForObject( |
|
96 | - $objectType, |
|
97 | - $objectId, |
|
98 | - $limit = 0, |
|
99 | - $offset = 0, |
|
100 | - ?\DateTime $notOlderThan = null, |
|
101 | - ); |
|
102 | - |
|
103 | - /** |
|
104 | - * @param string $objectType the object type, e.g. 'files' |
|
105 | - * @param string $objectId the id of the object |
|
106 | - * @param int $lastKnownCommentId the last known comment (will be used as offset) |
|
107 | - * @param string $sortDirection direction of the comments (`asc` or `desc`) |
|
108 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
109 | - * set to 0, all comments are returned. |
|
110 | - * @param bool $includeLastKnown |
|
111 | - * @param string $topmostParentId Limit the comments to a list of replies and its original root comment |
|
112 | - * @return list<IComment> |
|
113 | - * @since 14.0.0 |
|
114 | - * @deprecated 24.0.0 - Use getCommentsWithVerbForObjectSinceComment instead |
|
115 | - */ |
|
116 | - public function getForObjectSince( |
|
117 | - string $objectType, |
|
118 | - string $objectId, |
|
119 | - int $lastKnownCommentId, |
|
120 | - string $sortDirection = 'asc', |
|
121 | - int $limit = 30, |
|
122 | - bool $includeLastKnown = false, |
|
123 | - string $topmostParentId = '', |
|
124 | - ): array; |
|
125 | - |
|
126 | - /** |
|
127 | - * @param string $objectType the object type, e.g. 'files' |
|
128 | - * @param string $objectId the id of the object |
|
129 | - * @param string[] $verbs List of verbs to filter by |
|
130 | - * @param int $lastKnownCommentId the last known comment (will be used as offset) |
|
131 | - * @param string $sortDirection direction of the comments (`asc` or `desc`) |
|
132 | - * @param int $limit optional, number of maximum comments to be returned. if |
|
133 | - * set to 0, all comments are returned. |
|
134 | - * @param bool $includeLastKnown |
|
135 | - * @param string $topmostParentId Limit the comments to a list of replies and its original root comment |
|
136 | - * @return list<IComment> |
|
137 | - * @since 24.0.0 |
|
138 | - */ |
|
139 | - public function getCommentsWithVerbForObjectSinceComment( |
|
140 | - string $objectType, |
|
141 | - string $objectId, |
|
142 | - array $verbs, |
|
143 | - int $lastKnownCommentId, |
|
144 | - string $sortDirection = 'asc', |
|
145 | - int $limit = 30, |
|
146 | - bool $includeLastKnown = false, |
|
147 | - string $topmostParentId = '', |
|
148 | - ): array; |
|
149 | - |
|
150 | - /** |
|
151 | - * Search for comments with a given content |
|
152 | - * |
|
153 | - * @param string $search content to search for |
|
154 | - * @param string $objectType Limit the search by object type |
|
155 | - * @param string $objectId Limit the search by object id |
|
156 | - * @param string $verb Limit the verb of the comment |
|
157 | - * @param int $offset |
|
158 | - * @param int $limit |
|
159 | - * @return list<IComment> |
|
160 | - * @since 14.0.0 |
|
161 | - */ |
|
162 | - public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; |
|
163 | - |
|
164 | - /** |
|
165 | - * Search for comments on one or more objects with a given content |
|
166 | - * |
|
167 | - * @param string $search content to search for |
|
168 | - * @param string $objectType Limit the search by object type |
|
169 | - * @param array $objectIds Limit the search by object ids |
|
170 | - * @param string $verb Limit the verb of the comment |
|
171 | - * @param int $offset |
|
172 | - * @param int $limit |
|
173 | - * @return IComment[] |
|
174 | - * @since 21.0.0 |
|
175 | - */ |
|
176 | - public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array; |
|
177 | - |
|
178 | - /** |
|
179 | - * @param $objectType string the object type, e.g. 'files' |
|
180 | - * @param $objectId string the id of the object |
|
181 | - * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
182 | - * that may be returned |
|
183 | - * @param string $verb Limit the verb of the comment - Added in 14.0.0 |
|
184 | - * @return Int |
|
185 | - * @since 9.0.0 |
|
186 | - */ |
|
187 | - public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = ''); |
|
188 | - |
|
189 | - /** |
|
190 | - * @param $objectType string the object type, e.g. 'files' |
|
191 | - * @param $objectIds string[] the ids of the object |
|
192 | - * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
193 | - * that may be returned |
|
194 | - * @param string $verb Limit the verb of the comment |
|
195 | - * @return array<string, int> |
|
196 | - * @since 32.0.0 |
|
197 | - */ |
|
198 | - public function getNumberOfCommentsForObjects(string $objectType, array $objectIds, ?\DateTime $notOlderThan = null, string $verb = ''); |
|
199 | - |
|
200 | - /** |
|
201 | - * @param string $objectType the object type, e.g. 'files' |
|
202 | - * @param string[] $objectIds the id of the object |
|
203 | - * @param IUser $user |
|
204 | - * @param string $verb Limit the verb of the comment - Added in 14.0.0 |
|
205 | - * @return array Map with object id => # of unread comments |
|
206 | - * @psalm-return array<string, int> |
|
207 | - * @since 21.0.0 |
|
208 | - */ |
|
209 | - public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array; |
|
210 | - |
|
211 | - /** |
|
212 | - * @param string $objectType |
|
213 | - * @param string $objectId |
|
214 | - * @param int $lastRead |
|
215 | - * @param string $verb |
|
216 | - * @return int |
|
217 | - * @since 21.0.0 |
|
218 | - * @deprecated 24.0.0 - Use getNumberOfCommentsWithVerbsForObjectSinceComment instead |
|
219 | - */ |
|
220 | - public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int; |
|
221 | - |
|
222 | - |
|
223 | - /** |
|
224 | - * @param string $objectType |
|
225 | - * @param string $objectId |
|
226 | - * @param int $lastRead |
|
227 | - * @param string[] $verbs |
|
228 | - * @return int |
|
229 | - * @since 24.0.0 |
|
230 | - */ |
|
231 | - public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int; |
|
232 | - |
|
233 | - /** |
|
234 | - * @param string $objectType |
|
235 | - * @param string $objectId |
|
236 | - * @param \DateTime $beforeDate |
|
237 | - * @param string $verb |
|
238 | - * @return int |
|
239 | - * @since 21.0.0 |
|
240 | - */ |
|
241 | - public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int; |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $objectType |
|
245 | - * @param string $objectId |
|
246 | - * @param string $verb |
|
247 | - * @param string $actorType |
|
248 | - * @param string[] $actors |
|
249 | - * @return \DateTime[] Map of "string actor" => "\DateTime most recent comment date" |
|
250 | - * @psalm-return array<string, \DateTime> |
|
251 | - * @since 21.0.0 |
|
252 | - */ |
|
253 | - public function getLastCommentDateByActor( |
|
254 | - string $objectType, |
|
255 | - string $objectId, |
|
256 | - string $verb, |
|
257 | - string $actorType, |
|
258 | - array $actors, |
|
259 | - ): array; |
|
260 | - |
|
261 | - /** |
|
262 | - * Get the number of unread comments for all files in a folder |
|
263 | - * |
|
264 | - * @param int $folderId |
|
265 | - * @param IUser $user |
|
266 | - * @return array [$fileId => $unreadCount] |
|
267 | - * @since 12.0.0 |
|
268 | - * @deprecated 29.0.0 use getNumberOfUnreadCommentsForObjects instead |
|
269 | - */ |
|
270 | - public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); |
|
271 | - |
|
272 | - /** |
|
273 | - * creates a new comment and returns it. At this point of time, it is not |
|
274 | - * saved in the used data storage. Use save() after setting other fields |
|
275 | - * of the comment (e.g. message or verb). |
|
276 | - * |
|
277 | - * @param string $actorType the actor type (e.g. 'users') |
|
278 | - * @param string $actorId a user id |
|
279 | - * @param string $objectType the object type the comment is attached to |
|
280 | - * @param string $objectId the object id the comment is attached to |
|
281 | - * @return IComment |
|
282 | - * @since 9.0.0 |
|
283 | - */ |
|
284 | - public function create($actorType, $actorId, $objectType, $objectId); |
|
285 | - |
|
286 | - /** |
|
287 | - * permanently deletes the comment specified by the ID |
|
288 | - * |
|
289 | - * When the comment has child comments, their parent ID will be changed to |
|
290 | - * the parent ID of the item that is to be deleted. |
|
291 | - * |
|
292 | - * @param string $id |
|
293 | - * @return bool |
|
294 | - * @since 9.0.0 |
|
295 | - */ |
|
296 | - public function delete($id); |
|
297 | - |
|
298 | - /** |
|
299 | - * Get comment related with user reaction |
|
300 | - * |
|
301 | - * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
302 | - * use reactions |
|
303 | - * |
|
304 | - * @param int $parentId |
|
305 | - * @param string $actorType |
|
306 | - * @param string $actorId |
|
307 | - * @param string $reaction |
|
308 | - * @return IComment |
|
309 | - * @throws NotFoundException |
|
310 | - * @throws PreConditionNotMetException |
|
311 | - * @since 24.0.0 |
|
312 | - */ |
|
313 | - public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment; |
|
314 | - |
|
315 | - /** |
|
316 | - * Retrieve all reactions of a message |
|
317 | - * |
|
318 | - * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
319 | - * use reactions |
|
320 | - * |
|
321 | - * @param int $parentId |
|
322 | - * @return IComment[] |
|
323 | - * @throws PreConditionNotMetException |
|
324 | - * @since 24.0.0 |
|
325 | - */ |
|
326 | - public function retrieveAllReactions(int $parentId): array; |
|
327 | - |
|
328 | - /** |
|
329 | - * Retrieve all reactions with specific reaction of a message |
|
330 | - * |
|
331 | - * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
332 | - * use reactions |
|
333 | - * |
|
334 | - * @param int $parentId |
|
335 | - * @param string $reaction |
|
336 | - * @return IComment[] |
|
337 | - * @throws PreConditionNotMetException |
|
338 | - * @since 24.0.0 |
|
339 | - */ |
|
340 | - public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array; |
|
341 | - |
|
342 | - /** |
|
343 | - * Support reactions |
|
344 | - * |
|
345 | - * @return bool |
|
346 | - * @since 24.0.0 |
|
347 | - */ |
|
348 | - public function supportReactions(): bool; |
|
349 | - |
|
350 | - /** |
|
351 | - * saves the comment permanently |
|
352 | - * |
|
353 | - * if the supplied comment has an empty ID, a new entry comment will be |
|
354 | - * saved and the instance updated with the new ID. |
|
355 | - * |
|
356 | - * Otherwise, an existing comment will be updated. |
|
357 | - * |
|
358 | - * Throws NotFoundException when a comment that is to be updated does not |
|
359 | - * exist anymore at this point of time. |
|
360 | - * |
|
361 | - * @param IComment $comment |
|
362 | - * @return bool |
|
363 | - * @throws NotFoundException |
|
364 | - * @since 9.0.0 |
|
365 | - */ |
|
366 | - public function save(IComment $comment); |
|
367 | - |
|
368 | - /** |
|
369 | - * removes references to specific actor (e.g. on user delete) of a comment. |
|
370 | - * The comment itself must not get lost/deleted. |
|
371 | - * |
|
372 | - * A 'users' type actor (type and id) should get replaced by the |
|
373 | - * value of the DELETED_USER constant of this interface. |
|
374 | - * |
|
375 | - * @param string $actorType the actor type (e.g. 'users') |
|
376 | - * @param string $actorId a user id |
|
377 | - * @return boolean |
|
378 | - * @since 9.0.0 |
|
379 | - */ |
|
380 | - public function deleteReferencesOfActor($actorType, $actorId); |
|
381 | - |
|
382 | - /** |
|
383 | - * deletes all comments made of a specific object (e.g. on file delete) |
|
384 | - * |
|
385 | - * @param string $objectType the object type (e.g. 'files') |
|
386 | - * @param string $objectId e.g. the file id |
|
387 | - * @return boolean |
|
388 | - * @since 9.0.0 |
|
389 | - */ |
|
390 | - public function deleteCommentsAtObject($objectType, $objectId); |
|
391 | - |
|
392 | - /** |
|
393 | - * sets the read marker for a given file to the specified date for the |
|
394 | - * provided user |
|
395 | - * |
|
396 | - * @param string $objectType |
|
397 | - * @param string $objectId |
|
398 | - * @param \DateTime $dateTime |
|
399 | - * @param \OCP\IUser $user |
|
400 | - * @since 9.0.0 |
|
401 | - */ |
|
402 | - public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user); |
|
403 | - |
|
404 | - /** |
|
405 | - * returns the read marker for a given file to the specified date for the |
|
406 | - * provided user. It returns null, when the marker is not present, i.e. |
|
407 | - * no comments were marked as read. |
|
408 | - * |
|
409 | - * @param string $objectType |
|
410 | - * @param string $objectId |
|
411 | - * @param \OCP\IUser $user |
|
412 | - * @return \DateTime|null |
|
413 | - * @since 9.0.0 |
|
414 | - */ |
|
415 | - public function getReadMark($objectType, $objectId, \OCP\IUser $user); |
|
416 | - |
|
417 | - /** |
|
418 | - * deletes the read markers for the specified user |
|
419 | - * |
|
420 | - * @param \OCP\IUser $user |
|
421 | - * @return bool |
|
422 | - * @since 9.0.0 |
|
423 | - */ |
|
424 | - public function deleteReadMarksFromUser(\OCP\IUser $user); |
|
425 | - |
|
426 | - /** |
|
427 | - * deletes the read markers on the specified object |
|
428 | - * |
|
429 | - * @param string $objectType |
|
430 | - * @param string $objectId |
|
431 | - * @return bool |
|
432 | - * @since 9.0.0 |
|
433 | - */ |
|
434 | - public function deleteReadMarksOnObject($objectType, $objectId); |
|
435 | - |
|
436 | - /** |
|
437 | - * registers an Entity to the manager, so event notifications can be send |
|
438 | - * to consumers of the comments infrastructure |
|
439 | - * |
|
440 | - * @param \Closure $closure |
|
441 | - * @since 11.0.0 |
|
442 | - */ |
|
443 | - public function registerEventHandler(\Closure $closure); |
|
444 | - |
|
445 | - /** |
|
446 | - * registers a method that resolves an ID to a display name for a given type |
|
447 | - * |
|
448 | - * @param string $type |
|
449 | - * @param \Closure $closure |
|
450 | - * @throws \OutOfBoundsException |
|
451 | - * @since 11.0.0 |
|
452 | - * |
|
453 | - * Only one resolver shall be registered per type. Otherwise a |
|
454 | - * \OutOfBoundsException has to thrown. |
|
455 | - */ |
|
456 | - public function registerDisplayNameResolver($type, \Closure $closure); |
|
457 | - |
|
458 | - /** |
|
459 | - * resolves a given ID of a given Type to a display name. |
|
460 | - * |
|
461 | - * @param string $type |
|
462 | - * @param string $id |
|
463 | - * @return string |
|
464 | - * @throws \OutOfBoundsException |
|
465 | - * @since 11.0.0 |
|
466 | - * |
|
467 | - * If a provided type was not registered, an \OutOfBoundsException shall |
|
468 | - * be thrown. It is upon the resolver discretion what to return of the |
|
469 | - * provided ID is unknown. It must be ensured that a string is returned. |
|
470 | - */ |
|
471 | - public function resolveDisplayName($type, $id); |
|
472 | - |
|
473 | - /** |
|
474 | - * Load the Comments app into the page |
|
475 | - * |
|
476 | - * @since 21.0.0 |
|
477 | - */ |
|
478 | - public function load(): void; |
|
479 | - |
|
480 | - /** |
|
481 | - * Delete comments with field expire_date less than current date |
|
482 | - * Only will delete the message related with the object. |
|
483 | - * |
|
484 | - * @param string $objectType the object type (e.g. 'files') |
|
485 | - * @param string $objectId e.g. the file id, leave empty to expire on all objects of this type |
|
486 | - * @return boolean true if at least one row was deleted |
|
487 | - * @since 25.0.0 |
|
488 | - */ |
|
489 | - public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool; |
|
21 | + /** |
|
22 | + * @const DELETED_USER type and id for a user that has been deleted |
|
23 | + * @see deleteReferencesOfActor |
|
24 | + * @since 9.0.0 |
|
25 | + * |
|
26 | + * To be used as replacement for user type actors in deleteReferencesOfActor(). |
|
27 | + * |
|
28 | + * User interfaces shall show "Deleted user" as display name, if needed. |
|
29 | + */ |
|
30 | + public const DELETED_USER = 'deleted_users'; |
|
31 | + |
|
32 | + /** |
|
33 | + * returns a comment instance |
|
34 | + * |
|
35 | + * @param string $id the ID of the comment |
|
36 | + * @return IComment |
|
37 | + * @throws NotFoundException |
|
38 | + * @since 9.0.0 |
|
39 | + */ |
|
40 | + public function get($id); |
|
41 | + |
|
42 | + /** |
|
43 | + * Returns the comment specified by the id and all it's child comments |
|
44 | + * |
|
45 | + * @param string $id |
|
46 | + * @param int $limit max number of entries to return, 0 returns all |
|
47 | + * @param int $offset the start entry |
|
48 | + * @return array{comment: IComment, replies: list<array{comment: IComment, replies: array<empty, empty>}>} |
|
49 | + * @since 9.0.0 |
|
50 | + * |
|
51 | + * The return array looks like this |
|
52 | + * [ |
|
53 | + * 'comment' => IComment, // root comment |
|
54 | + * 'replies' => |
|
55 | + * [ |
|
56 | + * 0 => |
|
57 | + * [ |
|
58 | + * 'comment' => IComment, |
|
59 | + * 'replies' => |
|
60 | + * [ |
|
61 | + * 0 => |
|
62 | + * [ |
|
63 | + * 'comment' => IComment, |
|
64 | + * 'replies' => [ … ] |
|
65 | + * ], |
|
66 | + * … |
|
67 | + * ] |
|
68 | + * ] |
|
69 | + * 1 => |
|
70 | + * [ |
|
71 | + * 'comment' => IComment, |
|
72 | + * 'replies'=> [ … ] |
|
73 | + * ], |
|
74 | + * … |
|
75 | + * ] |
|
76 | + * ] |
|
77 | + */ |
|
78 | + public function getTree($id, $limit = 0, $offset = 0); |
|
79 | + |
|
80 | + /** |
|
81 | + * returns comments for a specific object (e.g. a file). |
|
82 | + * |
|
83 | + * The sort order is always newest to oldest. |
|
84 | + * |
|
85 | + * @param string $objectType the object type, e.g. 'files' |
|
86 | + * @param string $objectId the id of the object |
|
87 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
88 | + * not specified, all comments are returned. |
|
89 | + * @param int $offset optional, starting point |
|
90 | + * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
91 | + * that may be returned |
|
92 | + * @return list<IComment> |
|
93 | + * @since 9.0.0 |
|
94 | + */ |
|
95 | + public function getForObject( |
|
96 | + $objectType, |
|
97 | + $objectId, |
|
98 | + $limit = 0, |
|
99 | + $offset = 0, |
|
100 | + ?\DateTime $notOlderThan = null, |
|
101 | + ); |
|
102 | + |
|
103 | + /** |
|
104 | + * @param string $objectType the object type, e.g. 'files' |
|
105 | + * @param string $objectId the id of the object |
|
106 | + * @param int $lastKnownCommentId the last known comment (will be used as offset) |
|
107 | + * @param string $sortDirection direction of the comments (`asc` or `desc`) |
|
108 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
109 | + * set to 0, all comments are returned. |
|
110 | + * @param bool $includeLastKnown |
|
111 | + * @param string $topmostParentId Limit the comments to a list of replies and its original root comment |
|
112 | + * @return list<IComment> |
|
113 | + * @since 14.0.0 |
|
114 | + * @deprecated 24.0.0 - Use getCommentsWithVerbForObjectSinceComment instead |
|
115 | + */ |
|
116 | + public function getForObjectSince( |
|
117 | + string $objectType, |
|
118 | + string $objectId, |
|
119 | + int $lastKnownCommentId, |
|
120 | + string $sortDirection = 'asc', |
|
121 | + int $limit = 30, |
|
122 | + bool $includeLastKnown = false, |
|
123 | + string $topmostParentId = '', |
|
124 | + ): array; |
|
125 | + |
|
126 | + /** |
|
127 | + * @param string $objectType the object type, e.g. 'files' |
|
128 | + * @param string $objectId the id of the object |
|
129 | + * @param string[] $verbs List of verbs to filter by |
|
130 | + * @param int $lastKnownCommentId the last known comment (will be used as offset) |
|
131 | + * @param string $sortDirection direction of the comments (`asc` or `desc`) |
|
132 | + * @param int $limit optional, number of maximum comments to be returned. if |
|
133 | + * set to 0, all comments are returned. |
|
134 | + * @param bool $includeLastKnown |
|
135 | + * @param string $topmostParentId Limit the comments to a list of replies and its original root comment |
|
136 | + * @return list<IComment> |
|
137 | + * @since 24.0.0 |
|
138 | + */ |
|
139 | + public function getCommentsWithVerbForObjectSinceComment( |
|
140 | + string $objectType, |
|
141 | + string $objectId, |
|
142 | + array $verbs, |
|
143 | + int $lastKnownCommentId, |
|
144 | + string $sortDirection = 'asc', |
|
145 | + int $limit = 30, |
|
146 | + bool $includeLastKnown = false, |
|
147 | + string $topmostParentId = '', |
|
148 | + ): array; |
|
149 | + |
|
150 | + /** |
|
151 | + * Search for comments with a given content |
|
152 | + * |
|
153 | + * @param string $search content to search for |
|
154 | + * @param string $objectType Limit the search by object type |
|
155 | + * @param string $objectId Limit the search by object id |
|
156 | + * @param string $verb Limit the verb of the comment |
|
157 | + * @param int $offset |
|
158 | + * @param int $limit |
|
159 | + * @return list<IComment> |
|
160 | + * @since 14.0.0 |
|
161 | + */ |
|
162 | + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array; |
|
163 | + |
|
164 | + /** |
|
165 | + * Search for comments on one or more objects with a given content |
|
166 | + * |
|
167 | + * @param string $search content to search for |
|
168 | + * @param string $objectType Limit the search by object type |
|
169 | + * @param array $objectIds Limit the search by object ids |
|
170 | + * @param string $verb Limit the verb of the comment |
|
171 | + * @param int $offset |
|
172 | + * @param int $limit |
|
173 | + * @return IComment[] |
|
174 | + * @since 21.0.0 |
|
175 | + */ |
|
176 | + public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array; |
|
177 | + |
|
178 | + /** |
|
179 | + * @param $objectType string the object type, e.g. 'files' |
|
180 | + * @param $objectId string the id of the object |
|
181 | + * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
182 | + * that may be returned |
|
183 | + * @param string $verb Limit the verb of the comment - Added in 14.0.0 |
|
184 | + * @return Int |
|
185 | + * @since 9.0.0 |
|
186 | + */ |
|
187 | + public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = ''); |
|
188 | + |
|
189 | + /** |
|
190 | + * @param $objectType string the object type, e.g. 'files' |
|
191 | + * @param $objectIds string[] the ids of the object |
|
192 | + * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments |
|
193 | + * that may be returned |
|
194 | + * @param string $verb Limit the verb of the comment |
|
195 | + * @return array<string, int> |
|
196 | + * @since 32.0.0 |
|
197 | + */ |
|
198 | + public function getNumberOfCommentsForObjects(string $objectType, array $objectIds, ?\DateTime $notOlderThan = null, string $verb = ''); |
|
199 | + |
|
200 | + /** |
|
201 | + * @param string $objectType the object type, e.g. 'files' |
|
202 | + * @param string[] $objectIds the id of the object |
|
203 | + * @param IUser $user |
|
204 | + * @param string $verb Limit the verb of the comment - Added in 14.0.0 |
|
205 | + * @return array Map with object id => # of unread comments |
|
206 | + * @psalm-return array<string, int> |
|
207 | + * @since 21.0.0 |
|
208 | + */ |
|
209 | + public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array; |
|
210 | + |
|
211 | + /** |
|
212 | + * @param string $objectType |
|
213 | + * @param string $objectId |
|
214 | + * @param int $lastRead |
|
215 | + * @param string $verb |
|
216 | + * @return int |
|
217 | + * @since 21.0.0 |
|
218 | + * @deprecated 24.0.0 - Use getNumberOfCommentsWithVerbsForObjectSinceComment instead |
|
219 | + */ |
|
220 | + public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int; |
|
221 | + |
|
222 | + |
|
223 | + /** |
|
224 | + * @param string $objectType |
|
225 | + * @param string $objectId |
|
226 | + * @param int $lastRead |
|
227 | + * @param string[] $verbs |
|
228 | + * @return int |
|
229 | + * @since 24.0.0 |
|
230 | + */ |
|
231 | + public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int; |
|
232 | + |
|
233 | + /** |
|
234 | + * @param string $objectType |
|
235 | + * @param string $objectId |
|
236 | + * @param \DateTime $beforeDate |
|
237 | + * @param string $verb |
|
238 | + * @return int |
|
239 | + * @since 21.0.0 |
|
240 | + */ |
|
241 | + public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int; |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $objectType |
|
245 | + * @param string $objectId |
|
246 | + * @param string $verb |
|
247 | + * @param string $actorType |
|
248 | + * @param string[] $actors |
|
249 | + * @return \DateTime[] Map of "string actor" => "\DateTime most recent comment date" |
|
250 | + * @psalm-return array<string, \DateTime> |
|
251 | + * @since 21.0.0 |
|
252 | + */ |
|
253 | + public function getLastCommentDateByActor( |
|
254 | + string $objectType, |
|
255 | + string $objectId, |
|
256 | + string $verb, |
|
257 | + string $actorType, |
|
258 | + array $actors, |
|
259 | + ): array; |
|
260 | + |
|
261 | + /** |
|
262 | + * Get the number of unread comments for all files in a folder |
|
263 | + * |
|
264 | + * @param int $folderId |
|
265 | + * @param IUser $user |
|
266 | + * @return array [$fileId => $unreadCount] |
|
267 | + * @since 12.0.0 |
|
268 | + * @deprecated 29.0.0 use getNumberOfUnreadCommentsForObjects instead |
|
269 | + */ |
|
270 | + public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user); |
|
271 | + |
|
272 | + /** |
|
273 | + * creates a new comment and returns it. At this point of time, it is not |
|
274 | + * saved in the used data storage. Use save() after setting other fields |
|
275 | + * of the comment (e.g. message or verb). |
|
276 | + * |
|
277 | + * @param string $actorType the actor type (e.g. 'users') |
|
278 | + * @param string $actorId a user id |
|
279 | + * @param string $objectType the object type the comment is attached to |
|
280 | + * @param string $objectId the object id the comment is attached to |
|
281 | + * @return IComment |
|
282 | + * @since 9.0.0 |
|
283 | + */ |
|
284 | + public function create($actorType, $actorId, $objectType, $objectId); |
|
285 | + |
|
286 | + /** |
|
287 | + * permanently deletes the comment specified by the ID |
|
288 | + * |
|
289 | + * When the comment has child comments, their parent ID will be changed to |
|
290 | + * the parent ID of the item that is to be deleted. |
|
291 | + * |
|
292 | + * @param string $id |
|
293 | + * @return bool |
|
294 | + * @since 9.0.0 |
|
295 | + */ |
|
296 | + public function delete($id); |
|
297 | + |
|
298 | + /** |
|
299 | + * Get comment related with user reaction |
|
300 | + * |
|
301 | + * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
302 | + * use reactions |
|
303 | + * |
|
304 | + * @param int $parentId |
|
305 | + * @param string $actorType |
|
306 | + * @param string $actorId |
|
307 | + * @param string $reaction |
|
308 | + * @return IComment |
|
309 | + * @throws NotFoundException |
|
310 | + * @throws PreConditionNotMetException |
|
311 | + * @since 24.0.0 |
|
312 | + */ |
|
313 | + public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment; |
|
314 | + |
|
315 | + /** |
|
316 | + * Retrieve all reactions of a message |
|
317 | + * |
|
318 | + * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
319 | + * use reactions |
|
320 | + * |
|
321 | + * @param int $parentId |
|
322 | + * @return IComment[] |
|
323 | + * @throws PreConditionNotMetException |
|
324 | + * @since 24.0.0 |
|
325 | + */ |
|
326 | + public function retrieveAllReactions(int $parentId): array; |
|
327 | + |
|
328 | + /** |
|
329 | + * Retrieve all reactions with specific reaction of a message |
|
330 | + * |
|
331 | + * Throws PreConditionNotMetException when the system haven't the minimum requirements to |
|
332 | + * use reactions |
|
333 | + * |
|
334 | + * @param int $parentId |
|
335 | + * @param string $reaction |
|
336 | + * @return IComment[] |
|
337 | + * @throws PreConditionNotMetException |
|
338 | + * @since 24.0.0 |
|
339 | + */ |
|
340 | + public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array; |
|
341 | + |
|
342 | + /** |
|
343 | + * Support reactions |
|
344 | + * |
|
345 | + * @return bool |
|
346 | + * @since 24.0.0 |
|
347 | + */ |
|
348 | + public function supportReactions(): bool; |
|
349 | + |
|
350 | + /** |
|
351 | + * saves the comment permanently |
|
352 | + * |
|
353 | + * if the supplied comment has an empty ID, a new entry comment will be |
|
354 | + * saved and the instance updated with the new ID. |
|
355 | + * |
|
356 | + * Otherwise, an existing comment will be updated. |
|
357 | + * |
|
358 | + * Throws NotFoundException when a comment that is to be updated does not |
|
359 | + * exist anymore at this point of time. |
|
360 | + * |
|
361 | + * @param IComment $comment |
|
362 | + * @return bool |
|
363 | + * @throws NotFoundException |
|
364 | + * @since 9.0.0 |
|
365 | + */ |
|
366 | + public function save(IComment $comment); |
|
367 | + |
|
368 | + /** |
|
369 | + * removes references to specific actor (e.g. on user delete) of a comment. |
|
370 | + * The comment itself must not get lost/deleted. |
|
371 | + * |
|
372 | + * A 'users' type actor (type and id) should get replaced by the |
|
373 | + * value of the DELETED_USER constant of this interface. |
|
374 | + * |
|
375 | + * @param string $actorType the actor type (e.g. 'users') |
|
376 | + * @param string $actorId a user id |
|
377 | + * @return boolean |
|
378 | + * @since 9.0.0 |
|
379 | + */ |
|
380 | + public function deleteReferencesOfActor($actorType, $actorId); |
|
381 | + |
|
382 | + /** |
|
383 | + * deletes all comments made of a specific object (e.g. on file delete) |
|
384 | + * |
|
385 | + * @param string $objectType the object type (e.g. 'files') |
|
386 | + * @param string $objectId e.g. the file id |
|
387 | + * @return boolean |
|
388 | + * @since 9.0.0 |
|
389 | + */ |
|
390 | + public function deleteCommentsAtObject($objectType, $objectId); |
|
391 | + |
|
392 | + /** |
|
393 | + * sets the read marker for a given file to the specified date for the |
|
394 | + * provided user |
|
395 | + * |
|
396 | + * @param string $objectType |
|
397 | + * @param string $objectId |
|
398 | + * @param \DateTime $dateTime |
|
399 | + * @param \OCP\IUser $user |
|
400 | + * @since 9.0.0 |
|
401 | + */ |
|
402 | + public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user); |
|
403 | + |
|
404 | + /** |
|
405 | + * returns the read marker for a given file to the specified date for the |
|
406 | + * provided user. It returns null, when the marker is not present, i.e. |
|
407 | + * no comments were marked as read. |
|
408 | + * |
|
409 | + * @param string $objectType |
|
410 | + * @param string $objectId |
|
411 | + * @param \OCP\IUser $user |
|
412 | + * @return \DateTime|null |
|
413 | + * @since 9.0.0 |
|
414 | + */ |
|
415 | + public function getReadMark($objectType, $objectId, \OCP\IUser $user); |
|
416 | + |
|
417 | + /** |
|
418 | + * deletes the read markers for the specified user |
|
419 | + * |
|
420 | + * @param \OCP\IUser $user |
|
421 | + * @return bool |
|
422 | + * @since 9.0.0 |
|
423 | + */ |
|
424 | + public function deleteReadMarksFromUser(\OCP\IUser $user); |
|
425 | + |
|
426 | + /** |
|
427 | + * deletes the read markers on the specified object |
|
428 | + * |
|
429 | + * @param string $objectType |
|
430 | + * @param string $objectId |
|
431 | + * @return bool |
|
432 | + * @since 9.0.0 |
|
433 | + */ |
|
434 | + public function deleteReadMarksOnObject($objectType, $objectId); |
|
435 | + |
|
436 | + /** |
|
437 | + * registers an Entity to the manager, so event notifications can be send |
|
438 | + * to consumers of the comments infrastructure |
|
439 | + * |
|
440 | + * @param \Closure $closure |
|
441 | + * @since 11.0.0 |
|
442 | + */ |
|
443 | + public function registerEventHandler(\Closure $closure); |
|
444 | + |
|
445 | + /** |
|
446 | + * registers a method that resolves an ID to a display name for a given type |
|
447 | + * |
|
448 | + * @param string $type |
|
449 | + * @param \Closure $closure |
|
450 | + * @throws \OutOfBoundsException |
|
451 | + * @since 11.0.0 |
|
452 | + * |
|
453 | + * Only one resolver shall be registered per type. Otherwise a |
|
454 | + * \OutOfBoundsException has to thrown. |
|
455 | + */ |
|
456 | + public function registerDisplayNameResolver($type, \Closure $closure); |
|
457 | + |
|
458 | + /** |
|
459 | + * resolves a given ID of a given Type to a display name. |
|
460 | + * |
|
461 | + * @param string $type |
|
462 | + * @param string $id |
|
463 | + * @return string |
|
464 | + * @throws \OutOfBoundsException |
|
465 | + * @since 11.0.0 |
|
466 | + * |
|
467 | + * If a provided type was not registered, an \OutOfBoundsException shall |
|
468 | + * be thrown. It is upon the resolver discretion what to return of the |
|
469 | + * provided ID is unknown. It must be ensured that a string is returned. |
|
470 | + */ |
|
471 | + public function resolveDisplayName($type, $id); |
|
472 | + |
|
473 | + /** |
|
474 | + * Load the Comments app into the page |
|
475 | + * |
|
476 | + * @since 21.0.0 |
|
477 | + */ |
|
478 | + public function load(): void; |
|
479 | + |
|
480 | + /** |
|
481 | + * Delete comments with field expire_date less than current date |
|
482 | + * Only will delete the message related with the object. |
|
483 | + * |
|
484 | + * @param string $objectType the object type (e.g. 'files') |
|
485 | + * @param string $objectId e.g. the file id, leave empty to expire on all objects of this type |
|
486 | + * @return boolean true if at least one row was deleted |
|
487 | + * @since 25.0.0 |
|
488 | + */ |
|
489 | + public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool; |
|
490 | 490 | } |
@@ -30,1558 +30,1558 @@ |
||
30 | 30 | use Psr\Log\LoggerInterface; |
31 | 31 | |
32 | 32 | class Manager implements ICommentsManager { |
33 | - /** @var IComment[] */ |
|
34 | - protected array $commentsCache = []; |
|
35 | - |
|
36 | - /** @var \Closure[] */ |
|
37 | - protected array $eventHandlerClosures = []; |
|
38 | - |
|
39 | - /** @var ICommentsEventHandler[] */ |
|
40 | - protected array $eventHandlers = []; |
|
41 | - |
|
42 | - /** @var \Closure[] */ |
|
43 | - protected array $displayNameResolvers = []; |
|
44 | - |
|
45 | - public function __construct( |
|
46 | - protected IDBConnection $dbConn, |
|
47 | - protected LoggerInterface $logger, |
|
48 | - protected IConfig $config, |
|
49 | - protected ITimeFactory $timeFactory, |
|
50 | - protected IEmojiHelper $emojiHelper, |
|
51 | - protected IInitialStateService $initialStateService, |
|
52 | - protected IRootFolder $rootFolder, |
|
53 | - protected IEventDispatcher $eventDispatcher, |
|
54 | - ) { |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * converts data base data into PHP native, proper types as defined by |
|
59 | - * IComment interface. |
|
60 | - * |
|
61 | - * @param array $data |
|
62 | - */ |
|
63 | - protected function normalizeDatabaseData(array $data): array { |
|
64 | - $data['id'] = (string)$data['id']; |
|
65 | - $data['parent_id'] = (string)$data['parent_id']; |
|
66 | - $data['topmost_parent_id'] = (string)$data['topmost_parent_id']; |
|
67 | - $data['creation_timestamp'] = new \DateTime($data['creation_timestamp']); |
|
68 | - if (!is_null($data['latest_child_timestamp'])) { |
|
69 | - $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); |
|
70 | - } |
|
71 | - if (!is_null($data['expire_date'])) { |
|
72 | - $data['expire_date'] = new \DateTime($data['expire_date']); |
|
73 | - } |
|
74 | - $data['children_count'] = (int)$data['children_count']; |
|
75 | - $data['reference_id'] = $data['reference_id']; |
|
76 | - $data['meta_data'] = json_decode($data['meta_data'], true); |
|
77 | - if ($this->supportReactions()) { |
|
78 | - if ($data['reactions'] !== null) { |
|
79 | - $list = json_decode($data['reactions'], true); |
|
80 | - // Ordering does not work on the database with group concat and Oracle, |
|
81 | - // So we simply sort on the output. |
|
82 | - if (is_array($list)) { |
|
83 | - uasort($list, static function ($a, $b) { |
|
84 | - if ($a === $b) { |
|
85 | - return 0; |
|
86 | - } |
|
87 | - return ($a > $b) ? -1 : 1; |
|
88 | - }); |
|
89 | - $data['reactions'] = $list; |
|
90 | - } else { |
|
91 | - $data['reactions'] = []; |
|
92 | - } |
|
93 | - } else { |
|
94 | - $data['reactions'] = []; |
|
95 | - } |
|
96 | - } |
|
97 | - return $data; |
|
98 | - } |
|
99 | - |
|
100 | - public function getCommentFromData(array $data): IComment { |
|
101 | - return new Comment($this->normalizeDatabaseData($data)); |
|
102 | - } |
|
103 | - |
|
104 | - /** |
|
105 | - * prepares a comment for an insert or update operation after making sure |
|
106 | - * all necessary fields have a value assigned. |
|
107 | - * |
|
108 | - * @param IComment $comment |
|
109 | - * @return IComment returns the same updated IComment instance as provided |
|
110 | - * by parameter for convenience |
|
111 | - * @throws \UnexpectedValueException |
|
112 | - */ |
|
113 | - protected function prepareCommentForDatabaseWrite(IComment $comment): IComment { |
|
114 | - if (!$comment->getActorType() |
|
115 | - || $comment->getActorId() === '' |
|
116 | - || !$comment->getObjectType() |
|
117 | - || $comment->getObjectId() === '' |
|
118 | - || !$comment->getVerb() |
|
119 | - ) { |
|
120 | - throw new \UnexpectedValueException('Actor, Object and Verb information must be provided for saving'); |
|
121 | - } |
|
122 | - |
|
123 | - if ($comment->getVerb() === 'reaction' && !$this->emojiHelper->isValidSingleEmoji($comment->getMessage())) { |
|
124 | - // 4 characters: laptop + person + gender + skin color => " |
@@ -61,9 +61,9 @@ discard block |
||
61 | 61 | * @param array $data |
62 | 62 | */ |
63 | 63 | protected function normalizeDatabaseData(array $data): array { |
64 | - $data['id'] = (string)$data['id']; |
|
65 | - $data['parent_id'] = (string)$data['parent_id']; |
|
66 | - $data['topmost_parent_id'] = (string)$data['topmost_parent_id']; |
|
64 | + $data['id'] = (string) $data['id']; |
|
65 | + $data['parent_id'] = (string) $data['parent_id']; |
|
66 | + $data['topmost_parent_id'] = (string) $data['topmost_parent_id']; |
|
67 | 67 | $data['creation_timestamp'] = new \DateTime($data['creation_timestamp']); |
68 | 68 | if (!is_null($data['latest_child_timestamp'])) { |
69 | 69 | $data['latest_child_timestamp'] = new \DateTime($data['latest_child_timestamp']); |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if (!is_null($data['expire_date'])) { |
72 | 72 | $data['expire_date'] = new \DateTime($data['expire_date']); |
73 | 73 | } |
74 | - $data['children_count'] = (int)$data['children_count']; |
|
74 | + $data['children_count'] = (int) $data['children_count']; |
|
75 | 75 | $data['reference_id'] = $data['reference_id']; |
76 | 76 | $data['meta_data'] = json_decode($data['meta_data'], true); |
77 | 77 | if ($this->supportReactions()) { |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | // Ordering does not work on the database with group concat and Oracle, |
81 | 81 | // So we simply sort on the output. |
82 | 82 | if (is_array($list)) { |
83 | - uasort($list, static function ($a, $b) { |
|
83 | + uasort($list, static function($a, $b) { |
|
84 | 84 | if ($a === $b) { |
85 | 85 | return 0; |
86 | 86 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | $resultStatement = $query->execute(); |
180 | 180 | $data = $resultStatement->fetch(\PDO::FETCH_NUM); |
181 | 181 | $resultStatement->closeCursor(); |
182 | - $children = (int)$data[0]; |
|
182 | + $children = (int) $data[0]; |
|
183 | 183 | |
184 | 184 | $comment = $this->get($id); |
185 | 185 | $comment->setChildrenCount($children); |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | !is_string($type) || empty($type) |
202 | 202 | || !is_string($id) || empty($id) |
203 | 203 | ) { |
204 | - throw new \InvalidArgumentException($role . ' parameters must be string and not empty'); |
|
204 | + throw new \InvalidArgumentException($role.' parameters must be string and not empty'); |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | if (empty($id)) { |
214 | 214 | return; |
215 | 215 | } |
216 | - $this->commentsCache[(string)$id] = $comment; |
|
216 | + $this->commentsCache[(string) $id] = $comment; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | /** |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | * @param mixed $id the comment's id |
223 | 223 | */ |
224 | 224 | protected function uncache($id): void { |
225 | - $id = (string)$id; |
|
225 | + $id = (string) $id; |
|
226 | 226 | if (isset($this->commentsCache[$id])) { |
227 | 227 | unset($this->commentsCache[$id]); |
228 | 228 | } |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | * @since 9.0.0 |
238 | 238 | */ |
239 | 239 | public function get($id): IComment { |
240 | - if ((int)$id === 0) { |
|
240 | + if ((int) $id === 0) { |
|
241 | 241 | throw new \InvalidArgumentException('IDs must be translatable to a number in this implementation.'); |
242 | 242 | } |
243 | 243 | |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | |
588 | 588 | if ($search !== '') { |
589 | 589 | $query->where($query->expr()->iLike('message', $query->createNamedParameter( |
590 | - '%' . $this->dbConn->escapeLikeParameter($search) . '%' |
|
590 | + '%'.$this->dbConn->escapeLikeParameter($search).'%' |
|
591 | 591 | ))); |
592 | 592 | } |
593 | 593 | |
@@ -651,7 +651,7 @@ discard block |
||
651 | 651 | $comments = array_fill_keys($objectIds, 0); |
652 | 652 | $resultStatement = $query->execute(); |
653 | 653 | while ($data = $resultStatement->fetch()) { |
654 | - $comments[$data['object_id']] = (int)$data['num_comments']; |
|
654 | + $comments[$data['object_id']] = (int) $data['num_comments']; |
|
655 | 655 | } |
656 | 656 | $resultStatement->closeCursor(); |
657 | 657 | |
@@ -695,7 +695,7 @@ discard block |
||
695 | 695 | |
696 | 696 | $result = $query->executeQuery(); |
697 | 697 | while ($row = $result->fetch()) { |
698 | - $unreadComments[$row['object_id']] = (int)$row['num_comments']; |
|
698 | + $unreadComments[$row['object_id']] = (int) $row['num_comments']; |
|
699 | 699 | } |
700 | 700 | $result->closeCursor(); |
701 | 701 | } |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | $data = $result->fetch(); |
744 | 744 | $result->closeCursor(); |
745 | 745 | |
746 | - return (int)($data['num_messages'] ?? 0); |
|
746 | + return (int) ($data['num_messages'] ?? 0); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -771,7 +771,7 @@ discard block |
||
771 | 771 | $data = $result->fetch(); |
772 | 772 | $result->closeCursor(); |
773 | 773 | |
774 | - return (int)($data['id'] ?? 0); |
|
774 | + return (int) ($data['id'] ?? 0); |
|
775 | 775 | } |
776 | 776 | |
777 | 777 | /** |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | |
796 | 796 | $query = $this->dbConn->getQueryBuilder(); |
797 | 797 | $query->select('actor_id') |
798 | - ->selectAlias($query->createFunction('MAX(' . $query->getColumnName('creation_timestamp') . ')'), 'last_comment') |
|
798 | + ->selectAlias($query->createFunction('MAX('.$query->getColumnName('creation_timestamp').')'), 'last_comment') |
|
799 | 799 | ->from('comments') |
800 | 800 | ->where($query->expr()->eq('object_type', $query->createNamedParameter($objectType))) |
801 | 801 | ->andWhere($query->expr()->eq('object_id', $query->createNamedParameter($objectId))) |
@@ -828,11 +828,11 @@ discard block |
||
828 | 828 | return []; |
829 | 829 | } |
830 | 830 | $children = $directory->getDirectoryListing(); |
831 | - $ids = array_map(fn (FileInfo $child) => (string)$child->getId(), $children); |
|
831 | + $ids = array_map(fn (FileInfo $child) => (string) $child->getId(), $children); |
|
832 | 832 | |
833 | - $ids[] = (string)$directory->getId(); |
|
833 | + $ids[] = (string) $directory->getId(); |
|
834 | 834 | $counts = $this->getNumberOfUnreadCommentsForObjects('files', $ids, $user); |
835 | - return array_filter($counts, function (int $count) { |
|
835 | + return array_filter($counts, function(int $count) { |
|
836 | 836 | return $count > 0; |
837 | 837 | }); |
838 | 838 | } |
@@ -1099,7 +1099,7 @@ discard block |
||
1099 | 1099 | $result = $this->update($comment); |
1100 | 1100 | } |
1101 | 1101 | |
1102 | - if ($result && (bool)$comment->getParentId()) { |
|
1102 | + if ($result && (bool) $comment->getParentId()) { |
|
1103 | 1103 | $this->updateChildrenInformation( |
1104 | 1104 | $comment->getParentId(), |
1105 | 1105 | $comment->getCreationDateTime() |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | ->execute(); |
1142 | 1142 | |
1143 | 1143 | if ($affectedRows > 0) { |
1144 | - $comment->setId((string)$qb->getLastInsertId()); |
|
1144 | + $comment->setId((string) $qb->getLastInsertId()); |
|
1145 | 1145 | if ($comment->getVerb() === 'reaction') { |
1146 | 1146 | $this->addReaction($comment); |
1147 | 1147 | } |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | ->andWhere($qb->expr()->eq('actor_id', $qb->createNamedParameter($reaction->getActorId()))) |
1162 | 1162 | ->andWhere($qb->expr()->eq('reaction', $qb->createNamedParameter($reaction->getMessage()))); |
1163 | 1163 | $result = $qb->executeQuery(); |
1164 | - $exists = (int)$result->fetchOne(); |
|
1164 | + $exists = (int) $result->fetchOne(); |
|
1165 | 1165 | if (!$exists) { |
1166 | 1166 | $qb = $this->dbConn->getQueryBuilder(); |
1167 | 1167 | try { |
@@ -1214,12 +1214,12 @@ discard block |
||
1214 | 1214 | ), |
1215 | 1215 | 'json' |
1216 | 1216 | ) |
1217 | - ->from($jsonQuery->createFunction('(' . $totalQuery->getSQL() . ')'), 'json'); |
|
1217 | + ->from($jsonQuery->createFunction('('.$totalQuery->getSQL().')'), 'json'); |
|
1218 | 1218 | |
1219 | 1219 | $qb = $this->dbConn->getQueryBuilder(); |
1220 | 1220 | $qb |
1221 | 1221 | ->update('comments') |
1222 | - ->set('reactions', $qb->createFunction('(' . $jsonQuery->getSQL() . ')')) |
|
1222 | + ->set('reactions', $qb->createFunction('('.$jsonQuery->getSQL().')')) |
|
1223 | 1223 | ->where($qb->expr()->eq('id', $qb->createNamedParameter($parentId))) |
1224 | 1224 | ->executeStatement(); |
1225 | 1225 | } |
@@ -1514,7 +1514,7 @@ discard block |
||
1514 | 1514 | if (!isset($this->displayNameResolvers[$type])) { |
1515 | 1515 | throw new \OutOfBoundsException('No Displayname resolver for this type registered'); |
1516 | 1516 | } |
1517 | - return (string)$this->displayNameResolvers[$type]($id); |
|
1517 | + return (string) $this->displayNameResolvers[$type]($id); |
|
1518 | 1518 | } |
1519 | 1519 | |
1520 | 1520 | /** |
@@ -16,152 +16,152 @@ |
||
16 | 16 | use Sabre\DAV\ServerPlugin; |
17 | 17 | |
18 | 18 | class CommentPropertiesPlugin extends ServerPlugin { |
19 | - public const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
20 | - public const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
21 | - public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
22 | - |
|
23 | - protected ?Server $server = null; |
|
24 | - private array $cachedUnreadCount = []; |
|
25 | - private array $cachedCount = []; |
|
26 | - private array $cachedDirectories = []; |
|
27 | - |
|
28 | - public function __construct( |
|
29 | - private ICommentsManager $commentsManager, |
|
30 | - private IUserSession $userSession, |
|
31 | - ) { |
|
32 | - } |
|
33 | - |
|
34 | - /** |
|
35 | - * This initializes the plugin. |
|
36 | - * |
|
37 | - * This function is called by Sabre\DAV\Server, after |
|
38 | - * addPlugin is called. |
|
39 | - * |
|
40 | - * This method should set up the required event subscriptions. |
|
41 | - * |
|
42 | - * @param \Sabre\DAV\Server $server |
|
43 | - * @return void |
|
44 | - */ |
|
45 | - public function initialize(\Sabre\DAV\Server $server) { |
|
46 | - $this->server = $server; |
|
47 | - |
|
48 | - $this->server->on('preloadCollection', $this->preloadCollection(...)); |
|
49 | - $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
50 | - } |
|
51 | - |
|
52 | - private function cacheDirectory(Directory $directory, PropFind $propFind): void { |
|
53 | - if (is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) && is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) { |
|
54 | - return; |
|
55 | - } |
|
56 | - |
|
57 | - $children = $directory->getChildren(); |
|
58 | - |
|
59 | - $ids = []; |
|
60 | - foreach ($children as $child) { |
|
61 | - if (!($child instanceof File || $child instanceof Directory)) { |
|
62 | - continue; |
|
63 | - } |
|
64 | - |
|
65 | - $id = $child->getId(); |
|
66 | - if ($id === null) { |
|
67 | - continue; |
|
68 | - } |
|
69 | - |
|
70 | - $ids[] = (string)$id; |
|
71 | - } |
|
72 | - |
|
73 | - $ids[] = (string)$directory->getId(); |
|
74 | - if (!is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD))) { |
|
75 | - $user = $this->userSession->getUser(); |
|
76 | - if ($user) { |
|
77 | - $unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $user); |
|
78 | - foreach ($unread as $id => $count) { |
|
79 | - $this->cachedUnreadCount[(int)$id] = $count; |
|
80 | - } |
|
81 | - } else { |
|
82 | - foreach ($ids as $id) { |
|
83 | - $this->cachedUnreadCount[(int)$id] = null; |
|
84 | - } |
|
85 | - } |
|
86 | - } |
|
87 | - |
|
88 | - if (!is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) { |
|
89 | - $commentCounts = $this->commentsManager->getNumberOfCommentsForObjects('files', $ids); |
|
90 | - foreach ($commentCounts as $id => $count) { |
|
91 | - $this->cachedCount[(int)$id] = $count; |
|
92 | - } |
|
93 | - } |
|
94 | - |
|
95 | - } |
|
96 | - |
|
97 | - private function preloadCollection(PropFind $propFind, ICollection $collection): void { |
|
98 | - if (!($collection instanceof Directory)) { |
|
99 | - return; |
|
100 | - } |
|
101 | - |
|
102 | - $collectionPath = $collection->getPath(); |
|
103 | - if (!isset($this->cachedDirectories[$collectionPath]) && ( |
|
104 | - $propFind->getStatus(self::PROPERTY_NAME_UNREAD) !== null |
|
105 | - || $propFind->getStatus(self::PROPERTY_NAME_COUNT) !== null)) { |
|
106 | - $this->cacheDirectory($collection, $propFind); |
|
107 | - $this->cachedDirectories[$collectionPath] = true; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - /** |
|
112 | - * Adds tags and favorites properties to the response, |
|
113 | - * if requested. |
|
114 | - * |
|
115 | - * @param PropFind $propFind |
|
116 | - * @param \Sabre\DAV\INode $node |
|
117 | - * @return void |
|
118 | - */ |
|
119 | - public function handleGetProperties( |
|
120 | - PropFind $propFind, |
|
121 | - \Sabre\DAV\INode $node, |
|
122 | - ) { |
|
123 | - if (!($node instanceof File) && !($node instanceof Directory)) { |
|
124 | - return; |
|
125 | - } |
|
126 | - |
|
127 | - $propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int { |
|
128 | - return $this->cachedCount[$node->getId()] ?? $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId()); |
|
129 | - }); |
|
130 | - |
|
131 | - $propFind->handle(self::PROPERTY_NAME_HREF, function () use ($node): ?string { |
|
132 | - return $this->getCommentsLink($node); |
|
133 | - }); |
|
134 | - |
|
135 | - $propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node): ?int { |
|
136 | - return $this->cachedUnreadCount[$node->getId()] ?? $this->getUnreadCount($node); |
|
137 | - }); |
|
138 | - } |
|
139 | - |
|
140 | - /** |
|
141 | - * Returns a reference to the comments node |
|
142 | - */ |
|
143 | - public function getCommentsLink(Node $node): ?string { |
|
144 | - $href = $this->server->getBaseUri(); |
|
145 | - $entryPoint = strpos($href, '/remote.php/'); |
|
146 | - if ($entryPoint === false) { |
|
147 | - // in case we end up somewhere else, unexpectedly. |
|
148 | - return null; |
|
149 | - } |
|
150 | - $commentsPart = 'dav/comments/files/' . rawurldecode((string)$node->getId()); |
|
151 | - return substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns the number of unread comments for the currently logged in user |
|
156 | - * on the given file or directory node |
|
157 | - */ |
|
158 | - public function getUnreadCount(Node $node): ?int { |
|
159 | - $user = $this->userSession->getUser(); |
|
160 | - if (is_null($user)) { |
|
161 | - return null; |
|
162 | - } |
|
163 | - |
|
164 | - $objectId = (string)$node->getId(); |
|
165 | - return $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', [$objectId], $user)[$objectId]; |
|
166 | - } |
|
19 | + public const PROPERTY_NAME_HREF = '{http://owncloud.org/ns}comments-href'; |
|
20 | + public const PROPERTY_NAME_COUNT = '{http://owncloud.org/ns}comments-count'; |
|
21 | + public const PROPERTY_NAME_UNREAD = '{http://owncloud.org/ns}comments-unread'; |
|
22 | + |
|
23 | + protected ?Server $server = null; |
|
24 | + private array $cachedUnreadCount = []; |
|
25 | + private array $cachedCount = []; |
|
26 | + private array $cachedDirectories = []; |
|
27 | + |
|
28 | + public function __construct( |
|
29 | + private ICommentsManager $commentsManager, |
|
30 | + private IUserSession $userSession, |
|
31 | + ) { |
|
32 | + } |
|
33 | + |
|
34 | + /** |
|
35 | + * This initializes the plugin. |
|
36 | + * |
|
37 | + * This function is called by Sabre\DAV\Server, after |
|
38 | + * addPlugin is called. |
|
39 | + * |
|
40 | + * This method should set up the required event subscriptions. |
|
41 | + * |
|
42 | + * @param \Sabre\DAV\Server $server |
|
43 | + * @return void |
|
44 | + */ |
|
45 | + public function initialize(\Sabre\DAV\Server $server) { |
|
46 | + $this->server = $server; |
|
47 | + |
|
48 | + $this->server->on('preloadCollection', $this->preloadCollection(...)); |
|
49 | + $this->server->on('propFind', [$this, 'handleGetProperties']); |
|
50 | + } |
|
51 | + |
|
52 | + private function cacheDirectory(Directory $directory, PropFind $propFind): void { |
|
53 | + if (is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD)) && is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) { |
|
54 | + return; |
|
55 | + } |
|
56 | + |
|
57 | + $children = $directory->getChildren(); |
|
58 | + |
|
59 | + $ids = []; |
|
60 | + foreach ($children as $child) { |
|
61 | + if (!($child instanceof File || $child instanceof Directory)) { |
|
62 | + continue; |
|
63 | + } |
|
64 | + |
|
65 | + $id = $child->getId(); |
|
66 | + if ($id === null) { |
|
67 | + continue; |
|
68 | + } |
|
69 | + |
|
70 | + $ids[] = (string)$id; |
|
71 | + } |
|
72 | + |
|
73 | + $ids[] = (string)$directory->getId(); |
|
74 | + if (!is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD))) { |
|
75 | + $user = $this->userSession->getUser(); |
|
76 | + if ($user) { |
|
77 | + $unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $user); |
|
78 | + foreach ($unread as $id => $count) { |
|
79 | + $this->cachedUnreadCount[(int)$id] = $count; |
|
80 | + } |
|
81 | + } else { |
|
82 | + foreach ($ids as $id) { |
|
83 | + $this->cachedUnreadCount[(int)$id] = null; |
|
84 | + } |
|
85 | + } |
|
86 | + } |
|
87 | + |
|
88 | + if (!is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) { |
|
89 | + $commentCounts = $this->commentsManager->getNumberOfCommentsForObjects('files', $ids); |
|
90 | + foreach ($commentCounts as $id => $count) { |
|
91 | + $this->cachedCount[(int)$id] = $count; |
|
92 | + } |
|
93 | + } |
|
94 | + |
|
95 | + } |
|
96 | + |
|
97 | + private function preloadCollection(PropFind $propFind, ICollection $collection): void { |
|
98 | + if (!($collection instanceof Directory)) { |
|
99 | + return; |
|
100 | + } |
|
101 | + |
|
102 | + $collectionPath = $collection->getPath(); |
|
103 | + if (!isset($this->cachedDirectories[$collectionPath]) && ( |
|
104 | + $propFind->getStatus(self::PROPERTY_NAME_UNREAD) !== null |
|
105 | + || $propFind->getStatus(self::PROPERTY_NAME_COUNT) !== null)) { |
|
106 | + $this->cacheDirectory($collection, $propFind); |
|
107 | + $this->cachedDirectories[$collectionPath] = true; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + /** |
|
112 | + * Adds tags and favorites properties to the response, |
|
113 | + * if requested. |
|
114 | + * |
|
115 | + * @param PropFind $propFind |
|
116 | + * @param \Sabre\DAV\INode $node |
|
117 | + * @return void |
|
118 | + */ |
|
119 | + public function handleGetProperties( |
|
120 | + PropFind $propFind, |
|
121 | + \Sabre\DAV\INode $node, |
|
122 | + ) { |
|
123 | + if (!($node instanceof File) && !($node instanceof Directory)) { |
|
124 | + return; |
|
125 | + } |
|
126 | + |
|
127 | + $propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int { |
|
128 | + return $this->cachedCount[$node->getId()] ?? $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId()); |
|
129 | + }); |
|
130 | + |
|
131 | + $propFind->handle(self::PROPERTY_NAME_HREF, function () use ($node): ?string { |
|
132 | + return $this->getCommentsLink($node); |
|
133 | + }); |
|
134 | + |
|
135 | + $propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node): ?int { |
|
136 | + return $this->cachedUnreadCount[$node->getId()] ?? $this->getUnreadCount($node); |
|
137 | + }); |
|
138 | + } |
|
139 | + |
|
140 | + /** |
|
141 | + * Returns a reference to the comments node |
|
142 | + */ |
|
143 | + public function getCommentsLink(Node $node): ?string { |
|
144 | + $href = $this->server->getBaseUri(); |
|
145 | + $entryPoint = strpos($href, '/remote.php/'); |
|
146 | + if ($entryPoint === false) { |
|
147 | + // in case we end up somewhere else, unexpectedly. |
|
148 | + return null; |
|
149 | + } |
|
150 | + $commentsPart = 'dav/comments/files/' . rawurldecode((string)$node->getId()); |
|
151 | + return substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns the number of unread comments for the currently logged in user |
|
156 | + * on the given file or directory node |
|
157 | + */ |
|
158 | + public function getUnreadCount(Node $node): ?int { |
|
159 | + $user = $this->userSession->getUser(); |
|
160 | + if (is_null($user)) { |
|
161 | + return null; |
|
162 | + } |
|
163 | + |
|
164 | + $objectId = (string)$node->getId(); |
|
165 | + return $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', [$objectId], $user)[$objectId]; |
|
166 | + } |
|
167 | 167 | } |
@@ -67,20 +67,20 @@ discard block |
||
67 | 67 | continue; |
68 | 68 | } |
69 | 69 | |
70 | - $ids[] = (string)$id; |
|
70 | + $ids[] = (string) $id; |
|
71 | 71 | } |
72 | 72 | |
73 | - $ids[] = (string)$directory->getId(); |
|
73 | + $ids[] = (string) $directory->getId(); |
|
74 | 74 | if (!is_null($propFind->getStatus(self::PROPERTY_NAME_UNREAD))) { |
75 | 75 | $user = $this->userSession->getUser(); |
76 | 76 | if ($user) { |
77 | 77 | $unread = $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', $ids, $user); |
78 | 78 | foreach ($unread as $id => $count) { |
79 | - $this->cachedUnreadCount[(int)$id] = $count; |
|
79 | + $this->cachedUnreadCount[(int) $id] = $count; |
|
80 | 80 | } |
81 | 81 | } else { |
82 | 82 | foreach ($ids as $id) { |
83 | - $this->cachedUnreadCount[(int)$id] = null; |
|
83 | + $this->cachedUnreadCount[(int) $id] = null; |
|
84 | 84 | } |
85 | 85 | } |
86 | 86 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | if (!is_null($propFind->getStatus(self::PROPERTY_NAME_COUNT))) { |
89 | 89 | $commentCounts = $this->commentsManager->getNumberOfCommentsForObjects('files', $ids); |
90 | 90 | foreach ($commentCounts as $id => $count) { |
91 | - $this->cachedCount[(int)$id] = $count; |
|
91 | + $this->cachedCount[(int) $id] = $count; |
|
92 | 92 | } |
93 | 93 | } |
94 | 94 | |
@@ -124,15 +124,15 @@ discard block |
||
124 | 124 | return; |
125 | 125 | } |
126 | 126 | |
127 | - $propFind->handle(self::PROPERTY_NAME_COUNT, function () use ($node): int { |
|
128 | - return $this->cachedCount[$node->getId()] ?? $this->commentsManager->getNumberOfCommentsForObject('files', (string)$node->getId()); |
|
127 | + $propFind->handle(self::PROPERTY_NAME_COUNT, function() use ($node): int { |
|
128 | + return $this->cachedCount[$node->getId()] ?? $this->commentsManager->getNumberOfCommentsForObject('files', (string) $node->getId()); |
|
129 | 129 | }); |
130 | 130 | |
131 | - $propFind->handle(self::PROPERTY_NAME_HREF, function () use ($node): ?string { |
|
131 | + $propFind->handle(self::PROPERTY_NAME_HREF, function() use ($node): ?string { |
|
132 | 132 | return $this->getCommentsLink($node); |
133 | 133 | }); |
134 | 134 | |
135 | - $propFind->handle(self::PROPERTY_NAME_UNREAD, function () use ($node): ?int { |
|
135 | + $propFind->handle(self::PROPERTY_NAME_UNREAD, function() use ($node): ?int { |
|
136 | 136 | return $this->cachedUnreadCount[$node->getId()] ?? $this->getUnreadCount($node); |
137 | 137 | }); |
138 | 138 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | // in case we end up somewhere else, unexpectedly. |
148 | 148 | return null; |
149 | 149 | } |
150 | - $commentsPart = 'dav/comments/files/' . rawurldecode((string)$node->getId()); |
|
150 | + $commentsPart = 'dav/comments/files/'.rawurldecode((string) $node->getId()); |
|
151 | 151 | return substr_replace($href, $commentsPart, $entryPoint + strlen('/remote.php/')); |
152 | 152 | } |
153 | 153 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | return null; |
162 | 162 | } |
163 | 163 | |
164 | - $objectId = (string)$node->getId(); |
|
164 | + $objectId = (string) $node->getId(); |
|
165 | 165 | return $this->commentsManager->getNumberOfUnreadCommentsForObjects('files', [$objectId], $user)[$objectId]; |
166 | 166 | } |
167 | 167 | } |
@@ -19,99 +19,99 @@ |
||
19 | 19 | use Sabre\DAV\Server; |
20 | 20 | |
21 | 21 | class CommentsPropertiesPluginTest extends \Test\TestCase { |
22 | - protected CommentPropertiesPluginImplementation $plugin; |
|
23 | - protected ICommentsManager&MockObject $commentsManager; |
|
24 | - protected IUserSession&MockObject $userSession; |
|
25 | - protected Server&MockObject $server; |
|
26 | - |
|
27 | - protected function setUp(): void { |
|
28 | - parent::setUp(); |
|
29 | - |
|
30 | - $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
31 | - $this->userSession = $this->createMock(IUserSession::class); |
|
32 | - $this->server = $this->createMock(Server::class); |
|
33 | - |
|
34 | - $this->plugin = new CommentPropertiesPluginImplementation($this->commentsManager, $this->userSession); |
|
35 | - $this->plugin->initialize($this->server); |
|
36 | - } |
|
37 | - |
|
38 | - public static function nodeProvider(): array { |
|
39 | - return [ |
|
40 | - [File::class, true], |
|
41 | - [Directory::class, true], |
|
42 | - [\Sabre\DAV\INode::class, false] |
|
43 | - ]; |
|
44 | - } |
|
45 | - |
|
46 | - #[\PHPUnit\Framework\Attributes\DataProvider('nodeProvider')] |
|
47 | - public function testHandleGetProperties(string $class, bool $expectedSuccessful): void { |
|
48 | - $propFind = $this->createMock(PropFind::class); |
|
49 | - |
|
50 | - if ($expectedSuccessful) { |
|
51 | - $propFind->expects($this->exactly(3)) |
|
52 | - ->method('handle'); |
|
53 | - } else { |
|
54 | - $propFind->expects($this->never()) |
|
55 | - ->method('handle'); |
|
56 | - } |
|
57 | - |
|
58 | - $node = $this->createMock($class); |
|
59 | - $this->plugin->handleGetProperties($propFind, $node); |
|
60 | - } |
|
61 | - |
|
62 | - public static function baseUriProvider(): array { |
|
63 | - return [ |
|
64 | - ['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
65 | - ['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
66 | - ['owncloud/wicked.php/files/', '4567', null] |
|
67 | - ]; |
|
68 | - } |
|
69 | - |
|
70 | - #[\PHPUnit\Framework\Attributes\DataProvider('baseUriProvider')] |
|
71 | - public function testGetCommentsLink(string $baseUri, string $fid, ?string $expectedHref): void { |
|
72 | - $node = $this->createMock(File::class); |
|
73 | - $node->expects($this->any()) |
|
74 | - ->method('getId') |
|
75 | - ->willReturn($fid); |
|
76 | - |
|
77 | - $this->server->expects($this->once()) |
|
78 | - ->method('getBaseUri') |
|
79 | - ->willReturn($baseUri); |
|
80 | - |
|
81 | - $href = $this->plugin->getCommentsLink($node); |
|
82 | - $this->assertSame($expectedHref, $href); |
|
83 | - } |
|
84 | - |
|
85 | - public static function userProvider(): array { |
|
86 | - return [ |
|
87 | - [IUser::class], |
|
88 | - [null] |
|
89 | - ]; |
|
90 | - } |
|
91 | - |
|
92 | - #[\PHPUnit\Framework\Attributes\DataProvider('userProvider')] |
|
93 | - public function testGetUnreadCount(?string $user): void { |
|
94 | - $node = $this->createMock(File::class); |
|
95 | - $node->expects($this->any()) |
|
96 | - ->method('getId') |
|
97 | - ->willReturn('4567'); |
|
98 | - |
|
99 | - if ($user !== null) { |
|
100 | - $user = $this->createMock($user); |
|
101 | - } |
|
102 | - $this->userSession->expects($this->once()) |
|
103 | - ->method('getUser') |
|
104 | - ->willReturn($user); |
|
105 | - |
|
106 | - $this->commentsManager->expects($this->any()) |
|
107 | - ->method('getNumberOfUnreadCommentsForObjects') |
|
108 | - ->willReturn(['4567' => 42]); |
|
109 | - |
|
110 | - $unread = $this->plugin->getUnreadCount($node); |
|
111 | - if (is_null($user)) { |
|
112 | - $this->assertNull($unread); |
|
113 | - } else { |
|
114 | - $this->assertSame($unread, 42); |
|
115 | - } |
|
116 | - } |
|
22 | + protected CommentPropertiesPluginImplementation $plugin; |
|
23 | + protected ICommentsManager&MockObject $commentsManager; |
|
24 | + protected IUserSession&MockObject $userSession; |
|
25 | + protected Server&MockObject $server; |
|
26 | + |
|
27 | + protected function setUp(): void { |
|
28 | + parent::setUp(); |
|
29 | + |
|
30 | + $this->commentsManager = $this->createMock(ICommentsManager::class); |
|
31 | + $this->userSession = $this->createMock(IUserSession::class); |
|
32 | + $this->server = $this->createMock(Server::class); |
|
33 | + |
|
34 | + $this->plugin = new CommentPropertiesPluginImplementation($this->commentsManager, $this->userSession); |
|
35 | + $this->plugin->initialize($this->server); |
|
36 | + } |
|
37 | + |
|
38 | + public static function nodeProvider(): array { |
|
39 | + return [ |
|
40 | + [File::class, true], |
|
41 | + [Directory::class, true], |
|
42 | + [\Sabre\DAV\INode::class, false] |
|
43 | + ]; |
|
44 | + } |
|
45 | + |
|
46 | + #[\PHPUnit\Framework\Attributes\DataProvider('nodeProvider')] |
|
47 | + public function testHandleGetProperties(string $class, bool $expectedSuccessful): void { |
|
48 | + $propFind = $this->createMock(PropFind::class); |
|
49 | + |
|
50 | + if ($expectedSuccessful) { |
|
51 | + $propFind->expects($this->exactly(3)) |
|
52 | + ->method('handle'); |
|
53 | + } else { |
|
54 | + $propFind->expects($this->never()) |
|
55 | + ->method('handle'); |
|
56 | + } |
|
57 | + |
|
58 | + $node = $this->createMock($class); |
|
59 | + $this->plugin->handleGetProperties($propFind, $node); |
|
60 | + } |
|
61 | + |
|
62 | + public static function baseUriProvider(): array { |
|
63 | + return [ |
|
64 | + ['owncloud/remote.php/webdav/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
65 | + ['owncloud/remote.php/files/', '4567', 'owncloud/remote.php/dav/comments/files/4567'], |
|
66 | + ['owncloud/wicked.php/files/', '4567', null] |
|
67 | + ]; |
|
68 | + } |
|
69 | + |
|
70 | + #[\PHPUnit\Framework\Attributes\DataProvider('baseUriProvider')] |
|
71 | + public function testGetCommentsLink(string $baseUri, string $fid, ?string $expectedHref): void { |
|
72 | + $node = $this->createMock(File::class); |
|
73 | + $node->expects($this->any()) |
|
74 | + ->method('getId') |
|
75 | + ->willReturn($fid); |
|
76 | + |
|
77 | + $this->server->expects($this->once()) |
|
78 | + ->method('getBaseUri') |
|
79 | + ->willReturn($baseUri); |
|
80 | + |
|
81 | + $href = $this->plugin->getCommentsLink($node); |
|
82 | + $this->assertSame($expectedHref, $href); |
|
83 | + } |
|
84 | + |
|
85 | + public static function userProvider(): array { |
|
86 | + return [ |
|
87 | + [IUser::class], |
|
88 | + [null] |
|
89 | + ]; |
|
90 | + } |
|
91 | + |
|
92 | + #[\PHPUnit\Framework\Attributes\DataProvider('userProvider')] |
|
93 | + public function testGetUnreadCount(?string $user): void { |
|
94 | + $node = $this->createMock(File::class); |
|
95 | + $node->expects($this->any()) |
|
96 | + ->method('getId') |
|
97 | + ->willReturn('4567'); |
|
98 | + |
|
99 | + if ($user !== null) { |
|
100 | + $user = $this->createMock($user); |
|
101 | + } |
|
102 | + $this->userSession->expects($this->once()) |
|
103 | + ->method('getUser') |
|
104 | + ->willReturn($user); |
|
105 | + |
|
106 | + $this->commentsManager->expects($this->any()) |
|
107 | + ->method('getNumberOfUnreadCommentsForObjects') |
|
108 | + ->willReturn(['4567' => 42]); |
|
109 | + |
|
110 | + $unread = $this->plugin->getUnreadCount($node); |
|
111 | + if (is_null($user)) { |
|
112 | + $this->assertNull($unread); |
|
113 | + } else { |
|
114 | + $this->assertSame($unread, 42); |
|
115 | + } |
|
116 | + } |
|
117 | 117 | } |
@@ -16,144 +16,144 @@ |
||
16 | 16 | * Class FakeManager |
17 | 17 | */ |
18 | 18 | class FakeManager implements ICommentsManager { |
19 | - public function get($id) { |
|
20 | - } |
|
21 | - |
|
22 | - public function getTree($id, $limit = 0, $offset = 0) { |
|
23 | - } |
|
24 | - |
|
25 | - public function getForObject( |
|
26 | - $objectType, |
|
27 | - $objectId, |
|
28 | - $limit = 0, |
|
29 | - $offset = 0, |
|
30 | - ?\DateTime $notOlderThan = null, |
|
31 | - ) { |
|
32 | - } |
|
19 | + public function get($id) { |
|
20 | + } |
|
21 | + |
|
22 | + public function getTree($id, $limit = 0, $offset = 0) { |
|
23 | + } |
|
24 | + |
|
25 | + public function getForObject( |
|
26 | + $objectType, |
|
27 | + $objectId, |
|
28 | + $limit = 0, |
|
29 | + $offset = 0, |
|
30 | + ?\DateTime $notOlderThan = null, |
|
31 | + ) { |
|
32 | + } |
|
33 | 33 | |
34 | - public function getForObjectSince( |
|
35 | - string $objectType, |
|
36 | - string $objectId, |
|
37 | - int $lastKnownCommentId, |
|
38 | - string $sortDirection = 'asc', |
|
39 | - int $limit = 30, |
|
40 | - bool $includeLastKnown = false, |
|
41 | - string $topmostParentId = '', |
|
42 | - ): array { |
|
43 | - return []; |
|
44 | - } |
|
34 | + public function getForObjectSince( |
|
35 | + string $objectType, |
|
36 | + string $objectId, |
|
37 | + int $lastKnownCommentId, |
|
38 | + string $sortDirection = 'asc', |
|
39 | + int $limit = 30, |
|
40 | + bool $includeLastKnown = false, |
|
41 | + string $topmostParentId = '', |
|
42 | + ): array { |
|
43 | + return []; |
|
44 | + } |
|
45 | 45 | |
46 | - public function getCommentsWithVerbForObjectSinceComment( |
|
47 | - string $objectType, |
|
48 | - string $objectId, |
|
49 | - array $verbs, |
|
50 | - int $lastKnownCommentId, |
|
51 | - string $sortDirection = 'asc', |
|
52 | - int $limit = 30, |
|
53 | - bool $includeLastKnown = false, |
|
54 | - string $topmostParentId = '', |
|
55 | - ): array { |
|
56 | - return []; |
|
57 | - } |
|
58 | - |
|
59 | - public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = '') { |
|
60 | - } |
|
61 | - |
|
62 | - public function getNumberOfCommentsForObjects(string $objectType, array $objectIds, ?\DateTime $notOlderThan = null, string $verb = '') :array { |
|
63 | - return array_fill_keys($objectIds, 0); |
|
64 | - } |
|
65 | - |
|
66 | - public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array { |
|
67 | - return []; |
|
68 | - } |
|
69 | - |
|
70 | - public function create($actorType, $actorId, $objectType, $objectId) { |
|
71 | - } |
|
72 | - |
|
73 | - public function delete($id) { |
|
74 | - } |
|
75 | - |
|
76 | - public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment { |
|
77 | - return new Comment(); |
|
78 | - } |
|
79 | - |
|
80 | - public function retrieveAllReactions(int $parentId): array { |
|
81 | - return []; |
|
82 | - } |
|
83 | - |
|
84 | - public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array { |
|
85 | - return []; |
|
86 | - } |
|
87 | - |
|
88 | - public function supportReactions(): bool { |
|
89 | - return false; |
|
90 | - } |
|
91 | - |
|
92 | - public function save(IComment $comment) { |
|
93 | - } |
|
94 | - |
|
95 | - public function deleteReferencesOfActor($actorType, $actorId) { |
|
96 | - } |
|
97 | - |
|
98 | - public function deleteCommentsAtObject($objectType, $objectId) { |
|
99 | - } |
|
100 | - |
|
101 | - public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
102 | - } |
|
103 | - |
|
104 | - public function getReadMark($objectType, $objectId, IUser $user) { |
|
105 | - } |
|
106 | - |
|
107 | - public function deleteReadMarksFromUser(IUser $user) { |
|
108 | - } |
|
109 | - |
|
110 | - public function deleteReadMarksOnObject($objectType, $objectId) { |
|
111 | - } |
|
112 | - |
|
113 | - public function registerEventHandler(\Closure $closure) { |
|
114 | - } |
|
115 | - |
|
116 | - public function registerDisplayNameResolver($type, \Closure $closure) { |
|
117 | - } |
|
118 | - |
|
119 | - public function resolveDisplayName($type, $id) { |
|
120 | - } |
|
46 | + public function getCommentsWithVerbForObjectSinceComment( |
|
47 | + string $objectType, |
|
48 | + string $objectId, |
|
49 | + array $verbs, |
|
50 | + int $lastKnownCommentId, |
|
51 | + string $sortDirection = 'asc', |
|
52 | + int $limit = 30, |
|
53 | + bool $includeLastKnown = false, |
|
54 | + string $topmostParentId = '', |
|
55 | + ): array { |
|
56 | + return []; |
|
57 | + } |
|
58 | + |
|
59 | + public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = '') { |
|
60 | + } |
|
61 | + |
|
62 | + public function getNumberOfCommentsForObjects(string $objectType, array $objectIds, ?\DateTime $notOlderThan = null, string $verb = '') :array { |
|
63 | + return array_fill_keys($objectIds, 0); |
|
64 | + } |
|
65 | + |
|
66 | + public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array { |
|
67 | + return []; |
|
68 | + } |
|
69 | + |
|
70 | + public function create($actorType, $actorId, $objectType, $objectId) { |
|
71 | + } |
|
72 | + |
|
73 | + public function delete($id) { |
|
74 | + } |
|
75 | + |
|
76 | + public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment { |
|
77 | + return new Comment(); |
|
78 | + } |
|
79 | + |
|
80 | + public function retrieveAllReactions(int $parentId): array { |
|
81 | + return []; |
|
82 | + } |
|
83 | + |
|
84 | + public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array { |
|
85 | + return []; |
|
86 | + } |
|
87 | + |
|
88 | + public function supportReactions(): bool { |
|
89 | + return false; |
|
90 | + } |
|
91 | + |
|
92 | + public function save(IComment $comment) { |
|
93 | + } |
|
94 | + |
|
95 | + public function deleteReferencesOfActor($actorType, $actorId) { |
|
96 | + } |
|
97 | + |
|
98 | + public function deleteCommentsAtObject($objectType, $objectId) { |
|
99 | + } |
|
100 | + |
|
101 | + public function setReadMark($objectType, $objectId, \DateTime $dateTime, IUser $user) { |
|
102 | + } |
|
103 | + |
|
104 | + public function getReadMark($objectType, $objectId, IUser $user) { |
|
105 | + } |
|
106 | + |
|
107 | + public function deleteReadMarksFromUser(IUser $user) { |
|
108 | + } |
|
109 | + |
|
110 | + public function deleteReadMarksOnObject($objectType, $objectId) { |
|
111 | + } |
|
112 | + |
|
113 | + public function registerEventHandler(\Closure $closure) { |
|
114 | + } |
|
115 | + |
|
116 | + public function registerDisplayNameResolver($type, \Closure $closure) { |
|
117 | + } |
|
118 | + |
|
119 | + public function resolveDisplayName($type, $id) { |
|
120 | + } |
|
121 | 121 | |
122 | - public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
123 | - } |
|
122 | + public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user) { |
|
123 | + } |
|
124 | 124 | |
125 | - public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array { |
|
126 | - return []; |
|
127 | - } |
|
125 | + public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array { |
|
126 | + return []; |
|
127 | + } |
|
128 | 128 | |
129 | 129 | |
130 | - public function getActorsInTree($id) { |
|
131 | - } |
|
130 | + public function getActorsInTree($id) { |
|
131 | + } |
|
132 | 132 | |
133 | - public function load(): void { |
|
134 | - } |
|
133 | + public function load(): void { |
|
134 | + } |
|
135 | 135 | |
136 | - public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array { |
|
137 | - return []; |
|
138 | - } |
|
136 | + public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array { |
|
137 | + return []; |
|
138 | + } |
|
139 | 139 | |
140 | - public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int { |
|
141 | - return 0; |
|
142 | - } |
|
140 | + public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int { |
|
141 | + return 0; |
|
142 | + } |
|
143 | 143 | |
144 | - public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int { |
|
145 | - return 0; |
|
146 | - } |
|
144 | + public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int { |
|
145 | + return 0; |
|
146 | + } |
|
147 | 147 | |
148 | - public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int { |
|
149 | - return 0; |
|
150 | - } |
|
148 | + public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int { |
|
149 | + return 0; |
|
150 | + } |
|
151 | 151 | |
152 | - public function getLastCommentDateByActor(string $objectType, string $objectId, string $verb, string $actorType, array $actors): array { |
|
153 | - return []; |
|
154 | - } |
|
152 | + public function getLastCommentDateByActor(string $objectType, string $objectId, string $verb, string $actorType, array $actors): array { |
|
153 | + return []; |
|
154 | + } |
|
155 | 155 | |
156 | - public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool { |
|
157 | - return true; |
|
158 | - } |
|
156 | + public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool { |
|
157 | + return true; |
|
158 | + } |
|
159 | 159 | } |