IComment.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  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 Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCP\Comments;
  27. /**
  28. * Interface IComment
  29. *
  30. * This class represents a comment
  31. *
  32. * @since 9.0.0
  33. */
  34. interface IComment {
  35. /**
  36. * @since 9.0.0
  37. */
  38. public const MAX_MESSAGE_LENGTH = 1000;
  39. /**
  40. * returns the ID of the comment
  41. *
  42. * It may return an empty string, if the comment was not stored.
  43. * It is expected that the concrete Comment implementation gives an ID
  44. * by itself (e.g. after saving).
  45. *
  46. * @return string
  47. * @since 9.0.0
  48. */
  49. public function getId();
  50. /**
  51. * sets the ID of the comment and returns itself
  52. *
  53. * It is only allowed to set the ID only, if the current id is an empty
  54. * string (which means it is not stored in a database, storage or whatever
  55. * the concrete implementation does), or vice versa. Changing a given ID is
  56. * not permitted and must result in an IllegalIDChangeException.
  57. *
  58. * @param string $id
  59. * @return IComment
  60. * @throws IllegalIDChangeException
  61. * @since 9.0.0
  62. */
  63. public function setId($id);
  64. /**
  65. * returns the parent ID of the comment
  66. *
  67. * @return string
  68. * @since 9.0.0
  69. */
  70. public function getParentId();
  71. /**
  72. * sets the parent ID and returns itself
  73. * @param string $parentId
  74. * @return IComment
  75. * @since 9.0.0
  76. */
  77. public function setParentId($parentId);
  78. /**
  79. * returns the topmost parent ID of the comment
  80. *
  81. * @return string
  82. * @since 9.0.0
  83. */
  84. public function getTopmostParentId();
  85. /**
  86. * sets the topmost parent ID and returns itself
  87. *
  88. * @param string $id
  89. * @return IComment
  90. * @since 9.0.0
  91. */
  92. public function setTopmostParentId($id);
  93. /**
  94. * returns the number of children
  95. *
  96. * @return int
  97. * @since 9.0.0
  98. */
  99. public function getChildrenCount();
  100. /**
  101. * sets the number of children
  102. *
  103. * @param int $count
  104. * @return IComment
  105. * @since 9.0.0
  106. */
  107. public function setChildrenCount($count);
  108. /**
  109. * returns the message of the comment
  110. *
  111. * @return string
  112. * @since 9.0.0
  113. */
  114. public function getMessage();
  115. /**
  116. * sets the message of the comment and returns itself
  117. *
  118. * When the given message length exceeds MAX_MESSAGE_LENGTH an
  119. * MessageTooLongException shall be thrown.
  120. *
  121. * @param string $message
  122. * @param int $maxLength
  123. * @return IComment
  124. * @throws MessageTooLongException
  125. * @since 9.0.0 - $maxLength added in 16.0.2
  126. */
  127. public function setMessage($message, $maxLength = self::MAX_MESSAGE_LENGTH);
  128. /**
  129. * returns an array containing mentions that are included in the comment
  130. *
  131. * @return array each mention provides a 'type' and an 'id', see example below
  132. * @since 11.0.0
  133. *
  134. * The return array looks like:
  135. * [
  136. * [
  137. * 'type' => 'user',
  138. * 'id' => 'citizen4'
  139. * ],
  140. * [
  141. * 'type' => 'group',
  142. * 'id' => 'media'
  143. * ],
  144. * …
  145. * ]
  146. *
  147. */
  148. public function getMentions();
  149. /**
  150. * returns the verb of the comment
  151. *
  152. * @return string
  153. * @since 9.0.0
  154. */
  155. public function getVerb();
  156. /**
  157. * sets the verb of the comment, e.g. 'comment' or 'like'
  158. *
  159. * @param string $verb
  160. * @return IComment
  161. * @since 9.0.0
  162. */
  163. public function setVerb($verb);
  164. /**
  165. * returns the actor type
  166. *
  167. * @return string
  168. * @since 9.0.0
  169. */
  170. public function getActorType();
  171. /**
  172. * returns the actor ID
  173. *
  174. * @return string
  175. * @since 9.0.0
  176. */
  177. public function getActorId();
  178. /**
  179. * sets (overwrites) the actor type and id
  180. *
  181. * @param string $actorType e.g. 'users'
  182. * @param string $actorId e.g. 'zombie234'
  183. * @return IComment
  184. * @since 9.0.0
  185. */
  186. public function setActor($actorType, $actorId);
  187. /**
  188. * returns the creation date of the comment.
  189. *
  190. * If not explicitly set, it shall default to the time of initialization.
  191. *
  192. * @return \DateTime
  193. * @since 9.0.0
  194. */
  195. public function getCreationDateTime();
  196. /**
  197. * sets the creation date of the comment and returns itself
  198. *
  199. * @param \DateTime $dateTime
  200. * @return IComment
  201. * @since 9.0.0
  202. */
  203. public function setCreationDateTime(\DateTime $dateTime);
  204. /**
  205. * returns the date of the most recent child
  206. *
  207. * @return \DateTime
  208. * @since 9.0.0
  209. */
  210. public function getLatestChildDateTime();
  211. /**
  212. * sets the date of the most recent child
  213. *
  214. * @param \DateTime|null $dateTime
  215. * @return IComment
  216. * @since 9.0.0
  217. */
  218. public function setLatestChildDateTime(?\DateTime $dateTime = null);
  219. /**
  220. * returns the object type the comment is attached to
  221. *
  222. * @return string
  223. * @since 9.0.0
  224. */
  225. public function getObjectType();
  226. /**
  227. * returns the object id the comment is attached to
  228. *
  229. * @return string
  230. * @since 9.0.0
  231. */
  232. public function getObjectId();
  233. /**
  234. * sets (overwrites) the object of the comment
  235. *
  236. * @param string $objectType e.g. 'files'
  237. * @param string $objectId e.g. '16435'
  238. * @return IComment
  239. * @since 9.0.0
  240. */
  241. public function setObject($objectType, $objectId);
  242. /**
  243. * returns the reference id of the comment
  244. *
  245. * @return string|null
  246. * @since 19.0.0
  247. */
  248. public function getReferenceId(): ?string;
  249. /**
  250. * sets (overwrites) the reference id of the comment
  251. *
  252. * @param string|null $referenceId e.g. sha256 hash sum
  253. * @return IComment
  254. * @since 19.0.0
  255. */
  256. public function setReferenceId(?string $referenceId): IComment;
  257. /**
  258. * Returns the metadata of the comment
  259. *
  260. * @return array|null
  261. * @since 29.0.0
  262. */
  263. public function getMetaData(): ?array;
  264. /**
  265. * Sets (overwrites) the metadata of the comment
  266. * Data as a json encoded array
  267. *
  268. * @param array|null $metaData
  269. * @return IComment
  270. * @throws \JsonException When the metadata can not be converted to a json encoded string
  271. * @since 29.0.0
  272. */
  273. public function setMetaData(?array $metaData): IComment;
  274. /**
  275. * Returns the reactions array if exists
  276. *
  277. * The keys is the emoji of reaction and the value is the total.
  278. *
  279. * @return array<string, integer> e.g. ["👍":1]
  280. * @since 24.0.0
  281. */
  282. public function getReactions(): array;
  283. /**
  284. * Set summarized array of reactions by reaction type
  285. *
  286. * The keys is the emoji of reaction and the value is the total.
  287. *
  288. * @param array<string, integer>|null $reactions e.g. ["👍":1]
  289. * @return IComment
  290. * @since 24.0.0
  291. */
  292. public function setReactions(?array $reactions): IComment;
  293. /**
  294. * Set message expire date
  295. *
  296. * @param \DateTime|null $dateTime
  297. * @return IComment
  298. * @since 25.0.0
  299. */
  300. public function setExpireDate(?\DateTime $dateTime): IComment;
  301. /**
  302. * Get message expire date
  303. *
  304. * @return ?\DateTime
  305. * @since 25.0.0
  306. */
  307. public function getExpireDate(): ?\DateTime;
  308. }