Skip to content

Commit b874222

Browse files
committed
Added the class GiftInfo and the field gift to the class Message, describing a service message about a regular gift that was sent or received.
1 parent c29e22d commit b874222

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

library/src/main/java/com/pengrad/telegrambot/model/Message.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.pengrad.telegrambot.model.chatbackground.ChatBackground;
44
import com.pengrad.telegrambot.model.chatboost.ChatBoostAdded;
5+
import com.pengrad.telegrambot.model.gift.GiftInfo;
56
import com.pengrad.telegrambot.model.giveaway.Giveaway;
67
import com.pengrad.telegrambot.model.giveaway.GiveawayCompleted;
78
import com.pengrad.telegrambot.model.giveaway.GiveawayCreated;
@@ -105,6 +106,7 @@ public class Message extends MaybeInaccessibleMessage implements Serializable {
105106
private VideoChatScheduled video_chat_scheduled;
106107
private InlineKeyboardMarkup reply_markup;
107108
private WebAppData web_app_data;
109+
private GiftInfo gift;
108110

109111
public Integer messageThreadId() {
110112
return message_thread_id;
@@ -435,6 +437,10 @@ public WebAppData webAppData() {
435437
return web_app_data;
436438
}
437439

440+
public GiftInfo gift() {
441+
return gift;
442+
}
443+
438444
/**
439445
* Only for backwards-compatibility with MaybeInaccessibleMessage
440446
*/
@@ -545,7 +551,8 @@ public boolean equals(Object o) {
545551
Objects.equals(video_chat_participants_invited, message.video_chat_participants_invited) &&
546552
Objects.equals(video_chat_scheduled, message.video_chat_scheduled) &&
547553
Objects.equals(reply_markup, message.reply_markup) &&
548-
Objects.equals(web_app_data, message.web_app_data);
554+
Objects.equals(web_app_data, message.web_app_data) &&
555+
Objects.equals(gift, message.gift);
549556
}
550557

551558
@Override
@@ -641,6 +648,7 @@ public String toString() {
641648
", video_chat_scheduled=" + video_chat_scheduled +
642649
", reply_markup=" + reply_markup +
643650
", web_app_data=" + web_app_data +
651+
", gift=" + gift +
644652
'}';
645653
}
646654
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.pengrad.telegrambot.model.gift
2+
3+
import com.pengrad.telegrambot.model.MessageEntity
4+
5+
data class GiftInfo(
6+
@get:JvmName("gift") val gift: Gift,
7+
@get:JvmName("ownedGiftId") val ownedGiftId: String?,
8+
@get:JvmName("convertStarCount") val convertStarCount: Int?,
9+
@get:JvmName("prepaidUpgradeStarCount") val prepaidUpgradeStarCount: Int?,
10+
@get:JvmName("canBeUpgraded") val canBeUpgraded: Boolean?,
11+
@get:JvmName("text") val text: String?,
12+
@get:JvmName("entities") val entities: Array<MessageEntity>?,
13+
@get:JvmName("isPrivate") val isPrivate: Boolean?,
14+
) {
15+
16+
override fun equals(other: Any?): Boolean {
17+
if (this === other) return true
18+
if (other !is GiftInfo) return false
19+
20+
return gift == other.gift &&
21+
ownedGiftId == other.ownedGiftId &&
22+
convertStarCount == other.convertStarCount &&
23+
prepaidUpgradeStarCount == other.prepaidUpgradeStarCount &&
24+
canBeUpgraded == other.canBeUpgraded &&
25+
text == other.text &&
26+
entities contentEquals other.entities &&
27+
isPrivate == other.isPrivate
28+
}
29+
30+
override fun hashCode(): Int {
31+
var result = gift.hashCode()
32+
result = 31 * result + (ownedGiftId?.hashCode() ?: 0)
33+
result = 31 * result + (convertStarCount ?: 0)
34+
result = 31 * result + (prepaidUpgradeStarCount ?: 0)
35+
result = 31 * result + (canBeUpgraded?.hashCode() ?: 0)
36+
result = 31 * result + (text?.hashCode() ?: 0)
37+
result = 31 * result + (entities?.contentHashCode() ?: 0)
38+
result = 31 * result + (isPrivate?.hashCode() ?: 0)
39+
return result
40+
}
41+
42+
override fun toString(): String {
43+
return "GiftInfo(gift=$gift, ownedGiftId=$ownedGiftId, convertStarCount=$convertStarCount, " +
44+
"prepaidUpgradeStarCount=$prepaidUpgradeStarCount, canBeUpgraded=$canBeUpgraded, " +
45+
"text=$text, entities=${entities?.contentToString()}, isPrivate=$isPrivate)"
46+
}
47+
48+
}

0 commit comments

Comments
 (0)