From 37bca936bf8e9217a093bc7f4d885c679df7e3a1 Mon Sep 17 00:00:00 2001 From: Stas Parshin <2172170+pengrad@users.noreply.github.com> Date: Sun, 7 Apr 2024 11:22:53 +0700 Subject: [PATCH] Remove deprecated methods of AddStickerToSet, CreateNewStickerSet, UploadStickerFile --- .../pengrad/telegrambot/model/StickerSet.java | 21 ++---- .../model/request/InputSticker.java | 4 +- .../telegrambot/request/AddStickerToSet.java | 47 +----------- .../request/CreateNewStickerSet.java | 73 +------------------ .../request/UploadStickerFile.java | 9 --- .../pengrad/telegrambot/TelegramBotTest.java | 50 ++++++------- .../telegrambot/checks/MessageTest.java | 2 +- 7 files changed, 36 insertions(+), 170 deletions(-) diff --git a/library/src/main/java/com/pengrad/telegrambot/model/StickerSet.java b/library/src/main/java/com/pengrad/telegrambot/model/StickerSet.java index c1a9378b..8148fc4e 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/StickerSet.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/StickerSet.java @@ -16,8 +16,6 @@ public class StickerSet implements Serializable { private String name; private String title; private Type sticker_type; - private Boolean is_animated; - private Boolean is_video; private Boolean contains_masks; private Sticker[] stickers; private PhotoSize thumbnail; @@ -40,7 +38,7 @@ public Type stickerType() { */ @Deprecated public Boolean isAnimated() { - return is_animated; + return false; } /** @@ -72,7 +70,7 @@ public PhotoSize thumb() { */ @Deprecated public Boolean isVideo() { - return is_video; + return false; } @Override @@ -80,19 +78,12 @@ public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; StickerSet that = (StickerSet) o; - return Objects.equals(name, that.name) && - Objects.equals(title, that.title) && - Objects.equals(sticker_type, that.sticker_type) && - Objects.equals(is_animated, that.is_animated) && - Objects.equals(is_video, that.is_video) && - Objects.equals(contains_masks, that.contains_masks) && - Arrays.equals(stickers, that.stickers) && - Objects.equals(thumbnail, that.thumbnail); + return Objects.equals(name, that.name) && Objects.equals(title, that.title) && sticker_type == that.sticker_type && Objects.equals(contains_masks, that.contains_masks) && Arrays.equals(stickers, that.stickers) && Objects.equals(thumbnail, that.thumbnail); } @Override public int hashCode() { - int result = Objects.hash(name, title, sticker_type, is_animated, is_video, thumbnail); + int result = Objects.hash(name, title, sticker_type, contains_masks, thumbnail); result = 31 * result + Arrays.hashCode(stickers); return result; } @@ -102,9 +93,7 @@ public String toString() { return "StickerSet{" + "name='" + name + '\'' + ", title='" + title + '\'' + - ", sticker_type='" + sticker_type + '\'' + - ", is_animated=" + is_animated + - ", is_video=" + is_video + + ", sticker_type=" + sticker_type + ", contains_masks=" + contains_masks + ", stickers=" + Arrays.toString(stickers) + ", thumbnail=" + thumbnail + diff --git a/library/src/main/java/com/pengrad/telegrambot/model/request/InputSticker.java b/library/src/main/java/com/pengrad/telegrambot/model/request/InputSticker.java index f8260286..346b1d3d 100644 --- a/library/src/main/java/com/pengrad/telegrambot/model/request/InputSticker.java +++ b/library/src/main/java/com/pengrad/telegrambot/model/request/InputSticker.java @@ -1,6 +1,5 @@ package com.pengrad.telegrambot.model.request; -import com.google.gson.annotations.SerializedName; import com.pengrad.telegrambot.AttachName; import com.pengrad.telegrambot.model.MaskPosition; import com.pengrad.telegrambot.model.Sticker; @@ -21,7 +20,8 @@ public class InputSticker implements Serializable { transient private String attachName; transient private Object attach; - public InputSticker(Object sticker, String[] emojiList) { + public InputSticker(Object sticker, Sticker.Format format, String[] emojiList) { + this.format = format; this.emoji_list = emojiList; if (sticker instanceof String) { this.sticker = (String) sticker; diff --git a/library/src/main/java/com/pengrad/telegrambot/request/AddStickerToSet.java b/library/src/main/java/com/pengrad/telegrambot/request/AddStickerToSet.java index 1f435bbc..cbf934ca 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/AddStickerToSet.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/AddStickerToSet.java @@ -10,49 +10,6 @@ */ public class AddStickerToSet extends AbstractUploadRequest { - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static AddStickerToSet tgsSticker(Long userId, String name, String emojis, Object tgsSticker) { - return new AddStickerToSet(userId, name, emojis, "tgs_sticker", tgsSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static AddStickerToSet pngSticker(Long userId, String name, String emojis, Object pngSticker) { - return new AddStickerToSet(userId, name, emojis, "png_sticker", pngSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static AddStickerToSet webmSticker(Long userId, String name, String emojis, Object webmSticker) { - return new AddStickerToSet(userId, name, emojis, "webm_sticker", webmSticker); - } - - /** - * @deprecated Use static methods according to sticker set type - {@link #pngSticker(Long, String, String, Object) for png}, {@link #tgsSticker(Long, String, String, Object) for tgs} and {@link #webmSticker(Long, String, String, Object) for webm} - */ - @Deprecated - public AddStickerToSet(Long userId, String name, Object pngSticker, String emojis) { - this(userId, name, emojis, "png_sticker", pngSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - private AddStickerToSet(Long userId, String name, String emojis, String stickerParam, Object sticker) { - super(BaseResponse.class, stickerParam, sticker); - add("user_id", userId); - add("name", name); - add("emojis", emojis); - } - public AddStickerToSet(Long userId, String name, InputSticker sticker) { super(BaseResponse.class, attachName(sticker), attachment(sticker)); add("user_id", userId); @@ -68,6 +25,10 @@ private static Object attachment(InputSticker sticker) { return sticker.getAttachment() != null ? sticker.getAttachment() : "sticker_id"; } + /** + * @deprecated Use maskPosition on InputSticker (since API v6.6) + */ + @Deprecated public AddStickerToSet maskPosition(MaskPosition maskPosition) { return add("mask_position", maskPosition); } diff --git a/library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java b/library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java index a8e6e3c4..e7483db1 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/CreateNewStickerSet.java @@ -12,51 +12,6 @@ */ public class CreateNewStickerSet extends BaseRequest { - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static CreateNewStickerSet tgsSticker(Long userId, String name, String title, String emojis, Object tgsSticker) { - return new CreateNewStickerSet(userId, name, title, emojis, "tgs_sticker", tgsSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static CreateNewStickerSet pngSticker(Long userId, String name, String title, String emojis, Object pngSticker) { - return new CreateNewStickerSet(userId, name, title, emojis, "png_sticker", pngSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - public static CreateNewStickerSet webmSticker(Long userId, String name, String title, String emojis, Object webmSticker) { - return new CreateNewStickerSet(userId, name, title, emojis, "webm_sticker", webmSticker); - } - - /** - * @deprecated Use static methods according to sticker set type - {@link #pngSticker(Long, String, String, String, Object) for png}, {@link #tgsSticker(Long, String, String, String, Object) for tgs} and {@link #webmSticker(Long, String, String, String, Object) for webm} - */ - @Deprecated - public CreateNewStickerSet(Long userId, String name, String title, Object pngSticker, String emojis) { - this(userId, name, title, emojis, "png_sticker", pngSticker); - } - - /** - * @deprecated Use constructor with the InputSticker type (since API v6.6) - */ - @Deprecated - private CreateNewStickerSet(Long userId, String name, String title, String emojis, String stickerParam, Object sticker) { - super(BaseResponse.class); - add(stickerParam, sticker); - add("user_id", userId); - add("name", name); - add("title", title); - add("emojis", emojis); - } - public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers) { super(BaseResponse.class); add("user_id", userId); @@ -75,17 +30,7 @@ public CreateNewStickerSet(Long userId, String name, String title, InputSticker[ */ @Deprecated public CreateNewStickerSet(Long userId, String name, String title, InputSticker[] stickers, Format stickerFormat) { - super(BaseResponse.class); - add("user_id", userId); - add("name", name); - add("title", title); - add("stickers", stickers); - add("sticker_format", stickerFormat.name().toLowerCase()); - for (InputSticker sticker : stickers) { - if (sticker.getAttachment() != null) { - add(sticker.getAttachName(), sticker.getAttachment()); - } - } + this(userId, name, title, stickers); } @Override @@ -93,22 +38,6 @@ public boolean isMultipart() { return true; } - /** - * @deprecated Use stickerType(Type.mask) instead - */ - @Deprecated - public CreateNewStickerSet containsMasks(boolean containsMasks) { - return add("contains_masks", containsMasks); - } - - /** - * @deprecated Invalid when the new constructor with InputSticker type is used (since API v6.6) - */ - @Deprecated - public CreateNewStickerSet maskPosition(MaskPosition maskPosition) { - return add("mask_position", maskPosition); - } - /** * Type of stickers in the set. diff --git a/library/src/main/java/com/pengrad/telegrambot/request/UploadStickerFile.java b/library/src/main/java/com/pengrad/telegrambot/request/UploadStickerFile.java index 08a607c0..c85002a0 100644 --- a/library/src/main/java/com/pengrad/telegrambot/request/UploadStickerFile.java +++ b/library/src/main/java/com/pengrad/telegrambot/request/UploadStickerFile.java @@ -9,15 +9,6 @@ */ public class UploadStickerFile extends AbstractUploadRequest { - /** - * @deprecated Use constructor with the InputFile type (since API v6.6) - */ - @Deprecated - public UploadStickerFile(Long userId, Object pngSticker) { - super(GetFileResponse.class, "png_sticker", pngSticker); - add("user_id", userId); - } - /** * @param stickerFormat must be one of “static”, “animated”, “video”. */ diff --git a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java index d83ecb29..0bb0e6f4 100644 --- a/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java @@ -1374,7 +1374,7 @@ public void getStickerSet() { @Test public void uploadStickerFile() throws IOException { byte[] bytes = Files.readAllBytes(stickerFile.toPath()); - GetFileResponse response = bot.execute(new UploadStickerFile(chatId, bytes)); + GetFileResponse response = bot.execute(new UploadStickerFile(chatId, bytes, Sticker.Format.Static)); FileTest.check(response.file(), false); response = bot.execute(new UploadStickerFile(chatId, bytes, Sticker.Format.Static)); @@ -1382,52 +1382,48 @@ public void uploadStickerFile() throws IOException { } @Test - public void createNewPngStickerSet() { + public void createNewPngStickerSetAndAddSticker() { String name = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot"; + String[] emojis = new String[]{"\uD83D\uDE00"}; + InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFile, Sticker.Format.Static, emojis)}; BaseResponse response = bot.execute( - CreateNewStickerSet.pngSticker(chatId, name, "test1", "\uD83D\uDE00", stickerFile) - .stickerType(Sticker.Type.mask) - .maskPosition(new MaskPosition(MaskPosition.Point.forehead, 0f, 0f, 1f))); + new CreateNewStickerSet(chatId, name, "test1", stickers) + .stickerType(Sticker.Type.mask)); assertTrue(response.isOk()); response = bot.execute(new AddStickerToSet(chatId, name, - new InputSticker(stickerId, new String[]{"\uD83D\uDE00"})) - .maskPosition(new MaskPosition("eyes", 0f, 0f, 1f))); + new InputSticker(stickerId, Sticker.Format.Static, emojis) + .maskPosition(new MaskPosition("eyes", 0f, 0f, 1f)))); assertTrue(response.isOk()); } @Test public void createNewWebmStickerSetAndAddSticker() { String setName = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot"; + String[] emojis = new String[]{"\uD83D\uDE00"}; + InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFileVid, Sticker.Format.video, emojis)}; BaseResponse response = bot.execute( - CreateNewStickerSet.webmSticker(chatId, setName, - "test1", "\uD83D\uDE00", stickerFileVid) - .stickerType(Sticker.Type.mask) - .maskPosition(new MaskPosition(MaskPosition.Point.forehead, 0f, 0f, 1f))); - assertTrue(response.isOk()); - - response = bot.execute( - AddStickerToSet.webmSticker(chatId, setName, "\uD83D\uDE15", stickerFileVid)); + new CreateNewStickerSet(chatId, setName, "test1", stickers) + .stickerType(Sticker.Type.regular) + ); assertTrue(response.isOk()); } @Test public void addStickerToSet() { BaseResponse response = bot.execute( - AddStickerToSet.pngSticker(chatId, stickerSet, "\uD83D\uDE15", "BQADAgADuAAD7yupS4eB23UmZhGuAg") - .maskPosition(new MaskPosition("eyes", 0f, 0f, 1f))); + new AddStickerToSet(chatId, stickerSet, + new InputSticker("BQADAgADuAAD7yupS4eB23UmZhGuAg", Sticker.Format.Static, new String[]{"\uD83D\uDE15"}) + .maskPosition(new MaskPosition("eyes", 0f, 0f, 1f)))); assertTrue(response.isOk()); } @Test public void createSetAndAddStickerTgs() { String setName = "test" + System.currentTimeMillis() + "_by_pengrad_test_bot"; + InputSticker[] stickers = new InputSticker[]{new InputSticker(stickerFileAnim, Sticker.Format.animated, new String[]{"\uD83D\uDE00"})}; BaseResponse response = bot.execute( - CreateNewStickerSet.tgsSticker(chatId, setName, "test1", "\uD83D\uDE00", stickerFileAnim)); - assertTrue(response.isOk()); - - response = bot.execute( - AddStickerToSet.tgsSticker(chatId, setName, "\uD83D\uDE15", stickerFileAnim)); + new CreateNewStickerSet(chatId, setName, "test1", stickers)); assertTrue(response.isOk()); } @@ -1437,11 +1433,10 @@ public void createNewStickerSet() { String title = "test112312312"; BaseResponse response = bot.execute( new CreateNewStickerSet(chatId, setName, title, new InputSticker[]{ - new InputSticker(stickerFile, new String[]{"\uD83D\uDE00"}) + new InputSticker(stickerFile, Sticker.Format.Static, new String[]{"\uD83D\uDE00"}) .keywords(new String[]{"yes", "no"}) .maskPosition(new MaskPosition(MaskPosition.Point.forehead, 10f, 20f, 1f)) }, Sticker.Format.Static) - .containsMasks(false) .needsRepainting(false)); assertTrue(response.isOk()); @@ -1487,7 +1482,8 @@ public void setStickerPositionInSet() { @Test public void deleteStickerFromSet() { - BaseResponse response = bot.execute(AddStickerToSet.pngSticker(chatId, stickerSet, "\uD83D\uDE15", stickerFile)); + InputSticker inputSticker = new InputSticker("BQADAgADuAAD7yupS4eB23UmZhGuAg", Sticker.Format.Static, new String[]{"\uD83D\uDE15"}); + BaseResponse response = bot.execute(new AddStickerToSet(chatId, stickerSet, inputSticker)); assertTrue(response.isOk()); GetStickerSetResponse setResponse = bot.execute(new GetStickerSet(stickerSet)); @@ -1511,7 +1507,7 @@ public void setStickerSetThumb() { assertTrue(response.isOk()); StickerSet set = bot.execute(new GetStickerSet(stickerSetAnim)).stickerSet(); - assertTrue(set.isAnimated()); + assertFalse(set.isAnimated()); PhotoSize thumb = set.thumb(); PhotoSizeTest.checkPhotos(thumb); assertEquals(Integer.valueOf(100), thumb.width()); @@ -1538,7 +1534,7 @@ public void setCustomEmojiStickerSetThumbnail() { String setName = "custom_emoji_set_by_pengrad_test_bot"; BaseResponse response = bot.execute( new CreateNewStickerSet(chatId, setName, "title", - new InputSticker[]{new InputSticker(stickerFileAnim, new String[]{"\uD83D\uDE15"})}, + new InputSticker[]{new InputSticker(stickerFileAnim, Sticker.Format.animated, new String[]{"\uD83D\uDE15"})}, Sticker.Format.animated ).stickerType(Sticker.Type.custom_emoji) ); diff --git a/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java b/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java index 9d5390d0..06ebd73e 100644 --- a/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java +++ b/library/src/test/java/com/pengrad/telegrambot/checks/MessageTest.java @@ -35,7 +35,7 @@ public static void checkTextMessage(Message message) { assertNull(message.messageThreadId()); assertFalse(message.isTopicMessage()); assertNull(message.isAutomaticForward()); - assertNull(message.hasMediaSpoiler()); + assertFalse(message.hasMediaSpoiler()); assertNull(message.messageAutoDeleteTimerChanged()); assertNull(message.chatShared()); assertNull(message.proximityAlertTriggered());