IComment.php 6.5 KB

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