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 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  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 Lukas Reschke <lukas@statuscode.ch>
  9. * @author Robin Appelman <robin@icewind.nl>
  10. * @author Roeland Jago Douma <roeland@famdouma.nl>
  11. * @author Thomas Müller <thomas.mueller@tmit.eu>
  12. *
  13. * @license AGPL-3.0
  14. *
  15. * This code is free software: you can redistribute it and/or modify
  16. * it under the terms of the GNU Affero General Public License, version 3,
  17. * as published by the Free Software Foundation.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU Affero General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU Affero General Public License, version 3,
  25. * along with this program. If not, see <http://www.gnu.org/licenses/>
  26. *
  27. */
  28. namespace OCP\Comments;
  29. use OCP\IUser;
  30. /**
  31. * Interface ICommentsManager
  32. *
  33. * This class manages the access to comments
  34. *
  35. * @since 9.0.0
  36. */
  37. interface ICommentsManager {
  38. /**
  39. * @const DELETED_USER type and id for a user that has been deleted
  40. * @see deleteReferencesOfActor
  41. * @since 9.0.0
  42. *
  43. * To be used as replacement for user type actors in deleteReferencesOfActor().
  44. *
  45. * User interfaces shall show "Deleted user" as display name, if needed.
  46. */
  47. public const DELETED_USER = 'deleted_users';
  48. /**
  49. * returns a comment instance
  50. *
  51. * @param string $id the ID of the comment
  52. * @return IComment
  53. * @throws NotFoundException
  54. * @since 9.0.0
  55. */
  56. public function get($id);
  57. /**
  58. * returns the comment specified by the id and all it's child comments
  59. *
  60. * @param string $id
  61. * @param int $limit max number of entries to return, 0 returns all
  62. * @param int $offset the start entry
  63. * @return array
  64. * @since 9.0.0
  65. *
  66. * The return array looks like this
  67. * [
  68. * 'comment' => IComment, // root comment
  69. * 'replies' =>
  70. * [
  71. * 0 =>
  72. * [
  73. * 'comment' => IComment,
  74. * 'replies' =>
  75. * [
  76. * 0 =>
  77. * [
  78. * 'comment' => IComment,
  79. * 'replies' => [ … ]
  80. * ],
  81. * …
  82. * ]
  83. * ]
  84. * 1 =>
  85. * [
  86. * 'comment' => IComment,
  87. * 'replies'=> [ … ]
  88. * ],
  89. * …
  90. * ]
  91. * ]
  92. */
  93. public function getTree($id, $limit = 0, $offset = 0);
  94. /**
  95. * returns comments for a specific object (e.g. a file).
  96. *
  97. * The sort order is always newest to oldest.
  98. *
  99. * @param string $objectType the object type, e.g. 'files'
  100. * @param string $objectId the id of the object
  101. * @param int $limit optional, number of maximum comments to be returned. if
  102. * not specified, all comments are returned.
  103. * @param int $offset optional, starting point
  104. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  105. * that may be returned
  106. * @return IComment[]
  107. * @since 9.0.0
  108. */
  109. public function getForObject(
  110. $objectType,
  111. $objectId,
  112. $limit = 0,
  113. $offset = 0,
  114. \DateTime $notOlderThan = null
  115. );
  116. /**
  117. * @param string $objectType the object type, e.g. 'files'
  118. * @param string $objectId the id of the object
  119. * @param int $lastKnownCommentId the last known comment (will be used as offset)
  120. * @param string $sortDirection direction of the comments (`asc` or `desc`)
  121. * @param int $limit optional, number of maximum comments to be returned. if
  122. * set to 0, all comments are returned.
  123. * @return IComment[]
  124. * @since 14.0.0
  125. */
  126. public function getForObjectSince(
  127. string $objectType,
  128. string $objectId,
  129. int $lastKnownCommentId,
  130. string $sortDirection = 'asc',
  131. int $limit = 30
  132. ): array;
  133. /**
  134. * Search for comments with a given content
  135. *
  136. * @param string $search content to search for
  137. * @param string $objectType Limit the search by object type
  138. * @param string $objectId Limit the search by object id
  139. * @param string $verb Limit the verb of the comment
  140. * @param int $offset
  141. * @param int $limit
  142. * @return IComment[]
  143. * @since 14.0.0
  144. */
  145. public function search(string $search, string $objectType, string $objectId, string $verb, int $offset, int $limit = 50): array;
  146. /**
  147. * @param $objectType string the object type, e.g. 'files'
  148. * @param $objectId string the id of the object
  149. * @param \DateTime|null $notOlderThan optional, timestamp of the oldest comments
  150. * that may be returned
  151. * @param string $verb Limit the verb of the comment - Added in 14.0.0
  152. * @return Int
  153. * @since 9.0.0
  154. */
  155. public function getNumberOfCommentsForObject($objectType, $objectId, \DateTime $notOlderThan = null, $verb = '');
  156. /**
  157. * Get the number of unread comments for all files in a folder
  158. *
  159. * @param int $folderId
  160. * @param IUser $user
  161. * @return array [$fileId => $unreadCount]
  162. * @since 12.0.0
  163. */
  164. public function getNumberOfUnreadCommentsForFolder($folderId, IUser $user);
  165. /**
  166. * creates a new comment and returns it. At this point of time, it is not
  167. * saved in the used data storage. Use save() after setting other fields
  168. * of the comment (e.g. message or verb).
  169. *
  170. * @param string $actorType the actor type (e.g. 'users')
  171. * @param string $actorId a user id
  172. * @param string $objectType the object type the comment is attached to
  173. * @param string $objectId the object id the comment is attached to
  174. * @return IComment
  175. * @since 9.0.0
  176. */
  177. public function create($actorType, $actorId, $objectType, $objectId);
  178. /**
  179. * permanently deletes the comment specified by the ID
  180. *
  181. * When the comment has child comments, their parent ID will be changed to
  182. * the parent ID of the item that is to be deleted.
  183. *
  184. * @param string $id
  185. * @return bool
  186. * @since 9.0.0
  187. */
  188. public function delete($id);
  189. /**
  190. * saves the comment permanently
  191. *
  192. * if the supplied comment has an empty ID, a new entry comment will be
  193. * saved and the instance updated with the new ID.
  194. *
  195. * Otherwise, an existing comment will be updated.
  196. *
  197. * Throws NotFoundException when a comment that is to be updated does not
  198. * exist anymore at this point of time.
  199. *
  200. * @param IComment $comment
  201. * @return bool
  202. * @throws NotFoundException
  203. * @since 9.0.0
  204. */
  205. public function save(IComment $comment);
  206. /**
  207. * removes references to specific actor (e.g. on user delete) of a comment.
  208. * The comment itself must not get lost/deleted.
  209. *
  210. * A 'users' type actor (type and id) should get replaced by the
  211. * value of the DELETED_USER constant of this interface.
  212. *
  213. * @param string $actorType the actor type (e.g. 'users')
  214. * @param string $actorId a user id
  215. * @return boolean
  216. * @since 9.0.0
  217. */
  218. public function deleteReferencesOfActor($actorType, $actorId);
  219. /**
  220. * deletes all comments made of a specific object (e.g. on file delete)
  221. *
  222. * @param string $objectType the object type (e.g. 'files')
  223. * @param string $objectId e.g. the file id
  224. * @return boolean
  225. * @since 9.0.0
  226. */
  227. public function deleteCommentsAtObject($objectType, $objectId);
  228. /**
  229. * sets the read marker for a given file to the specified date for the
  230. * provided user
  231. *
  232. * @param string $objectType
  233. * @param string $objectId
  234. * @param \DateTime $dateTime
  235. * @param \OCP\IUser $user
  236. * @since 9.0.0
  237. */
  238. public function setReadMark($objectType, $objectId, \DateTime $dateTime, \OCP\IUser $user);
  239. /**
  240. * returns the read marker for a given file to the specified date for the
  241. * provided user. It returns null, when the marker is not present, i.e.
  242. * no comments were marked as read.
  243. *
  244. * @param string $objectType
  245. * @param string $objectId
  246. * @param \OCP\IUser $user
  247. * @return \DateTime|null
  248. * @since 9.0.0
  249. */
  250. public function getReadMark($objectType, $objectId, \OCP\IUser $user);
  251. /**
  252. * deletes the read markers for the specified user
  253. *
  254. * @param \OCP\IUser $user
  255. * @return bool
  256. * @since 9.0.0
  257. */
  258. public function deleteReadMarksFromUser(\OCP\IUser $user);
  259. /**
  260. * deletes the read markers on the specified object
  261. *
  262. * @param string $objectType
  263. * @param string $objectId
  264. * @return bool
  265. * @since 9.0.0
  266. */
  267. public function deleteReadMarksOnObject($objectType, $objectId);
  268. /**
  269. * registers an Entity to the manager, so event notifications can be send
  270. * to consumers of the comments infrastructure
  271. *
  272. * @param \Closure $closure
  273. * @since 11.0.0
  274. */
  275. public function registerEventHandler(\Closure $closure);
  276. /**
  277. * registers a method that resolves an ID to a display name for a given type
  278. *
  279. * @param string $type
  280. * @param \Closure $closure
  281. * @throws \OutOfBoundsException
  282. * @since 11.0.0
  283. *
  284. * Only one resolver shall be registered per type. Otherwise a
  285. * \OutOfBoundsException has to thrown.
  286. */
  287. public function registerDisplayNameResolver($type, \Closure $closure);
  288. /**
  289. * resolves a given ID of a given Type to a display name.
  290. *
  291. * @param string $type
  292. * @param string $id
  293. * @return string
  294. * @throws \OutOfBoundsException
  295. * @since 11.0.0
  296. *
  297. * If a provided type was not registered, an \OutOfBoundsException shall
  298. * be thrown. It is upon the resolver discretion what to return of the
  299. * provided ID is unknown. It must be ensured that a string is returned.
  300. */
  301. public function resolveDisplayName($type, $id);
  302. /**
  303. * Load the Comments app into the page
  304. *
  305. * @since 21.0.0
  306. */
  307. public function load(): void;
  308. }