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