All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.whispersystems.signalservice.api.messages.SignalServiceStickerManifestUpload Maven / Gradle / Ivy

There is a newer version: 2.15.3_unofficial_107
Show newest version
package org.whispersystems.signalservice.api.messages;


import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;

public class SignalServiceStickerManifestUpload {

  private final Optional      title;
  private final Optional      author;
  private final Optional cover;
  private final List     stickers;

  public SignalServiceStickerManifestUpload(String title, String author, StickerInfo cover, List stickers) {
    this.title    = Optional.ofNullable(title);
    this.author   = Optional.ofNullable(author);
    this.cover    = Optional.ofNullable(cover);
    this.stickers = (stickers == null) ? Collections.emptyList() : new ArrayList<>(stickers);
  }

  public Optional getTitle() {
    return title;
  }

  public Optional getAuthor() {
    return author;
  }

  public Optional getCover() {
    return cover;
  }

  public List getStickers() {
    return stickers;
  }

  public SignalServiceStickerManifest toManifest() {
    List stickers = new ArrayList<>();

    int i = 0;
    for (StickerInfo sticker : this.stickers) {
      stickers.add(new SignalServiceStickerManifest.StickerInfo(i, sticker.emoji, sticker.contentType));
      i++;
    }

    SignalServiceStickerManifest.StickerInfo cover = this.cover.isPresent()
                                                     ? new SignalServiceStickerManifest.StickerInfo(stickers.size(), this.cover.get().emoji, this.cover.get().contentType)
                                                     : stickers.get(0);

    return new SignalServiceStickerManifest(title.orElse(null), author.orElse(null), cover, stickers);
  }

  public static final class StickerInfo {
    private final InputStream inputStream;
    private final long        length;
    private final String      emoji;
    private final String      contentType;

    public StickerInfo(InputStream inputStream, long length, String emoji, String contentType) {
      this.inputStream = inputStream;
      this.length      = length;
      this.emoji       = emoji;
      this.contentType = contentType;
    }

    public InputStream getInputStream() {
      return inputStream;
    }

    public long getLength() {
      return length;
    }

    public String getEmoji() {
      return emoji;
    }

    public String getContentType() {
      return contentType;
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy