Skip to content

Commit 790c8d8

Browse files
committed
Move showCaptionAboveMedia to CopyMessage
1 parent f9f93f2 commit 790c8d8

File tree

6 files changed

+132
-75
lines changed

6 files changed

+132
-75
lines changed

library/src/main/java/com/pengrad/telegrambot/model/request/InlineKeyboardButton.kt

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@ import com.pengrad.telegrambot.model.WebAppInfo
77
* 06 May 2016
88
*/
99
data class InlineKeyboardButton @JvmOverloads constructor(
10-
@get:JvmName("text") var text: String? = null,
11-
@get:JvmName("url") var url: String? = null,
12-
@get:JvmName("loginUrl") var loginUrl: LoginUrl? = null,
13-
@get:JvmName("callbackData") var callbackData: String? = null,
14-
@get:JvmName("switchInlineQuery") var switchInlineQuery: String? = null,
15-
@get:JvmName("switchInlineQueryCurrentChat") var switchInlineQueryCurrentChat: String? = null,
16-
@get:JvmName("switchInlineQueryChosenChat") var switchInlineQueryChosenChat: SwitchInlineQueryChosenChat? = null,
17-
@get:JvmName("callbackGame") var callbackGame: CallbackGame? = null,
18-
var pay: Boolean? = null,
19-
@get:JvmName("webApp") var webApp: WebAppInfo? = null,
20-
@get:JvmName("copyText") var copyText: CopyTextButton? = null,
10+
@get:JvmName("text") var text: String? = null,
11+
@get:JvmName("url") var url: String? = null,
12+
@get:JvmName("loginUrl") var loginUrl: LoginUrl? = null,
13+
@get:JvmName("callbackData") var callbackData: String? = null,
14+
@get:JvmName("switchInlineQuery") var switchInlineQuery: String? = null,
15+
@get:JvmName("switchInlineQueryCurrentChat") var switchInlineQueryCurrentChat: String? = null,
16+
@get:JvmName("switchInlineQueryChosenChat") var switchInlineQueryChosenChat: SwitchInlineQueryChosenChat? = null,
17+
@get:JvmName("callbackGame") var callbackGame: CallbackGame? = null,
18+
var pay: Boolean? = null,
19+
@get:JvmName("webApp") var webApp: WebAppInfo? = null,
20+
@get:JvmName("copyText") var copyText: CopyTextButton? = null,
2121
) {
2222

2323
fun url(url: String): InlineKeyboardButton {
@@ -66,7 +66,11 @@ data class InlineKeyboardButton @JvmOverloads constructor(
6666
return this
6767
}
6868

69-
fun copyText(copyText : CopyTextButton): InlineKeyboardButton {
69+
fun copyText(text: String): InlineKeyboardButton {
70+
return copyText(CopyTextButton(text))
71+
}
72+
73+
fun copyText(copyText: CopyTextButton): InlineKeyboardButton {
7074
this.copyText = copyText
7175
return this
7276
}

library/src/main/java/com/pengrad/telegrambot/request/CopyMessage.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,14 @@ public CopyMessage replyMarkup(Keyboard replyMarkup) {
5555
return add("reply_markup", replyMarkup);
5656
}
5757

58+
public CopyMessage showCaptionAboveMedia(boolean showCaptionAboveMedia) {
59+
return add("show_caption_above_media", showCaptionAboveMedia);
60+
}
61+
5862
public CopyMessage disableNotification(boolean disableNotification) {
5963
return add("disable_notification", disableNotification);
6064
}
65+
6166
public CopyMessage protectContent(boolean protectContent) {
6267
return add("protect_content", protectContent);
6368
}

library/src/main/java/com/pengrad/telegrambot/request/CopyMessages.kt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,4 @@ class CopyMessages(
2626
fun protectContent(protectContent: Boolean): CopyMessages {
2727
return add("protect_content", protectContent)
2828
}
29-
30-
fun showCaptionAboveMedia(showCaptionAboveMedia: Boolean): CopyMessages {
31-
return add("show_caption_above_media", showCaptionAboveMedia)
32-
}
3329
}

library/src/test/java/com/pengrad/telegrambot/BotUtilsTest.java

Lines changed: 0 additions & 55 deletions
This file was deleted.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
package com.pengrad.telegrambot
2+
3+
import com.pengrad.telegrambot.model.Update
4+
import com.pengrad.telegrambot.response.SendResponse
5+
import com.pengrad.telegrambot.utility.BotUtils
6+
import org.junit.Assert
7+
import org.junit.Test
8+
import java.io.ByteArrayInputStream
9+
import java.io.IOException
10+
import java.io.StringReader
11+
12+
/**
13+
* Stas Parshin
14+
* 26 January 2020
15+
*/
16+
class BotUtilsTest {
17+
val updateStr: String = """
18+
{
19+
"update_id": 874199391,
20+
"message": {
21+
"message_id": 33111,
22+
"from": {
23+
"id": 1231231231,
24+
"is_bot": false,
25+
"first_name": "RRRR",
26+
"username": "RRRR54321"
27+
},
28+
"chat": {
29+
"id": -23123123123123,
30+
"title": "hhh iiiiii ccccc",
31+
"type": "supergroup"
32+
},
33+
"user_shared": {
34+
"user_id": 6111111111,
35+
"request_id": 1
36+
},
37+
"users_shared": {
38+
"user_ids": [
39+
6111111111
40+
],
41+
"users": [
42+
{
43+
"user_id": 6111111111,
44+
"first_name": "FirstNameTest",
45+
"last_name": "LastNameTest"
46+
}
47+
],
48+
"request_id": 1
49+
},
50+
"date": 1579958705,
51+
"text": "block the news",
52+
"giveaway_created": {}
53+
}
54+
}
55+
""".trimIndent()
56+
57+
private fun check(update: Update) {
58+
Assert.assertEquals(update.updateId(), 874199391)
59+
Assert.assertEquals(update.message().messageId(), 33111)
60+
Assert.assertEquals(update.message().usersShared().users()[0].userId(), 6111111111L)
61+
Assert.assertEquals(update.message().giveawayCreated().prizeStarCount, 0)
62+
}
63+
64+
@Test
65+
fun parseUpdateString() {
66+
val update = BotUtils.parseUpdate(updateStr)
67+
check(update)
68+
}
69+
70+
@Test
71+
fun parseUpdateReader() {
72+
val update = BotUtils.parseUpdate(StringReader(updateStr))
73+
check(update)
74+
}
75+
76+
@Test
77+
@Throws(IOException::class)
78+
fun bytesFromInputStream() {
79+
val src = byteArrayOf(1, 2, 3, 4)
80+
val bytes = BotUtils.getBytesFromInputStream(ByteArrayInputStream(src))
81+
Assert.assertArrayEquals(bytes, src)
82+
}
83+
84+
@Test
85+
fun parseNull() {
86+
Assert.assertNull(BotUtils.fromJson(null, SendResponse::class.java))
87+
Assert.assertNull(BotUtils.fromJson("", SendResponse::class.java))
88+
}
89+
}

library/src/test/java/com/pengrad/telegrambot/TelegramBotTest.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -598,11 +598,8 @@ public void sendMessage() {
598598
SendResponse sendResponse = bot.execute(new SendMessage(chatId, "reply this message").replyMarkup(
599599
new ForceReply().inputFieldPlaceholder("input-placeholder").selective(true)
600600
));
601-
ForceReply f = new ForceReply().inputFieldPlaceholder("asd");
602-
Giveaway g = new Giveaway();
603601
MessageTest.checkTextMessage(sendResponse.message());
604602
assertNotNull(sendResponse.message().from());
605-
if (true) return;
606603

607604
sendResponse = bot.execute(new SendMessage(chatId, "remove keyboard")
608605
.replyMarkup(new ReplyKeyboardRemove())
@@ -616,6 +613,7 @@ public void sendMessage() {
616613
.parseMode(ParseMode.HTML)
617614
.disableWebPagePreview(false)
618615
.protectContent(true)
616+
.allowPaidBroadcast(true)
619617
.replyMarkup(new ReplyKeyboardMarkup(
620618
new KeyboardButton("contact").requestContact(true),
621619
new KeyboardButton("location").requestLocation(true),
@@ -710,9 +708,14 @@ public void copyMessage() {
710708
.caption("new **caption**")
711709
.parseMode(ParseMode.MarkdownV2)
712710
.captionEntities(new MessageEntity(MessageEntity.Type.bold, 0, 1))
711+
.replyParameters(new ReplyParameters(forwardMessageId))
713712
.allowSendingWithoutReply(false)
714713
.replyToMessageId(1)
714+
.replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton("copy").copyText("text")))
715+
.showCaptionAboveMedia(true)
715716
.disableNotification(true)
717+
.protectContent(true)
718+
.allowPaidBroadcast(false)
716719
);
717720
assertTrue(response.messageId() > 0);
718721
}
@@ -2425,7 +2428,22 @@ public void sendPaidMedia() {
24252428
Integer starCount = 2;
24262429
SendResponse response = bot.execute(new SendPaidMedia(chatId, starCount,
24272430
new InputPaidMediaVideo(videoFile).thumbnail(thumbFile),
2428-
new InputPaidMediaPhoto(photoFileId)));
2431+
new InputPaidMediaPhoto(photoFileId))
2432+
.caption("caption")
2433+
.parseMode(ParseMode.MarkdownV2)
2434+
.captionEntities(new MessageEntity(MessageEntity.Type.bold, 0, 1))
2435+
.showCaptionAboveMedia(true)
2436+
.disableNotification(true)
2437+
.protectContent(false)
2438+
.replyParameters(new ReplyParameters(forwardMessageId))
2439+
.businessConnectionId("")
2440+
.replyMarkup(new InlineKeyboardMarkup(new InlineKeyboardButton("send")))
2441+
.replyMarkup(new ReplyKeyboardMarkup("reply"))
2442+
.replyMarkup(new ReplyKeyboardRemove())
2443+
.replyMarkup(new ForceReply())
2444+
.payload("payload")
2445+
.allowPaidBroadcast(false)
2446+
);
24292447
PaidMediaInfo mediaInfo = response.message().paidMedia();
24302448
assertTrue(response.isOk());
24312449
assertEquals(starCount, mediaInfo.starCount());

0 commit comments

Comments
 (0)