001// Generated by delombok at Tue Dec 10 13:42:03 UTC 2024 002/* 003 * Copyright (c) 2010-2024 Mark Allen, Norbert Bartels. 004 * 005 * Permission is hereby granted, free of charge, to any person obtaining a copy 006 * of this software and associated documentation files (the "Software"), to deal 007 * in the Software without restriction, including without limitation the rights 008 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 009 * copies of the Software, and to permit persons to whom the Software is 010 * furnished to do so, subject to the following conditions: 011 * 012 * The above copyright notice and this permission notice shall be included in 013 * all copies or substantial portions of the Software. 014 * 015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 018 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 019 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 020 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 021 * THE SOFTWARE. 022 */ 023package com.restfb.types; 024 025import static java.util.Collections.unmodifiableList; 026import java.util.ArrayList; 027import java.util.Date; 028import java.util.List; 029import com.restfb.Facebook; 030import com.restfb.JsonMapper; 031import com.restfb.JsonMapper.JsonMappingCompleted; 032import com.restfb.annotation.GraphAPI; 033import com.restfb.exception.FacebookJsonMappingException; 034import com.restfb.json.JsonObject; 035import com.restfb.types.features.HasComments; 036import com.restfb.types.features.HasCreatedTime; 037import com.restfb.types.features.HasMessage; 038 039/** 040 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/comment">Comment Graph API type</a>. 041 * 042 * @author <a href="http://restfb.com">Mark Allen</a> 043 * @since 1.5 044 */ 045public class Comment extends FacebookType implements HasComments, HasCreatedTime, HasMessage { 046 /** 047 * User who posted the comment. 048 */ 049 @Facebook 050 private From from; 051 /** 052 * Text contents of the comment. 053 */ 054 @Facebook 055 private String message; 056 /** 057 * Date on which the comment was created. 058 */ 059 @Facebook("created_time") 060 private Date createdTime; 061 /** 062 * Duplicate mapping for "likes" since FB can return it differently in different situations. 063 * <p> 064 * -- GETTER -- The likes on this post. 065 * <p> 066 * Sometimes this can be {@code null} - check {@link #getLikeCount()} instead in that case. 067 */ 068 @Facebook 069 private Likes likes; 070 /** 071 * The reactions for this post. 072 */ 073 @Facebook 074 private Reactions reactions; 075 /** 076 * The number of likes on this comment. 077 * 078 * @since 1.6.10 079 */ 080 @Facebook("like_count") 081 private Long likeCount; 082 /** 083 * Number of replies to this comment. 084 */ 085 @Facebook("comment_count") 086 private long commentCount; 087 /** 088 * This field is returned only if the authenticated user can remove this comment. 089 * 090 * @since 1.6.10 091 */ 092 @Facebook("can_remove") 093 private Boolean canRemove; 094 /** 095 * This field is returned only if the authenticated user likes this comment 096 * 097 * @since 1.6.10 098 */ 099 @Facebook("user_likes") 100 private Boolean userLikes; 101 /** 102 * If this comment is a reply, this field returns the parent comment, otherwise no value 103 * 104 * @since 1.6.13 105 */ 106 @Facebook 107 private Comment parent; 108 /** 109 * Specifies whether you can reply to this comment 110 * 111 * @since 1.6.13 112 */ 113 @Facebook("can_comment") 114 private Boolean canComment; 115 /** 116 * Whether the viewer can hide this comment 117 * 118 * @since 1.7.1 119 */ 120 @Facebook("can_hide") 121 private Boolean canHide; 122 /** 123 * Whether the viewer can send a private reply to this comment (Page viewers only) 124 */ 125 @Facebook("can_reply_privately") 126 @GraphAPI(since = "2.5") 127 private Boolean canReplyPrivately; 128 /** 129 * For comments with private replies, gets conversation between the Page and author of the comment (Page viewers only) 130 */ 131 @Facebook("private_reply_conversation") 132 @GraphAPI(since = "2.5") 133 private Conversation privateReplyConversation; 134 /** 135 * Whether this comment is hidden. The original poster can still see the comment, along with the page admin and anyone 136 * else tagged in the comment 137 * 138 * @since 1.7.1 139 */ 140 @Facebook("is_hidden") 141 private Boolean isHidden; 142 /** 143 * Whether the viewer can like this comment 144 */ 145 @Facebook("can_like") 146 private Boolean canLike; 147 /** 148 * Parent object this comment was made on. 149 * 150 * @since 1.7.1 151 */ 152 @Facebook 153 private NamedFacebookType object; 154 /** 155 * The permanent static URL to the comment 156 */ 157 @Facebook("permalink_url") 158 private String permalinkUrl; 159 /** 160 * The replies to this comment 161 */ 162 @Facebook("comments") 163 private Comments comments; 164 /** 165 * Attachment (image) added to a comment. 166 * <p> 167 * To force Facebook to fill the <code>attachment</code> field you have to fetch the comment with the 168 * <code>fields=attachment</code> parameter, otherwise the attachments are <code>null</code>. 169 */ 170 @Facebook 171 private StoryAttachment attachment; 172 @Facebook("message_tags") 173 private transient String rawMessageTags; 174 private List<MessageTag> messageTags = new ArrayList<>(); 175 private static final long serialVersionUID = 2L; 176 177 /** 178 * Post-JSON-mapping operation that populates the {@code messageTags} field "by hand". 179 * 180 * @param jsonMapper 181 * The {@code JsonMapper} that was used to map to this type. 182 */ 183 @JsonMappingCompleted 184 protected void jsonMappingCompleted(JsonMapper jsonMapper) { 185 if (rawMessageTags == null) { 186 return; 187 } 188 try { 189 messageTags = jsonMapper.toJavaList(rawMessageTags, MessageTag.class); 190 return; 191 } catch (FacebookJsonMappingException je) { 192 } 193 // message tags not in Graph API 2.5 format, ignore this exception and try another way 194 try { 195 JsonObject rawMessageTagsObject = jsonMapper.toJavaObject(rawMessageTags, JsonObject.class); 196 for (String key : rawMessageTagsObject.names()) { 197 String tagArrayString = rawMessageTagsObject.get(key).toString(); 198 messageTags.addAll(jsonMapper.toJavaList(tagArrayString, MessageTag.class)); 199 } 200 } catch (FacebookJsonMappingException je) { 201 } 202 // cannot parse message tags, but don't break the flow here 203 } 204 205 /** 206 * Objects tagged in the message (Users, Pages, etc.) 207 * 208 * @return Objects tagged in the message (Users, Pages, etc.) 209 * @since 1.6.10 210 */ 211 public List<MessageTag> getMessageTags() { 212 return unmodifiableList(messageTags); 213 } 214 215 public void addMessageTag(MessageTag messageTag) { 216 messageTags.add(messageTag); 217 } 218 219 public void removeMessageTag(MessageTag messageTag) { 220 messageTags.remove(messageTag); 221 } 222 223 /** 224 * User who posted the comment. 225 * 226 * @return User who posted the comment. 227 */ 228 @java.lang.SuppressWarnings("all") 229 public From getFrom() { 230 return this.from; 231 } 232 233 /** 234 * User who posted the comment. 235 */ 236 @java.lang.SuppressWarnings("all") 237 public void setFrom(final From from) { 238 this.from = from; 239 } 240 241 /** 242 * Text contents of the comment. 243 * 244 * @return Text contents of the comment. 245 */ 246 @Override 247 @java.lang.SuppressWarnings("all") 248 public String getMessage() { 249 return this.message; 250 } 251 252 /** 253 * Text contents of the comment. 254 */ 255 @java.lang.SuppressWarnings("all") 256 public void setMessage(final String message) { 257 this.message = message; 258 } 259 260 /** 261 * Date on which the comment was created. 262 * 263 * @return Date on which the comment was created. 264 */ 265 @Override 266 @java.lang.SuppressWarnings("all") 267 public Date getCreatedTime() { 268 return this.createdTime; 269 } 270 271 /** 272 * Date on which the comment was created. 273 */ 274 @java.lang.SuppressWarnings("all") 275 public void setCreatedTime(final Date createdTime) { 276 this.createdTime = createdTime; 277 } 278 279 /** 280 * Duplicate mapping for "likes" since FB can return it differently in different situations. 281 * <p> 282 * -- GETTER -- The likes on this post. 283 * <p> 284 * Sometimes this can be {@code null} - check {@link #getLikeCount()} instead in that case. 285 * 286 * @return The likes on this comment. 287 */ 288 @java.lang.SuppressWarnings("all") 289 public Likes getLikes() { 290 return this.likes; 291 } 292 293 /** 294 * Duplicate mapping for "likes" since FB can return it differently in different situations. 295 * <p> 296 * -- GETTER -- The likes on this post. 297 * <p> 298 * Sometimes this can be {@code null} - check {@link #getLikeCount()} instead in that case. 299 */ 300 @java.lang.SuppressWarnings("all") 301 public void setLikes(final Likes likes) { 302 this.likes = likes; 303 } 304 305 /** 306 * The reactions for this post. 307 * 308 * @return The reactions for this post. 309 */ 310 @java.lang.SuppressWarnings("all") 311 public Reactions getReactions() { 312 return this.reactions; 313 } 314 315 /** 316 * The reactions for this post. 317 */ 318 @java.lang.SuppressWarnings("all") 319 public void setReactions(final Reactions reactions) { 320 this.reactions = reactions; 321 } 322 323 /** 324 * The number of likes on this comment. 325 * 326 * @return The number of likes on this comment. 327 * @since 1.6.10 328 */ 329 @java.lang.SuppressWarnings("all") 330 public Long getLikeCount() { 331 return this.likeCount; 332 } 333 334 /** 335 * The number of likes on this comment. 336 * 337 * @since 1.6.10 338 */ 339 @java.lang.SuppressWarnings("all") 340 public void setLikeCount(final Long likeCount) { 341 this.likeCount = likeCount; 342 } 343 344 /** 345 * Number of replies to this comment. 346 * 347 * @return Number of replies to this comment 348 */ 349 @java.lang.SuppressWarnings("all") 350 public long getCommentCount() { 351 return this.commentCount; 352 } 353 354 /** 355 * Number of replies to this comment. 356 */ 357 @java.lang.SuppressWarnings("all") 358 public void setCommentCount(final long commentCount) { 359 this.commentCount = commentCount; 360 } 361 362 /** 363 * This field is returned only if the authenticated user can remove this comment. 364 * 365 * @return This field is returned only if the authenticated user can remove this comment. 366 * @since 1.6.10 367 */ 368 @java.lang.SuppressWarnings("all") 369 public Boolean getCanRemove() { 370 return this.canRemove; 371 } 372 373 /** 374 * This field is returned only if the authenticated user can remove this comment. 375 * 376 * @since 1.6.10 377 */ 378 @java.lang.SuppressWarnings("all") 379 public void setCanRemove(final Boolean canRemove) { 380 this.canRemove = canRemove; 381 } 382 383 /** 384 * This field is returned only if the authenticated user likes this comment 385 * 386 * @return This field is returned only if the authenticated user likes this comment. 387 * @since 1.6.10 388 */ 389 @java.lang.SuppressWarnings("all") 390 public Boolean getUserLikes() { 391 return this.userLikes; 392 } 393 394 /** 395 * This field is returned only if the authenticated user likes this comment 396 * 397 * @since 1.6.10 398 */ 399 @java.lang.SuppressWarnings("all") 400 public void setUserLikes(final Boolean userLikes) { 401 this.userLikes = userLikes; 402 } 403 404 /** 405 * If this comment is a reply, this field returns the parent comment, otherwise no value 406 * 407 * @return the parent Comment 408 * @since 1.6.13 409 */ 410 @java.lang.SuppressWarnings("all") 411 public Comment getParent() { 412 return this.parent; 413 } 414 415 /** 416 * If this comment is a reply, this field returns the parent comment, otherwise no value 417 * 418 * @since 1.6.13 419 */ 420 @java.lang.SuppressWarnings("all") 421 public void setParent(final Comment parent) { 422 this.parent = parent; 423 } 424 425 /** 426 * Specifies whether you can reply to this comment 427 * 428 * @return can_comment 429 * @since 1.6.13 430 */ 431 @java.lang.SuppressWarnings("all") 432 public Boolean getCanComment() { 433 return this.canComment; 434 } 435 436 /** 437 * Specifies whether you can reply to this comment 438 * 439 * @since 1.6.13 440 */ 441 @java.lang.SuppressWarnings("all") 442 public void setCanComment(final Boolean canComment) { 443 this.canComment = canComment; 444 } 445 446 /** 447 * Whether the viewer can hide this comment 448 * 449 * @return can_hide 450 * @since 1.7.1 451 */ 452 @java.lang.SuppressWarnings("all") 453 public Boolean getCanHide() { 454 return this.canHide; 455 } 456 457 /** 458 * Whether the viewer can hide this comment 459 * 460 * @since 1.7.1 461 */ 462 @java.lang.SuppressWarnings("all") 463 public void setCanHide(final Boolean canHide) { 464 this.canHide = canHide; 465 } 466 467 /** 468 * Whether the viewer can send a private reply to this comment (Page viewers only) 469 * 470 * @return Whether the viewer can send a private reply to this comment 471 */ 472 @GraphAPI(since = "2.5") 473 @java.lang.SuppressWarnings("all") 474 public Boolean getCanReplyPrivately() { 475 return this.canReplyPrivately; 476 } 477 478 /** 479 * Whether the viewer can send a private reply to this comment (Page viewers only) 480 */ 481 @java.lang.SuppressWarnings("all") 482 public void setCanReplyPrivately(final Boolean canReplyPrivately) { 483 this.canReplyPrivately = canReplyPrivately; 484 } 485 486 /** 487 * For comments with private replies, gets conversation between the Page and author of the comment (Page viewers only) 488 * 489 * @return conversation between Page and author of the comment 490 */ 491 @GraphAPI(since = "2.5") 492 @java.lang.SuppressWarnings("all") 493 public Conversation getPrivateReplyConversation() { 494 return this.privateReplyConversation; 495 } 496 497 /** 498 * For comments with private replies, gets conversation between the Page and author of the comment (Page viewers only) 499 */ 500 @java.lang.SuppressWarnings("all") 501 public void setPrivateReplyConversation(final Conversation privateReplyConversation) { 502 this.privateReplyConversation = privateReplyConversation; 503 } 504 505 /** 506 * Whether this comment is hidden. The original poster can still see the comment, along with the page admin and anyone 507 * else tagged in the comment 508 * 509 * @return is_hidden 510 * @since 1.7.1 511 */ 512 @java.lang.SuppressWarnings("all") 513 public Boolean getIsHidden() { 514 return this.isHidden; 515 } 516 517 /** 518 * Whether this comment is hidden. The original poster can still see the comment, along with the page admin and anyone 519 * else tagged in the comment 520 * 521 * @since 1.7.1 522 */ 523 @java.lang.SuppressWarnings("all") 524 public void setIsHidden(final Boolean isHidden) { 525 this.isHidden = isHidden; 526 } 527 528 /** 529 * Whether the viewer can like this comment 530 * 531 * @return can_like 532 */ 533 @java.lang.SuppressWarnings("all") 534 public Boolean getCanLike() { 535 return this.canLike; 536 } 537 538 /** 539 * Whether the viewer can like this comment 540 */ 541 @java.lang.SuppressWarnings("all") 542 public void setCanLike(final Boolean canLike) { 543 this.canLike = canLike; 544 } 545 546 /** 547 * Parent object this comment was made on. 548 * 549 * @return object 550 * @since 1.7.1 551 */ 552 @java.lang.SuppressWarnings("all") 553 public NamedFacebookType getObject() { 554 return this.object; 555 } 556 557 /** 558 * Parent object this comment was made on. 559 * 560 * @since 1.7.1 561 */ 562 @java.lang.SuppressWarnings("all") 563 public void setObject(final NamedFacebookType object) { 564 this.object = object; 565 } 566 567 /** 568 * The permanent static URL to the comment 569 * 570 * @return permanent static url 571 */ 572 @java.lang.SuppressWarnings("all") 573 public String getPermalinkUrl() { 574 return this.permalinkUrl; 575 } 576 577 /** 578 * The permanent static URL to the comment 579 */ 580 @java.lang.SuppressWarnings("all") 581 public void setPermalinkUrl(final String permalinkUrl) { 582 this.permalinkUrl = permalinkUrl; 583 } 584 585 /** 586 * The replies to this comment 587 * 588 * @return replies 589 */ 590 @Override 591 @java.lang.SuppressWarnings("all") 592 public Comments getComments() { 593 return this.comments; 594 } 595 596 /** 597 * The replies to this comment 598 */ 599 @java.lang.SuppressWarnings("all") 600 public void setComments(final Comments comments) { 601 this.comments = comments; 602 } 603 604 /** 605 * Attachment (image) added to a comment. 606 * <p> 607 * To force Facebook to fill the <code>attachment</code> field you have to fetch the comment with the 608 * <code>fields=attachment</code> parameter, otherwise the attachments are <code>null</code>. 609 * 610 * @return Attachment on the comment 611 */ 612 @java.lang.SuppressWarnings("all") 613 public StoryAttachment getAttachment() { 614 return this.attachment; 615 } 616 617 /** 618 * Attachment (image) added to a comment. 619 * <p> 620 * To force Facebook to fill the <code>attachment</code> field you have to fetch the comment with the 621 * <code>fields=attachment</code> parameter, otherwise the attachments are <code>null</code>. 622 */ 623 @java.lang.SuppressWarnings("all") 624 public void setAttachment(final StoryAttachment attachment) { 625 this.attachment = attachment; 626 } 627}