001// Generated by delombok at Sun Jul 07 22:01:31 CEST 2019
002/**
003 * Copyright (c) 2010-2019 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.JsonMappingCompleted;
031import com.restfb.json.Json;
032import com.restfb.json.JsonValue;
033
034/**
035 * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/message/">Message Graph API type</a>
036 * .
037 *
038 * @author <a href="http://restfb.com">Mark Allen</a>
039 * @author Felipe Kurkowski
040 * @author alockhart
041 */
042public class Message extends FacebookType {
043  /**
044   * The time the message was initially created.
045   */
046  @Facebook("created_time")
047  private Date createdTime;
048  /**
049   * The subject of the message.
050   */
051  @Facebook
052  private String subject;
053  /**
054   * The sender of this message
055   */
056  @Facebook
057  private NamedFacebookType from;
058  @Facebook
059  private List<NamedFacebookType> to = new ArrayList<>();
060  /**
061   * The text of the message
062   */
063  @Facebook
064  private String message;
065  /**
066   * Sticker contained in the message.
067   */
068  @Facebook
069  private String sticker;
070  @Facebook
071  private List<Attachment> attachments = new ArrayList<>();
072  @Facebook
073  private List<Share> shares = new ArrayList<>();
074  /**
075   * The time of the last update to this message.
076   */
077  @Facebook("updated_time")
078  private Date updatedTime;
079  /**
080   * The "unread" count for this message.
081   */
082  @Facebook
083  private Integer unread;
084  /**
085   * Whether this message has been seen.
086   */
087  @Facebook
088  private Boolean unseen;
089  @Facebook("tags")
090  private transient String rawTags;
091  private List<String> tags = new ArrayList<>();
092  private static final long serialVersionUID = 1L;
093
094
095  /**
096   * Represents an attached file that you may find on a private message.
097   *
098   * @author alockhart
099   * @since 1.6.12
100   */
101  public static class Attachment extends FacebookType {
102    private static final long serialVersionUID = 1L;
103    /**
104     * The attachment's filename, for example 121423423.jpg.
105     */
106    @Facebook
107    private String name;
108    /**
109     * The attachment's mime type, for example image/jpeg.
110     */
111    @Facebook("mime_type")
112    private String mimeType;
113    /**
114     * The size of the attachment in bytes.
115     */
116    @Facebook
117    private Long size;
118    @Facebook("file_url")
119    private String fileUrl;
120    /**
121     * When the attached file is an image, Facebook will also send information about it's width, height and url.
122     */
123    @Facebook("image_data")
124    private ImageData imageData;
125    /**
126     * When the attached file is a video, Facebook will also send information about it's width, height and url.
127     */
128    @Facebook("video_data")
129    private VideoData videoData;
130
131    /**
132     * returns if the attachment is a image
133     * 
134     * @return true if the attachment is a image, false otherwise
135     */
136    public boolean isImage() {
137      return null != imageData && null == videoData;
138    }
139
140    /**
141     * returns if the attachment is a video
142     * 
143     * @return true if the attachment is a video, false otherwise
144     */
145    public boolean isVideo() {
146      return null != videoData;
147    }
148
149    /**
150     * The attachment's filename, for example 121423423.jpg.
151     *
152     * @return The attachment's filename.
153     */
154    @java.lang.SuppressWarnings("all")
155    public String getName() {
156      return this.name;
157    }
158
159    /**
160     * The attachment's filename, for example 121423423.jpg.
161     */
162    @java.lang.SuppressWarnings("all")
163    public void setName(final String name) {
164      this.name = name;
165    }
166
167    /**
168     * The attachment's mime type, for example image/jpeg.
169     *
170     * @return The attachment's mime type.
171     */
172    @java.lang.SuppressWarnings("all")
173    public String getMimeType() {
174      return this.mimeType;
175    }
176
177    /**
178     * The attachment's mime type, for example image/jpeg.
179     */
180    @java.lang.SuppressWarnings("all")
181    public void setMimeType(final String mimeType) {
182      this.mimeType = mimeType;
183    }
184
185    /**
186     * The size of the attachment in bytes.
187     *
188     * @return The size of the attachment in bytes.
189     */
190    @java.lang.SuppressWarnings("all")
191    public Long getSize() {
192      return this.size;
193    }
194
195    /**
196     * The size of the attachment in bytes.
197     */
198    @java.lang.SuppressWarnings("all")
199    public void setSize(final Long size) {
200      this.size = size;
201    }
202
203    @java.lang.SuppressWarnings("all")
204    public String getFileUrl() {
205      return this.fileUrl;
206    }
207
208    @java.lang.SuppressWarnings("all")
209    public void setFileUrl(final String fileUrl) {
210      this.fileUrl = fileUrl;
211    }
212
213    /**
214     * When the attached file is an image, Facebook will also send information about it's width, height and url.
215     *
216     * @return The attachment's image data.
217     */
218    @java.lang.SuppressWarnings("all")
219    public ImageData getImageData() {
220      return this.imageData;
221    }
222
223    /**
224     * When the attached file is an image, Facebook will also send information about it's width, height and url.
225     */
226    @java.lang.SuppressWarnings("all")
227    public void setImageData(final ImageData imageData) {
228      this.imageData = imageData;
229    }
230
231    /**
232     * When the attached file is a video, Facebook will also send information about it's width, height and url.
233     *
234     * @return The attachment's video data.
235     */
236    @java.lang.SuppressWarnings("all")
237    public VideoData getVideoData() {
238      return this.videoData;
239    }
240
241    /**
242     * When the attached file is a video, Facebook will also send information about it's width, height and url.
243     */
244    @java.lang.SuppressWarnings("all")
245    public void setVideoData(final VideoData videoData) {
246      this.videoData = videoData;
247    }
248  }
249
250
251  /**
252   * Represents the <a href="https://developers.facebook.com/docs/graph-api/reference/message/shares/">Message Share
253   * Graph API type</a>.
254   */
255  public static class Share extends NamedFacebookType {
256    /**
257     * The URL to the shared item.
258     */
259    @Facebook
260    private String link;
261    /**
262     * The description of the shared item.
263     */
264    @Facebook
265    private String description;
266    @Facebook
267    private String picture;
268
269    /**
270     * The URL to the shared item.
271     *
272     * @return The URL to the shared item.
273     */
274    @java.lang.SuppressWarnings("all")
275    public String getLink() {
276      return this.link;
277    }
278
279    /**
280     * The URL to the shared item.
281     */
282    @java.lang.SuppressWarnings("all")
283    public void setLink(final String link) {
284      this.link = link;
285    }
286
287    /**
288     * The description of the shared item.
289     *
290     * @return The description of the shared item.
291     */
292    @java.lang.SuppressWarnings("all")
293    public String getDescription() {
294      return this.description;
295    }
296
297    /**
298     * The description of the shared item.
299     */
300    @java.lang.SuppressWarnings("all")
301    public void setDescription(final String description) {
302      this.description = description;
303    }
304
305    @java.lang.SuppressWarnings("all")
306    public String getPicture() {
307      return this.picture;
308    }
309
310    @java.lang.SuppressWarnings("all")
311    public void setPicture(final String picture) {
312      this.picture = picture;
313    }
314  }
315
316
317  /**
318   * Additional attachment information, only present when an attached file is an image.
319   *
320   * @author Felipe Kurkowski
321   */
322  public static class ImageData extends AttachmentData {
323    private static final long serialVersionUID = 1L;
324    /**
325     * The image's max width.
326     */
327    @Facebook("max_width")
328    private int maxWidth;
329    /**
330     * The image's max height.
331     */
332    @Facebook("max_height")
333    private int maxHeight;
334    @Facebook("render_as_sticker")
335    private Boolean renderAsSticker;
336    @Facebook("image_type")
337    private int imageType;
338    @Facebook("raw_gif_image")
339    private String rawGifImage;
340    @Facebook("raw_webp_image")
341    private String rawWebpImage;
342    @Facebook("animated_gif_url")
343    private String animatedGifUrl;
344    @Facebook("animated_gif_preview_url")
345    private String animatedGifPreviewUrl;
346    @Facebook("animated_webp_url")
347    private String animatedWebpUrl;
348    @Facebook("animated_webp_preview_url")
349    private String animatedWebpPreviewUrl;
350
351    /**
352     * The image's max width.
353     *
354     * @return The image's max width.
355     */
356    @java.lang.SuppressWarnings("all")
357    public int getMaxWidth() {
358      return this.maxWidth;
359    }
360
361    /**
362     * The image's max width.
363     */
364    @java.lang.SuppressWarnings("all")
365    public void setMaxWidth(final int maxWidth) {
366      this.maxWidth = maxWidth;
367    }
368
369    /**
370     * The image's max height.
371     *
372     * @return The image's max height.
373     */
374    @java.lang.SuppressWarnings("all")
375    public int getMaxHeight() {
376      return this.maxHeight;
377    }
378
379    /**
380     * The image's max height.
381     */
382    @java.lang.SuppressWarnings("all")
383    public void setMaxHeight(final int maxHeight) {
384      this.maxHeight = maxHeight;
385    }
386
387    @java.lang.SuppressWarnings("all")
388    public Boolean getRenderAsSticker() {
389      return this.renderAsSticker;
390    }
391
392    @java.lang.SuppressWarnings("all")
393    public void setRenderAsSticker(final Boolean renderAsSticker) {
394      this.renderAsSticker = renderAsSticker;
395    }
396
397    @java.lang.SuppressWarnings("all")
398    public int getImageType() {
399      return this.imageType;
400    }
401
402    @java.lang.SuppressWarnings("all")
403    public void setImageType(final int imageType) {
404      this.imageType = imageType;
405    }
406
407    @java.lang.SuppressWarnings("all")
408    public String getRawGifImage() {
409      return this.rawGifImage;
410    }
411
412    @java.lang.SuppressWarnings("all")
413    public void setRawGifImage(final String rawGifImage) {
414      this.rawGifImage = rawGifImage;
415    }
416
417    @java.lang.SuppressWarnings("all")
418    public String getRawWebpImage() {
419      return this.rawWebpImage;
420    }
421
422    @java.lang.SuppressWarnings("all")
423    public void setRawWebpImage(final String rawWebpImage) {
424      this.rawWebpImage = rawWebpImage;
425    }
426
427    @java.lang.SuppressWarnings("all")
428    public String getAnimatedGifUrl() {
429      return this.animatedGifUrl;
430    }
431
432    @java.lang.SuppressWarnings("all")
433    public void setAnimatedGifUrl(final String animatedGifUrl) {
434      this.animatedGifUrl = animatedGifUrl;
435    }
436
437    @java.lang.SuppressWarnings("all")
438    public String getAnimatedGifPreviewUrl() {
439      return this.animatedGifPreviewUrl;
440    }
441
442    @java.lang.SuppressWarnings("all")
443    public void setAnimatedGifPreviewUrl(final String animatedGifPreviewUrl) {
444      this.animatedGifPreviewUrl = animatedGifPreviewUrl;
445    }
446
447    @java.lang.SuppressWarnings("all")
448    public String getAnimatedWebpUrl() {
449      return this.animatedWebpUrl;
450    }
451
452    @java.lang.SuppressWarnings("all")
453    public void setAnimatedWebpUrl(final String animatedWebpUrl) {
454      this.animatedWebpUrl = animatedWebpUrl;
455    }
456
457    @java.lang.SuppressWarnings("all")
458    public String getAnimatedWebpPreviewUrl() {
459      return this.animatedWebpPreviewUrl;
460    }
461
462    @java.lang.SuppressWarnings("all")
463    public void setAnimatedWebpPreviewUrl(final String animatedWebpPreviewUrl) {
464      this.animatedWebpPreviewUrl = animatedWebpPreviewUrl;
465    }
466  }
467
468
469  /**
470   * Additional attachment information, only present when an attached file is an video.
471   */
472  public static class VideoData extends AttachmentData {
473    private static final long serialVersionUID = 1L;
474    @Facebook
475    private int length;
476    @Facebook("video_type")
477    private int videoType;
478    @Facebook
479    private int rotation;
480
481    @java.lang.SuppressWarnings("all")
482    public int getLength() {
483      return this.length;
484    }
485
486    @java.lang.SuppressWarnings("all")
487    public void setLength(final int length) {
488      this.length = length;
489    }
490
491    @java.lang.SuppressWarnings("all")
492    public int getVideoType() {
493      return this.videoType;
494    }
495
496    @java.lang.SuppressWarnings("all")
497    public void setVideoType(final int videoType) {
498      this.videoType = videoType;
499    }
500
501    @java.lang.SuppressWarnings("all")
502    public int getRotation() {
503      return this.rotation;
504    }
505
506    @java.lang.SuppressWarnings("all")
507    public void setRotation(final int rotation) {
508      this.rotation = rotation;
509    }
510  }
511
512
513  public static abstract class AttachmentData extends AbstractFacebookType {
514    private static final long serialVersionUID = 1L;
515    /**
516     * The image's width.
517     */
518    @Facebook
519    private int width;
520    /**
521     * The image's height.
522     */
523    @Facebook
524    private int height;
525    /**
526     * The image's url.
527     */
528    @Facebook
529    private String url;
530    /**
531     * The image's preview url.
532     */
533    @Facebook("preview_url")
534    private String previewUrl;
535
536    /**
537     * The image's width.
538     *
539     * @return The image's width.
540     */
541    @java.lang.SuppressWarnings("all")
542    public int getWidth() {
543      return this.width;
544    }
545
546    /**
547     * The image's width.
548     */
549    @java.lang.SuppressWarnings("all")
550    public void setWidth(final int width) {
551      this.width = width;
552    }
553
554    /**
555     * The image's height.
556     *
557     * @return The image's height.
558     */
559    @java.lang.SuppressWarnings("all")
560    public int getHeight() {
561      return this.height;
562    }
563
564    /**
565     * The image's height.
566     */
567    @java.lang.SuppressWarnings("all")
568    public void setHeight(final int height) {
569      this.height = height;
570    }
571
572    /**
573     * The image's url.
574     *
575     * @return The image's url.
576     */
577    @java.lang.SuppressWarnings("all")
578    public String getUrl() {
579      return this.url;
580    }
581
582    /**
583     * The image's url.
584     */
585    @java.lang.SuppressWarnings("all")
586    public void setUrl(final String url) {
587      this.url = url;
588    }
589
590    /**
591     * The image's preview url.
592     *
593     * @return The image's preview url.
594     */
595    @java.lang.SuppressWarnings("all")
596    public String getPreviewUrl() {
597      return this.previewUrl;
598    }
599
600    /**
601     * The image's preview url.
602     */
603    @java.lang.SuppressWarnings("all")
604    public void setPreviewUrl(final String previewUrl) {
605      this.previewUrl = previewUrl;
606    }
607  }
608
609  @JsonMappingCompleted
610  void convertTags() {
611    if (rawTags != null) {
612      JsonValue parsedObject = Json.parse(rawTags);
613      if (parsedObject.isObject() && parsedObject.asObject().get("data").isArray()) {
614        for (JsonValue tagObject : parsedObject.asObject().get("data").asArray()) {
615          tags.add(tagObject.asObject().get("name").asString());
616        }
617      }
618    }
619  }
620
621  /**
622   * The attachments associated with the message.
623   *
624   * @return The attachments associated with the message.
625   */
626  public List<Attachment> getAttachments() {
627    return (attachments != null ? unmodifiableList(attachments) : null);
628  }
629
630  public boolean addAttachment(Attachment attachment) {
631    return attachments.add(attachment);
632  }
633
634  public boolean removeAttachment(Attachment attachment) {
635    return attachments.remove(attachment);
636  }
637
638  /**
639   * The shares associated with the message.
640   *
641   * This is page only.
642   *
643   * @return The shares associated with the message.
644   */
645  public List<Share> getShares() {
646    return (shares != null ? unmodifiableList(shares) : null);
647  }
648
649  public boolean addShare(Share share) {
650    return shares.add(share);
651  }
652
653  public boolean removeShare(Share share) {
654    return shares.remove(share);
655  }
656
657  /**
658   * A list of recipients of the message.
659   *
660   * @return A list of the message recipients
661   */
662  public List<NamedFacebookType> getTo() {
663    return unmodifiableList(to);
664  }
665
666  public boolean addTo(NamedFacebookType receiver) {
667    return to.add(receiver);
668  }
669
670  public boolean removeTo(NamedFacebookType receiver) {
671    return to.remove(receiver);
672  }
673
674  /**
675   * A set of tags indicating the message folder and source of the message.
676   *
677   * @return A set of tags indicating the message folder and source of the message.
678   */
679  public List<String> getTags() {
680    return unmodifiableList(tags);
681  }
682
683  public boolean addTag(String tag) {
684    return tags.add(tag);
685  }
686
687  public boolean removeTag(String tag) {
688    return tags.remove(tag);
689  }
690
691  /**
692   * The time the message was initially created.
693   *
694   * @return The time the message was initially created.
695   */
696  @java.lang.SuppressWarnings("all")
697  public Date getCreatedTime() {
698    return this.createdTime;
699  }
700
701  /**
702   * The time the message was initially created.
703   */
704  @java.lang.SuppressWarnings("all")
705  public void setCreatedTime(final Date createdTime) {
706    this.createdTime = createdTime;
707  }
708
709  /**
710   * The subject of the message.
711   *
712   * @return The subject of the message.
713   */
714  @java.lang.SuppressWarnings("all")
715  public String getSubject() {
716    return this.subject;
717  }
718
719  /**
720   * The subject of the message.
721   */
722  @java.lang.SuppressWarnings("all")
723  public void setSubject(final String subject) {
724    this.subject = subject;
725  }
726
727  /**
728   * The sender of this message
729   *
730   * @return The sender of this message
731   */
732  @java.lang.SuppressWarnings("all")
733  public NamedFacebookType getFrom() {
734    return this.from;
735  }
736
737  /**
738   * The sender of this message
739   */
740  @java.lang.SuppressWarnings("all")
741  public void setFrom(final NamedFacebookType from) {
742    this.from = from;
743  }
744
745  /**
746   * The text of the message
747   *
748   * @return The text of the message
749   */
750  @java.lang.SuppressWarnings("all")
751  public String getMessage() {
752    return this.message;
753  }
754
755  /**
756   * The text of the message
757   */
758  @java.lang.SuppressWarnings("all")
759  public void setMessage(final String message) {
760    this.message = message;
761  }
762
763  /**
764   * Sticker contained in the message.
765   *
766   * @return The Sticker in that message
767   */
768  @java.lang.SuppressWarnings("all")
769  public String getSticker() {
770    return this.sticker;
771  }
772
773  /**
774   * Sticker contained in the message.
775   */
776  @java.lang.SuppressWarnings("all")
777  public void setSticker(final String sticker) {
778    this.sticker = sticker;
779  }
780
781  /**
782   * The time of the last update to this message.
783   *
784   * @return The time of the last update to this message.
785   */
786  @java.lang.SuppressWarnings("all")
787  public Date getUpdatedTime() {
788    return this.updatedTime;
789  }
790
791  /**
792   * The time of the last update to this message.
793   */
794  @java.lang.SuppressWarnings("all")
795  public void setUpdatedTime(final Date updatedTime) {
796    this.updatedTime = updatedTime;
797  }
798
799  /**
800   * The "unread" count for this message.
801   *
802   * @return The "unread" count for this message.
803   */
804  @java.lang.SuppressWarnings("all")
805  public Integer getUnread() {
806    return this.unread;
807  }
808
809  /**
810   * The "unread" count for this message.
811   */
812  @java.lang.SuppressWarnings("all")
813  public void setUnread(final Integer unread) {
814    this.unread = unread;
815  }
816
817  /**
818   * Whether this message has been seen.
819   *
820   * @return Whether this message has been seen.
821   */
822  @java.lang.SuppressWarnings("all")
823  public Boolean getUnseen() {
824    return this.unseen;
825  }
826
827  /**
828   * Whether this message has been seen.
829   */
830  @java.lang.SuppressWarnings("all")
831  public void setUnseen(final Boolean unseen) {
832    this.unseen = unseen;
833  }
834}