From c8bb581599d5c4318b4a2ed40f929c7152a5d17d Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Mon, 27 Nov 2023 14:21:50 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20=D1=81=20=D1=84=D0=B0?= =?UTF-8?q?=D0=B9=D0=BB=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/context/convert/MessageChatMailConvert.java | 3 +-- .../main/context/convert/MessageMailConvert.java | 7 ++++--- .../quarkus/context/service/AttachmentService.java | 3 --- .../telegram/main/core/util/Attachments.java | 2 +- .../quarkus/core/service/AttachmentServiceImpl.java | 11 ----------- .../godfather/telegram/domain/attachment/Picture.java | 9 +++++---- .../domain/attachment/PictureGroupAttachment.java | 4 ++-- .../domain/attachment/TelegramAttachmentType.java | 1 + .../telegram/domain/attachment/VideoAttachment.java | 7 +------ .../domain/deser/TelegramAttachmentDeserializer.java | 3 ++- 10 files changed, 17 insertions(+), 33 deletions(-) diff --git a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java index dd5fdc3..ea456eb 100644 --- a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java +++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageChatMailConvert.java @@ -79,11 +79,10 @@ public final class MessageChatMailConvert { final List pictures = photoSizes.stream() .map(photoSize -> { final Picture picture = new Picture(); - picture.setFileSize(photoSize.getFileSize()); + picture.setFileSize(photoSize.getFileSize().longValue()); picture.setFileId(photoSize.getFileId()); picture.setHeight(photoSize.getHeight()); picture.setWeight(photoSize.getWidth()); - picture.setFileUniqueId(photoSize.getFileUniqueId()); return picture; }).toList(); diff --git a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java index 1760c86..737c061 100644 --- a/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java +++ b/telegram-context/telegram-context-main/src/main/java/dev/struchkov/godfather/telegram/main/context/convert/MessageMailConvert.java @@ -74,6 +74,7 @@ public final class MessageMailConvert { convertPhoto(message.getPhoto()).ifPresent(mail::addAttachment); convertVideo(message.getVideo()).ifPresent(mail::addAttachment); convertVoice(message.getVoice()).ifPresent(mail::addAttachment); + convertSticker(message.getSticker()).ifPresent(mail::addAttachment); final List entities = message.getEntities(); if (entities != null) { @@ -104,11 +105,10 @@ public final class MessageMailConvert { final List pictures = photoSizes.stream() .map(photoSize -> { final Picture picture = new Picture(); - picture.setFileSize(photoSize.getFileSize()); + picture.setFileSize(photoSize.getFileSize().longValue()); picture.setFileId(photoSize.getFileId()); picture.setHeight(photoSize.getHeight()); picture.setWeight(photoSize.getWidth()); - picture.setFileUniqueId(photoSize.getFileUniqueId()); return picture; }).toList(); @@ -162,7 +162,7 @@ public final class MessageMailConvert { return Optional.empty(); } - private static Optional convertVoice(Sticker sticker) { + private static Optional convertSticker(Sticker sticker) { if (sticker != null) { final StickerAttachment attachment = new StickerAttachment(); attachment.setFileId(sticker.getFileId()); @@ -181,6 +181,7 @@ public final class MessageMailConvert { attachment.setFileId(video.getFileId()); attachment.setFileSize(video.getFileSize()); attachment.setFileName(video.getFileName()); + attachment.setMimeType(video.getMimeType()); return Optional.of(attachment); } return Optional.empty(); diff --git a/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/AttachmentService.java b/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/AttachmentService.java index 768701c..99e9125 100644 --- a/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/AttachmentService.java +++ b/telegram-context/telegram-context-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/context/service/AttachmentService.java @@ -1,7 +1,6 @@ package dev.struchkov.godfather.telegram.quarkus.context.service; import dev.struchkov.godfather.telegram.domain.attachment.FileAttachment; -import dev.struchkov.godfather.telegram.domain.attachment.Picture; import dev.struchkov.godfather.telegram.domain.files.ByteContainer; import dev.struchkov.godfather.telegram.domain.files.FileContainer; import io.smallrye.mutiny.Uni; @@ -13,6 +12,4 @@ public interface AttachmentService { Uni uploadBytes(@NotNull FileAttachment fileAttachment); - Uni uploadBytes(@NotNull Picture picture); - } diff --git a/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/util/Attachments.java b/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/util/Attachments.java index 4394af4..c6a808d 100644 --- a/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/util/Attachments.java +++ b/telegram-core/telegram-core-main/src/main/java/dev/struchkov/godfather/telegram/main/core/util/Attachments.java @@ -176,7 +176,7 @@ public final class Attachments { public static boolean isPictureGroup(Attachment attachment) { isNotNull(attachment); - return TelegramAttachmentType.PICTURE.name().equals(attachment.getType()); + return TelegramAttachmentType.PICTURE_GROUP.name().equals(attachment.getType()); } public static boolean isLink(Attachment attachment) { diff --git a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/AttachmentServiceImpl.java b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/AttachmentServiceImpl.java index 7631f04..4f9a200 100644 --- a/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/AttachmentServiceImpl.java +++ b/telegram-core/telegram-core-quarkus/src/main/java/dev/struchkov/godfather/telegram/quarkus/core/service/AttachmentServiceImpl.java @@ -77,17 +77,6 @@ public class AttachmentServiceImpl implements AttachmentService { .onItem().ifNotNull().transform(bytes -> new ByteContainer(fileAttachment.getFileName(), fileAttachment.getMimeType(), bytes)); } - @Override - public Uni uploadBytes(@NotNull Picture picture) { - isNotNull(picture); - return downloadBytes(picture) - .onItem().ifNotNull().transform(bytes -> new ByteContainer(null, "image/jpeg", bytes)); - } - - private Uni downloadBytes(Picture picture) { - return telegramDownloadBytes(picture.getFileId()); - } - private Uni downloadBytes(FileAttachment documentAttachment) { return telegramDownloadBytes(documentAttachment.getFileId()); } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/Picture.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/Picture.java index c27e66c..d5d5d30 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/Picture.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/Picture.java @@ -5,12 +5,13 @@ import lombok.Setter; @Getter @Setter -public class Picture { +public class Picture extends FileAttachment { - private String fileId; - private String fileUniqueId; - private Integer fileSize; private Integer weight; private Integer height; + public Picture() { + super(TelegramAttachmentType.PICTURE.name()); + } + } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/PictureGroupAttachment.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/PictureGroupAttachment.java index 5b205ad..b0de1f5 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/PictureGroupAttachment.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/PictureGroupAttachment.java @@ -15,12 +15,12 @@ public class PictureGroupAttachment extends Attachment { private List pictures; public PictureGroupAttachment() { - super(TelegramAttachmentType.PICTURE.name()); + super(TelegramAttachmentType.PICTURE_GROUP.name()); } public Optional getLargePicture() { return pictures.stream() - .max(Comparator.comparingInt(Picture::getFileSize)); + .max(Comparator.comparing(Picture::getFileSize)); } } diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/TelegramAttachmentType.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/TelegramAttachmentType.java index be038af..1c53b96 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/TelegramAttachmentType.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/TelegramAttachmentType.java @@ -4,6 +4,7 @@ public enum TelegramAttachmentType { DOCUMENT, CONTACT, + PICTURE_GROUP, PICTURE, LINK, COMMAND, diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/VideoAttachment.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/VideoAttachment.java index 477f656..a80693c 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/VideoAttachment.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/attachment/VideoAttachment.java @@ -1,16 +1,11 @@ package dev.struchkov.godfather.telegram.domain.attachment; -import dev.struchkov.godfather.main.domain.content.Attachment; import lombok.Getter; import lombok.Setter; @Getter @Setter -public class VideoAttachment extends Attachment { - - private String fileId; - private Long fileSize; - private String fileName; +public class VideoAttachment extends FileAttachment { public VideoAttachment() { super(TelegramAttachmentType.VIDEO.name()); diff --git a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/deser/TelegramAttachmentDeserializer.java b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/deser/TelegramAttachmentDeserializer.java index 1f63df9..37099f5 100644 --- a/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/deser/TelegramAttachmentDeserializer.java +++ b/telegram-domain/telegram-domain-main/src/main/java/dev/struchkov/godfather/telegram/domain/deser/TelegramAttachmentDeserializer.java @@ -39,12 +39,13 @@ public class TelegramAttachmentDeserializer extends StdDeserializer case BUTTON_CLICK -> parser.getCodec().treeToValue(node, ButtonClickAttachment.class); case DOCUMENT -> parser.getCodec().treeToValue(node, DocumentAttachment.class); case CONTACT -> parser.getCodec().treeToValue(node, ContactAttachment.class); - case PICTURE -> parser.getCodec().treeToValue(node, PictureGroupAttachment.class); + case PICTURE_GROUP -> parser.getCodec().treeToValue(node, PictureGroupAttachment.class); case LINK -> parser.getCodec().treeToValue(node, LinkAttachment.class); case COMMAND -> parser.getCodec().treeToValue(node, CommandAttachment.class); case VIDEO -> parser.getCodec().treeToValue(node, VideoAttachment.class); case VOICE -> parser.getCodec().treeToValue(node, VoiceAttachment.class); case STICKER -> parser.getCodec().treeToValue(node, StickerAttachment.class); + case PICTURE -> null; }; }