+
+ private HashMap<String, Variant<?>> getMessageExtras(MessageEnvelope.Data message) {
+ var extras = new HashMap<String, Variant<?>>();
+ if (message.attachments().size() > 0) {
+ var attachments = message.attachments()
+ .stream()
+ .filter(a -> a.id().isPresent())
+ .map(a -> getAttachmentMap(m, a))
+ .collect(Collectors.toList());
+ extras.put("attachments", new Variant<>(attachments, "aa{sv}"));
+ }
+ if (message.mentions().size() > 0) {
+ var mentions = message.mentions().stream().map(this::getMentionMap).collect(Collectors.toList());
+ extras.put("mentions", new Variant<>(mentions, "aa{sv}"));
+ }
+ extras.put("expiresInSeconds", new Variant<>(message.expiresInSeconds()));
+ if (message.quote().isPresent()) {
+ extras.put("quote", new Variant<>(getQuoteMap(message.quote().get()), "a{sv}"));
+ }
+ if (message.reaction().isPresent()) {
+ final var reaction = message.reaction().get();
+ extras.put("reaction", new Variant<>(getReactionMap(reaction), "a{sv}"));
+ }
+ if (message.remoteDeleteId().isPresent()) {
+ extras.put("remoteDelete",
+ new Variant<>(Map.of("timestamp", new Variant<>(message.remoteDeleteId().get())), "a{sv}"));
+ }
+ if (message.sticker().isPresent()) {
+ final var sticker = message.sticker().get();
+ extras.put("sticker", new Variant<>(getStickerMap(sticker), "a{sv}"));
+ }
+ extras.put("isViewOnce", new Variant<>(message.isViewOnce()));
+ return extras;
+ }
+
+ private Map<String, Variant<?>> getQuoteMap(final MessageEnvelope.Data.Quote quote) {
+ return Map.of("id",
+ new Variant<>(quote.id()),
+ "author",
+ new Variant<>(quote.author().getLegacyIdentifier()),
+ "text",
+ new Variant<>(quote.text().orElse("")));
+ }
+
+ private Map<String, Variant<? extends Serializable>> getStickerMap(final MessageEnvelope.Data.Sticker sticker) {
+ return Map.of("packId", new Variant<>(sticker.packId()), "stickerId", new Variant<>(sticker.stickerId()));
+ }
+
+ private Map<String, Variant<?>> getReactionMap(final MessageEnvelope.Data.Reaction reaction) {
+ return Map.of("emoji",
+ new Variant<>(reaction.emoji()),
+ "targetAuthor",
+ new Variant<>(reaction.targetAuthor().getLegacyIdentifier()),
+ "targetSentTimestamp",
+ new Variant<>(reaction.targetSentTimestamp()),
+ "isRemove",
+ new Variant<>(reaction.isRemove()));
+ }
+
+ private Map<String, Variant<?>> getAttachmentMap(
+ final Manager m, final MessageEnvelope.Data.Attachment a
+ ) {
+ final var map = new HashMap<String, Variant<?>>();
+ if (a.id().isPresent()) {
+ map.put("remoteId", new Variant<>(a.id().get()));
+ }
+ if (a.file().isPresent()) {
+ map.put("file", new Variant<>(a.file().get().getAbsolutePath()));
+ }
+ map.put("contentType", new Variant<>(a.contentType()));
+ map.put("isVoiceNote", new Variant<>(a.isVoiceNote()));
+ map.put("isBorderless", new Variant<>(a.isBorderless()));
+ map.put("isGif", new Variant<>(a.isGif()));
+ if (a.caption().isPresent()) {
+ map.put("caption", new Variant<>(a.caption().get()));
+ }
+ if (a.fileName().isPresent()) {
+ map.put("fileName", new Variant<>(a.fileName().get()));
+ }
+ if (a.size().isPresent()) {
+ map.put("size", new Variant<>(a.size().get()));
+ }
+ if (a.width().isPresent()) {
+ map.put("width", new Variant<>(a.width().get()));
+ }
+ if (a.height().isPresent()) {
+ map.put("height", new Variant<>(a.height().get()));
+ }
+ return map;
+ }
+
+ private Map<String, Variant<?>> getMentionMap(
+ final MessageEnvelope.Data.Mention mention
+ ) {
+ return Map.of("recipient",
+ new Variant<>(mention.recipient().getLegacyIdentifier()),
+ "start",
+ new Variant<>(mention.start()),
+ "length",
+ new Variant<>(mention.length()));
+ }