IComment.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. * @psalm-return list<array{type: 'guest'|'email'|'federated_group'|'group'|'federated_team'|'team'|'federated_user'|'user', id: non-empty-lowercase-string}>
  114. * @since 30.0.2 Type 'email' is supported
  115. * @since 29.0.0 Types 'federated_group', 'federated_team', 'team' and 'federated_user' are supported
  116. * @since 23.0.0 Type 'group' is supported
  117. * @since 17.0.0 Type 'guest' is supported
  118. * @since 11.0.0
  119. */
  120. public function getMentions();
  121. /**
  122. * returns the verb of the comment
  123. *
  124. * @return string
  125. * @since 9.0.0
  126. */
  127. public function getVerb();
  128. /**
  129. * sets the verb of the comment, e.g. 'comment' or 'like'
  130. *
  131. * @param string $verb
  132. * @return IComment
  133. * @since 9.0.0
  134. */
  135. public function setVerb($verb);
  136. /**
  137. * returns the actor type
  138. *
  139. * @return string
  140. * @since 9.0.0
  141. */
  142. public function getActorType();
  143. /**
  144. * returns the actor ID
  145. *
  146. * @return string
  147. * @since 9.0.0
  148. */
  149. public function getActorId();
  150. /**
  151. * sets (overwrites) the actor type and id
  152. *
  153. * @param string $actorType e.g. 'users'
  154. * @param string $actorId e.g. 'zombie234'
  155. * @return IComment
  156. * @since 9.0.0
  157. */
  158. public function setActor($actorType, $actorId);
  159. /**
  160. * returns the creation date of the comment.
  161. *
  162. * If not explicitly set, it shall default to the time of initialization.
  163. *
  164. * @return \DateTime
  165. * @since 9.0.0
  166. */
  167. public function getCreationDateTime();
  168. /**
  169. * sets the creation date of the comment and returns itself
  170. *
  171. * @param \DateTime $dateTime
  172. * @return IComment
  173. * @since 9.0.0
  174. */
  175. public function setCreationDateTime(\DateTime $dateTime);
  176. /**
  177. * returns the date of the most recent child
  178. *
  179. * @return \DateTime
  180. * @since 9.0.0
  181. */
  182. public function getLatestChildDateTime();
  183. /**
  184. * sets the date of the most recent child
  185. *
  186. * @param \DateTime|null $dateTime
  187. * @return IComment
  188. * @since 9.0.0
  189. */
  190. public function setLatestChildDateTime(?\DateTime $dateTime = null);
  191. /**
  192. * returns the object type the comment is attached to
  193. *
  194. * @return string
  195. * @since 9.0.0
  196. */
  197. public function getObjectType();
  198. /**
  199. * returns the object id the comment is attached to
  200. *
  201. * @return string
  202. * @since 9.0.0
  203. */
  204. public function getObjectId();
  205. /**
  206. * sets (overwrites) the object of the comment
  207. *
  208. * @param string $objectType e.g. 'files'
  209. * @param string $objectId e.g. '16435'
  210. * @return IComment
  211. * @since 9.0.0
  212. */
  213. public function setObject($objectType, $objectId);
  214. /**
  215. * returns the reference id of the comment
  216. *
  217. * @return string|null
  218. * @since 19.0.0
  219. */
  220. public function getReferenceId(): ?string;
  221. /**
  222. * sets (overwrites) the reference id of the comment
  223. *
  224. * @param string|null $referenceId e.g. sha256 hash sum
  225. * @return IComment
  226. * @since 19.0.0
  227. */
  228. public function setReferenceId(?string $referenceId): IComment;
  229. /**
  230. * Returns the metadata of the comment
  231. *
  232. * @return array|null
  233. * @since 29.0.0
  234. */
  235. public function getMetaData(): ?array;
  236. /**
  237. * Sets (overwrites) the metadata of the comment
  238. * Data as a json encoded array
  239. *
  240. * @param array|null $metaData
  241. * @return IComment
  242. * @throws \JsonException When the metadata can not be converted to a json encoded string
  243. * @since 29.0.0
  244. */
  245. public function setMetaData(?array $metaData): IComment;
  246. /**
  247. * Returns the reactions array if exists
  248. *
  249. * The keys is the emoji of reaction and the value is the total.
  250. *
  251. * @return array<string, integer> e.g. ["👍":1]
  252. * @since 24.0.0
  253. */
  254. public function getReactions(): array;
  255. /**
  256. * Set summarized array of reactions by reaction type
  257. *
  258. * The keys is the emoji of reaction and the value is the total.
  259. *
  260. * @param array<string, integer>|null $reactions e.g. ["👍":1]
  261. * @return IComment
  262. * @since 24.0.0
  263. */
  264. public function setReactions(?array $reactions): IComment;
  265. /**
  266. * Set message expire date
  267. *
  268. * @param \DateTime|null $dateTime
  269. * @return IComment
  270. * @since 25.0.0
  271. */
  272. public function setExpireDate(?\DateTime $dateTime): IComment;
  273. /**
  274. * Get message expire date
  275. *
  276. * @return ?\DateTime
  277. * @since 25.0.0
  278. */
  279. public function getExpireDate(): ?\DateTime;
  280. }