ICommentsManager.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. * @author Joas Schilling <coding@schilljs.com>
  8. * @author John Molakvoæ <skjnldsv@protonmail.com>
  9. * @author Lukas Reschke <lukas@statuscode.ch>
  10. * @author Robin Appelman <robin@icewind.nl>
  11. * @author Roeland Jago Douma <roeland@famdouma.nl>
  12. * @author Thomas Müller <thomas.mueller@tmit.eu>
  13. *
  14. * @license AGPL-3.0
  15. *
  16. * This code is free software: you can redistribute it and/or modify
  17. * it under the terms of the GNU Affero General Public License, version 3,
  18. * as published by the Free Software Foundation.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU Affero General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU Affero General Public License, version 3,
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>
  27. *
  28. */
  29. namespace OCP\Comments;
  30. use OCP\IUser;
  31. use OCP\PreConditionNotMetException;
  32. /**
  33. * Interface ICommentsManager
  34. *
  35. * This class manages the access to comments
  36. *
  37. * @since 9.0.0
  38. */
  39. interface ICommentsManager {
  40. /**
  41. * @const DELETED_USER type and id for a user that has been deleted
  42. * @see deleteReferencesOfActor
  43. * @since 9.0.0
  44. *
  45. * To be used as replacement for user type actors in deleteReferencesOfActor().
  46. *
  47. * User interfaces shall show "Deleted user" as display name, if needed.
  48. */
  49. public const DELETED_USER = 'deleted_users';
  50. /**
  51. * returns a comment instance
  52. *
  53. * @param string $id the ID of the comment
  54. * @return IComment
  55. * @throws NotFoundException
  56. * @since 9.0.0
  57. */
  58. public function get($id);
  59. /**
  60. * Returns the comment specified by the id and all it's child comments
  61. *
  62. * @param string $id
  63. * @param int $limit max number of entries to return, 0 returns all
  64. * @param int $offset the start entry
  65. * @return array{comment: IComment, replies: list<array{comment: IComment, replies: array<empty, empty>}>}
  66. * @since 9.0.0
  67. *
  68. * The return array looks like this
  69. * [
  70. * 'comment' => IComment, // root comment
  71. * 'replies' =>
  72. * [
  73. * 0 =>
  74. * [
  75. * 'comment' => IComment,
  76. * 'replies' =>
  77. * [
  78. * 0 =>
  79. * [
  80. * 'comment' => IComment,
  81. * 'replies' => [ … ]
  82. * ],
  83. * …
  84. * ]
  85. * ]
  86. * 1 =>
  87. * [
  88. * 'comment' => IComment,
  89. * 'replies'=> [ … ]
  90. * ],
  91. * …
  92. * ]
  93. * ]
  94. */
  95. public function getTree($id, $limit = 0, $offset = 0);
  96. /**
  97. * returns comments for a specific object (e.g. a file).
  98. *
  99. * The sort order is always newest to oldest.
  100. *
  101. * @param string $objectType the object type, e.g. 'files'
  102. * @param string $objectId the id of the object
  103. * @param int $limit optional, number of maximum comments to be returned. if
  104. * not specified, all comments are returned.
  105. * @param int $offset optional, starting point
  106. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  107. * that may be returned
  108. * @return list<IComment>
  109. * @since 9.0.0
  110. */
  111. public function getForObject(
  112. $objectType,
  113. $objectId,
  114. $limit = 0,
  115. $offset = 0,
  116. ?\DateTime $notOlderThan = null
  117. );
  118. /**
  119. * @param string $objectType the object type, e.g. 'files'
  120. * @param string $objectId the id of the object
  121. * @param int $lastKnownCommentId the last known comment (will be used as offset)
  122. * @param string $sortDirection direction of the comments (`asc` or `desc`)
  123. * @param int $limit optional, number of maximum comments to be returned. if
  124. * set to 0, all comments are returned.
  125. * @param bool $includeLastKnown
  126. * @return list<IComment>
  127. * @since 14.0.0
  128. * @deprecated 24.0.0 - Use getCommentsWithVerbForObjectSinceComment instead
  129. */
  130. public function getForObjectSince(
  131. string $objectType,
  132. string $objectId,
  133. int $lastKnownCommentId,
  134. string $sortDirection = 'asc',
  135. int $limit = 30,
  136. bool $includeLastKnown = false
  137. ): array;
  138. /**
  139. * @param string $objectType the object type, e.g. 'files'
  140. * @param string $objectId the id of the object
  141. * @param string[] $verbs List of verbs to filter by
  142. * @param int $lastKnownCommentId the last known comment (will be used as offset)
  143. * @param string $sortDirection direction of the comments (`asc` or `desc`)
  144. * @param int $limit optional, number of maximum comments to be returned. if
  145. * set to 0, all comments are returned.
  146. * @param bool $includeLastKnown
  147. * @return list<IComment>
  148. * @since 24.0.0
  149. */
  150. public function getCommentsWithVerbForObjectSinceComment(
  151. string $objectType,
  152. string $objectId,
  153. array $verbs,
  154. int $lastKnownCommentId,
  155. string $sortDirection = 'asc',
  156. int $limit = 30,
  157. bool $includeLastKnown = false
  158. ): array;
  159. /**
  160. * Search for comments with a given content
  161. *
  162. * @param string $search content to search for
  163. * @param string $objectType Limit the search by object type
  164. * @param string $objectId Limit the search by object id
  165. * @param string $verb Limit the verb of the comment
  166. * @param int $offset
  167. * @param int $limit
  168. * @return list<IComment>
  169. * @since 14.0.0
  170. */
  171. public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array;
  172. /**
  173. * Search for comments on one or more objects with a given content
  174. *
  175. * @param string $search content to search for
  176. * @param string $objectType Limit the search by object type
  177. * @param array $objectIds Limit the search by object ids
  178. * @param string $verb Limit the verb of the comment
  179. * @param int $offset
  180. * @param int $limit
  181. * @return IComment[]
  182. * @since 21.0.0
  183. */
  184. public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array;
  185. /**
  186. * @param $objectType string the object type, e.g. 'files'
  187. * @param $objectId string the id of the object
  188. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  189. * that may be returned
  190. * @param string $verb Limit the verb of the comment - Added in 14.0.0
  191. * @return Int
  192. * @since 9.0.0
  193. */
  194. public function getNumberOfCommentsForObject($objectType, $objectId, ?\DateTime $notOlderThan = null, $verb = '');
  195. /**
  196. * @param string $objectType the object type, e.g. 'files'
  197. * @param string[] $objectIds the id of the object
  198. * @param IUser $user
  199. * @param string $verb Limit the verb of the comment - Added in 14.0.0
  200. * @return array Map with object id => # of unread comments
  201. * @psalm-return array<string, int>
  202. * @since 21.0.0
  203. */
  204. public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array;
  205. /**
  206. * @param string $objectType
  207. * @param string $objectId
  208. * @param int $lastRead
  209. * @param string $verb
  210. * @return int
  211. * @since 21.0.0
  212. * @deprecated 24.0.0 - Use getNumberOfCommentsWithVerbsForObjectSinceComment instead
  213. */
  214. public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int;
  215. /**
  216. * @param string $objectType
  217. * @param string $objectId
  218. * @param int $lastRead
  219. * @param string[] $verbs
  220. * @return int
  221. * @since 24.0.0
  222. */
  223. public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int;
  224. /**
  225. * @param string $objectType
  226. * @param string $objectId
  227. * @param \DateTime $beforeDate
  228. * @param string $verb
  229. * @return int
  230. * @since 21.0.0
  231. */
  232. public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int;
  233. /**
  234. * @param string $objectType
  235. * @param string $objectId
  236. * @param string $verb
  237. * @param string $actorType
  238. * @param string[] $actors
  239. * @return \DateTime[] Map of "string actor" => "\DateTime most recent comment date"
  240. * @psalm-return array<string, \DateTime>
  241. * @since 21.0.0
  242. */
  243. public function getLastCommentDateByActor(
  244. string $objectType,
  245. string $objectId,
  246. string $verb,
  247. string $actorType,
  248. array $actors
  249. ): array;
  250. /**
  251. * Get the number of unread comments for all files in a folder
  252. *
  253. * @param int $folderId
  254. * @param IUser $user
  255. * @return array [$fileId => $unreadCount]
  256. * @since 12.0.0
  257. * @deprecated 29.0.0 use getNumberOfUnreadCommentsForObjects instead
  258. */
  259. public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user);
  260. /**
  261. * creates a new comment and returns it. At this point of time, it is not
  262. * saved in the used data storage. Use save() after setting other fields
  263. * of the comment (e.g. message or verb).
  264. *
  265. * @param string $actorType the actor type (e.g. 'users')
  266. * @param string $actorId a user id
  267. * @param string $objectType the object type the comment is attached to
  268. * @param string $objectId the object id the comment is attached to
  269. * @return IComment
  270. * @since 9.0.0
  271. */
  272. public function create($actorType, $actorId, $objectType, $objectId);
  273. /**
  274. * permanently deletes the comment specified by the ID
  275. *
  276. * When the comment has child comments, their parent ID will be changed to
  277. * the parent ID of the item that is to be deleted.
  278. *
  279. * @param string $id
  280. * @return bool
  281. * @since 9.0.0
  282. */
  283. public function delete($id);
  284. /**
  285. * Get comment related with user reaction
  286. *
  287. * Throws PreConditionNotMetException when the system haven't the minimum requirements to
  288. * use reactions
  289. *
  290. * @param int $parentId
  291. * @param string $actorType
  292. * @param string $actorId
  293. * @param string $reaction
  294. * @return IComment
  295. * @throws NotFoundException
  296. * @throws PreConditionNotMetException
  297. * @since 24.0.0
  298. */
  299. public function getReactionComment(int $parentId, string $actorType, string $actorId, string $reaction): IComment;
  300. /**
  301. * Retrieve all reactions of a message
  302. *
  303. * Throws PreConditionNotMetException when the system haven't the minimum requirements to
  304. * use reactions
  305. *
  306. * @param int $parentId
  307. * @return IComment[]
  308. * @throws PreConditionNotMetException
  309. * @since 24.0.0
  310. */
  311. public function retrieveAllReactions(int $parentId): array;
  312. /**
  313. * Retrieve all reactions with specific reaction of a message
  314. *
  315. * Throws PreConditionNotMetException when the system haven't the minimum requirements to
  316. * use reactions
  317. *
  318. * @param int $parentId
  319. * @param string $reaction
  320. * @return IComment[]
  321. * @throws PreConditionNotMetException
  322. * @since 24.0.0
  323. */
  324. public function retrieveAllReactionsWithSpecificReaction(int $parentId, string $reaction): array;
  325. /**
  326. * Support reactions
  327. *
  328. * @return bool
  329. * @since 24.0.0
  330. */
  331. public function supportReactions(): bool;
  332. /**
  333. * saves the comment permanently
  334. *
  335. * if the supplied comment has an empty ID, a new entry comment will be
  336. * saved and the instance updated with the new ID.
  337. *
  338. * Otherwise, an existing comment will be updated.
  339. *
  340. * Throws NotFoundException when a comment that is to be updated does not
  341. * exist anymore at this point of time.
  342. *
  343. * @param IComment $comment
  344. * @return bool
  345. * @throws NotFoundException
  346. * @since 9.0.0
  347. */
  348. public function save(IComment $comment);
  349. /**
  350. * removes references to specific actor (e.g. on user delete) of a comment.
  351. * The comment itself must not get lost/deleted.
  352. *
  353. * A 'users' type actor (type and id) should get replaced by the
  354. * value of the DELETED_USER constant of this interface.
  355. *
  356. * @param string $actorType the actor type (e.g. 'users')
  357. * @param string $actorId a user id
  358. * @return boolean
  359. * @since 9.0.0
  360. */
  361. public function deleteReferencesOfActor($actorType, $actorId);
  362. /**
  363. * deletes all comments made of a specific object (e.g. on file delete)
  364. *
  365. * @param string $objectType the object type (e.g. 'files')
  366. * @param string $objectId e.g. the file id
  367. * @return boolean
  368. * @since 9.0.0
  369. */
  370. public function deleteCommentsAtObject($objectType, $objectId);
  371. /**
  372. * sets the read marker for a given file to the specified date for the
  373. * provided user
  374. *
  375. * @param string $objectType
  376. * @param string $objectId
  377. * @param \DateTime $dateTime
  378. * @param \OCP\IUser $user
  379. * @since 9.0.0
  380. */
  381. public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user);
  382. /**
  383. * returns the read marker for a given file to the specified date for the
  384. * provided user. It returns null, when the marker is not present, i.e.
  385. * no comments were marked as read.
  386. *
  387. * @param string $objectType
  388. * @param string $objectId
  389. * @param \OCP\IUser $user
  390. * @return \DateTime|null
  391. * @since 9.0.0
  392. */
  393. public function getReadMark($objectType, $objectId, \OCP\IUser $user);
  394. /**
  395. * deletes the read markers for the specified user
  396. *
  397. * @param \OCP\IUser $user
  398. * @return bool
  399. * @since 9.0.0
  400. */
  401. public function deleteReadMarksFromUser(\OCP\IUser $user);
  402. /**
  403. * deletes the read markers on the specified object
  404. *
  405. * @param string $objectType
  406. * @param string $objectId
  407. * @return bool
  408. * @since 9.0.0
  409. */
  410. public function deleteReadMarksOnObject($objectType, $objectId);
  411. /**
  412. * registers an Entity to the manager, so event notifications can be send
  413. * to consumers of the comments infrastructure
  414. *
  415. * @param \Closure $closure
  416. * @since 11.0.0
  417. */
  418. public function registerEventHandler(\Closure $closure);
  419. /**
  420. * registers a method that resolves an ID to a display name for a given type
  421. *
  422. * @param string $type
  423. * @param \Closure $closure
  424. * @throws \OutOfBoundsException
  425. * @since 11.0.0
  426. *
  427. * Only one resolver shall be registered per type. Otherwise a
  428. * \OutOfBoundsException has to thrown.
  429. */
  430. public function registerDisplayNameResolver($type, \Closure $closure);
  431. /**
  432. * resolves a given ID of a given Type to a display name.
  433. *
  434. * @param string $type
  435. * @param string $id
  436. * @return string
  437. * @throws \OutOfBoundsException
  438. * @since 11.0.0
  439. *
  440. * If a provided type was not registered, an \OutOfBoundsException shall
  441. * be thrown. It is upon the resolver discretion what to return of the
  442. * provided ID is unknown. It must be ensured that a string is returned.
  443. */
  444. public function resolveDisplayName($type, $id);
  445. /**
  446. * Load the Comments app into the page
  447. *
  448. * @since 21.0.0
  449. */
  450. public function load(): void;
  451. /**
  452. * Delete comments with field expire_date less than current date
  453. * Only will delete the message related with the object.
  454. *
  455. * @param string $objectType the object type (e.g. 'files')
  456. * @param string $objectId e.g. the file id, leave empty to expire on all objects of this type
  457. * @return boolean true if at least one row was deleted
  458. * @since 25.0.0
  459. */
  460. public function deleteCommentsExpiredAtObject(string $objectType, string $objectId = ''): bool;
  461. }