You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ICommentsManager.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. /**
  32. * Interface ICommentsManager
  33. *
  34. * This class manages the access to comments
  35. *
  36. * @since 9.0.0
  37. */
  38. interface ICommentsManager {
  39. /**
  40. * @const DELETED_USER type and id for a user that has been deleted
  41. * @see deleteReferencesOfActor
  42. * @since 9.0.0
  43. *
  44. * To be used as replacement for user type actors in deleteReferencesOfActor().
  45. *
  46. * User interfaces shall show "Deleted user" as display name, if needed.
  47. */
  48. public const DELETED_USER = 'deleted_users';
  49. /**
  50. * returns a comment instance
  51. *
  52. * @param string $id the ID of the comment
  53. * @return IComment
  54. * @throws NotFoundException
  55. * @since 9.0.0
  56. */
  57. public function get($id);
  58. /**
  59. * returns the comment specified by the id and all it's child comments
  60. *
  61. * @param string $id
  62. * @param int $limit max number of entries to return, 0 returns all
  63. * @param int $offset the start entry
  64. * @return array
  65. * @since 9.0.0
  66. *
  67. * The return array looks like this
  68. * [
  69. * 'comment' => IComment, // root comment
  70. * 'replies' =>
  71. * [
  72. * 0 =>
  73. * [
  74. * 'comment' => IComment,
  75. * 'replies' =>
  76. * [
  77. * 0 =>
  78. * [
  79. * 'comment' => IComment,
  80. * 'replies' => [ … ]
  81. * ],
  82. * …
  83. * ]
  84. * ]
  85. * 1 =>
  86. * [
  87. * 'comment' => IComment,
  88. * 'replies'=> [ … ]
  89. * ],
  90. * …
  91. * ]
  92. * ]
  93. */
  94. public function getTree($id, $limit = 0, $offset = 0);
  95. /**
  96. * returns comments for a specific object (e.g. a file).
  97. *
  98. * The sort order is always newest to oldest.
  99. *
  100. * @param string $objectType the object type, e.g. 'files'
  101. * @param string $objectId the id of the object
  102. * @param int $limit optional, number of maximum comments to be returned. if
  103. * not specified, all comments are returned.
  104. * @param int $offset optional, starting point
  105. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  106. * that may be returned
  107. * @return IComment[]
  108. * @since 9.0.0
  109. */
  110. public function getForObject(
  111. $objectType,
  112. $objectId,
  113. $limit = 0,
  114. $offset = 0,
  115. \DateTime $notOlderThan = null
  116. );
  117. /**
  118. * @param string $objectType the object type, e.g. 'files'
  119. * @param string $objectId the id of the object
  120. * @param int $lastKnownCommentId the last known comment (will be used as offset)
  121. * @param string $sortDirection direction of the comments (`asc` or `desc`)
  122. * @param int $limit optional, number of maximum comments to be returned. if
  123. * set to 0, all comments are returned.
  124. * @param bool $includeLastKnown
  125. * @return IComment[]
  126. * @since 14.0.0
  127. */
  128. public function getForObjectSince(
  129. string $objectType,
  130. string $objectId,
  131. int $lastKnownCommentId,
  132. string $sortDirection = 'asc',
  133. int $limit = 30,
  134. bool $includeLastKnown = false
  135. ): array;
  136. /**
  137. * Search for comments with a given content
  138. *
  139. * @param string $search content to search for
  140. * @param string $objectType Limit the search by object type
  141. * @param string $objectId Limit the search by object id
  142. * @param string $verb Limit the verb of the comment
  143. * @param int $offset
  144. * @param int $limit
  145. * @return IComment[]
  146. * @since 14.0.0
  147. */
  148. public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array;
  149. /**
  150. * Search for comments on one or more objects with a given content
  151. *
  152. * @param string $search content to search for
  153. * @param string $objectType Limit the search by object type
  154. * @param array $objectIds Limit the search by object ids
  155. * @param string $verb Limit the verb of the comment
  156. * @param int $offset
  157. * @param int $limit
  158. * @return IComment[]
  159. * @since 21.0.0
  160. */
  161. public function searchForObjects(string $search, string $objectType, array $objectIds, string $verb, int $offset, int $limit = 50): array;
  162. /**
  163. * @param $objectType string the object type, e.g. 'files'
  164. * @param $objectId string the id of the object
  165. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  166. * that may be returned
  167. * @param string $verb Limit the verb of the comment - Added in 14.0.0
  168. * @return Int
  169. * @since 9.0.0
  170. */
  171. public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '');
  172. /**
  173. * @param string $objectType the object type, e.g. 'files'
  174. * @param string[] $objectIds the id of the object
  175. * @param IUser $user
  176. * @param string $verb Limit the verb of the comment - Added in 14.0.0
  177. * @return array Map with object id => # of unread comments
  178. * @psalm-return array<string, int>
  179. * @since 21.0.0
  180. */
  181. public function getNumberOfUnreadCommentsForObjects(string $objectType, array $objectIds, IUser $user, $verb = ''): array;
  182. /**
  183. * @param string $objectType
  184. * @param string $objectId
  185. * @param int $lastRead
  186. * @param string $verb
  187. * @return int
  188. * @since 21.0.0
  189. */
  190. public function getNumberOfCommentsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, string $verb = ''): int;
  191. /**
  192. * @param string $objectType
  193. * @param string $objectId
  194. * @param int $lastRead
  195. * @param string[] $verbs
  196. * @return int
  197. * @since 24.0.0
  198. */
  199. public function getNumberOfCommentsWithVerbsForObjectSinceComment(string $objectType, string $objectId, int $lastRead, array $verbs): int;
  200. /**
  201. * @param string $objectType
  202. * @param string $objectId
  203. * @param \DateTime $beforeDate
  204. * @param string $verb
  205. * @return int
  206. * @since 21.0.0
  207. */
  208. public function getLastCommentBeforeDate(string $objectType, string $objectId, \DateTime $beforeDate, string $verb = ''): int;
  209. /**
  210. * @param string $objectType
  211. * @param string $objectId
  212. * @param string $verb
  213. * @param string $actorType
  214. * @param string[] $actors
  215. * @return \DateTime[] Map of "string actor" => "\DateTime most recent comment date"
  216. * @psalm-return array<string, \DateTime>
  217. * @since 21.0.0
  218. */
  219. public function getLastCommentDateByActor(
  220. string $objectType,
  221. string $objectId,
  222. string $verb,
  223. string $actorType,
  224. array $actors
  225. ): array;
  226. /**
  227. * Get the number of unread comments for all files in a folder
  228. *
  229. * @param int $folderId
  230. * @param IUser $user
  231. * @return array [$fileId => $unreadCount]
  232. * @since 12.0.0
  233. */
  234. public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user);
  235. /**
  236. * creates a new comment and returns it. At this point of time, it is not
  237. * saved in the used data storage. Use save() after setting other fields
  238. * of the comment (e.g. message or verb).
  239. *
  240. * @param string $actorType the actor type (e.g. 'users')
  241. * @param string $actorId a user id
  242. * @param string $objectType the object type the comment is attached to
  243. * @param string $objectId the object id the comment is attached to
  244. * @return IComment
  245. * @since 9.0.0
  246. */
  247. public function create($actorType, $actorId, $objectType, $objectId);
  248. /**
  249. * permanently deletes the comment specified by the ID
  250. *
  251. * When the comment has child comments, their parent ID will be changed to
  252. * the parent ID of the item that is to be deleted.
  253. *
  254. * @param string $id
  255. * @return bool
  256. * @since 9.0.0
  257. */
  258. public function delete($id);
  259. /**
  260. * saves the comment permanently
  261. *
  262. * if the supplied comment has an empty ID, a new entry comment will be
  263. * saved and the instance updated with the new ID.
  264. *
  265. * Otherwise, an existing comment will be updated.
  266. *
  267. * Throws NotFoundException when a comment that is to be updated does not
  268. * exist anymore at this point of time.
  269. *
  270. * @param IComment $comment
  271. * @return bool
  272. * @throws NotFoundException
  273. * @since 9.0.0
  274. */
  275. public function save(IComment $comment);
  276. /**
  277. * removes references to specific actor (e.g. on user delete) of a comment.
  278. * The comment itself must not get lost/deleted.
  279. *
  280. * A 'users' type actor (type and id) should get replaced by the
  281. * value of the DELETED_USER constant of this interface.
  282. *
  283. * @param string $actorType the actor type (e.g. 'users')
  284. * @param string $actorId a user id
  285. * @return boolean
  286. * @since 9.0.0
  287. */
  288. public function deleteReferencesOfActor($actorType, $actorId);
  289. /**
  290. * deletes all comments made of a specific object (e.g. on file delete)
  291. *
  292. * @param string $objectType the object type (e.g. 'files')
  293. * @param string $objectId e.g. the file id
  294. * @return boolean
  295. * @since 9.0.0
  296. */
  297. public function deleteCommentsAtObject($objectType, $objectId);
  298. /**
  299. * sets the read marker for a given file to the specified date for the
  300. * provided user
  301. *
  302. * @param string $objectType
  303. * @param string $objectId
  304. * @param \DateTime $dateTime
  305. * @param \OCP\IUser $user
  306. * @since 9.0.0
  307. */
  308. public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user);
  309. /**
  310. * returns the read marker for a given file to the specified date for the
  311. * provided user. It returns null, when the marker is not present, i.e.
  312. * no comments were marked as read.
  313. *
  314. * @param string $objectType
  315. * @param string $objectId
  316. * @param \OCP\IUser $user
  317. * @return \DateTime|null
  318. * @since 9.0.0
  319. */
  320. public function getReadMark($objectType, $objectId, \OCP\IUser $user);
  321. /**
  322. * deletes the read markers for the specified user
  323. *
  324. * @param \OCP\IUser $user
  325. * @return bool
  326. * @since 9.0.0
  327. */
  328. public function deleteReadMarksFromUser(\OCP\IUser $user);
  329. /**
  330. * deletes the read markers on the specified object
  331. *
  332. * @param string $objectType
  333. * @param string $objectId
  334. * @return bool
  335. * @since 9.0.0
  336. */
  337. public function deleteReadMarksOnObject($objectType, $objectId);
  338. /**
  339. * registers an Entity to the manager, so event notifications can be send
  340. * to consumers of the comments infrastructure
  341. *
  342. * @param \Closure $closure
  343. * @since 11.0.0
  344. */
  345. public function registerEventHandler(\Closure $closure);
  346. /**
  347. * registers a method that resolves an ID to a display name for a given type
  348. *
  349. * @param string $type
  350. * @param \Closure $closure
  351. * @throws \OutOfBoundsException
  352. * @since 11.0.0
  353. *
  354. * Only one resolver shall be registered per type. Otherwise a
  355. * \OutOfBoundsException has to thrown.
  356. */
  357. public function registerDisplayNameResolver($type, \Closure $closure);
  358. /**
  359. * resolves a given ID of a given Type to a display name.
  360. *
  361. * @param string $type
  362. * @param string $id
  363. * @return string
  364. * @throws \OutOfBoundsException
  365. * @since 11.0.0
  366. *
  367. * If a provided type was not registered, an \OutOfBoundsException shall
  368. * be thrown. It is upon the resolver discretion what to return of the
  369. * provided ID is unknown. It must be ensured that a string is returned.
  370. */
  371. public function resolveDisplayName($type, $id);
  372. /**
  373. * Load the Comments app into the page
  374. *
  375. * @since 21.0.0
  376. */
  377. public function load(): void;
  378. }