Skip to content

Commit 7f8e935

Browse files
committed
Added the new fields photo, description and invite_link to the Chat object
1 parent 87f44fe commit 7f8e935

File tree

6 files changed

+104
-6
lines changed

6 files changed

+104
-6
lines changed

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

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public class Chat implements Serializable {
1212
private final static long serialVersionUID = 0L;
1313

1414
public enum Type {
15-
@SerializedName("private") Private, group, supergroup, channel
15+
@SerializedName("private")Private, group, supergroup, channel
1616
}
1717

1818
private Long id;
@@ -30,6 +30,10 @@ public enum Type {
3030

3131
private Boolean all_members_are_administrators;
3232

33+
private ChatPhoto photo;
34+
private String description;
35+
private String invite_link;
36+
3337
public Long id() {
3438
return id;
3539
}
@@ -58,6 +62,18 @@ public Boolean allMembersAreAdministrators() {
5862
return all_members_are_administrators;
5963
}
6064

65+
public ChatPhoto photo() {
66+
return photo;
67+
}
68+
69+
public String description() {
70+
return description;
71+
}
72+
73+
public String inviteLink() {
74+
return invite_link;
75+
}
76+
6177
@Override
6278
public boolean equals(Object o) {
6379
if (this == o) return true;
@@ -71,7 +87,11 @@ public boolean equals(Object o) {
7187
if (last_name != null ? !last_name.equals(chat.last_name) : chat.last_name != null) return false;
7288
if (username != null ? !username.equals(chat.username) : chat.username != null) return false;
7389
if (title != null ? !title.equals(chat.title) : chat.title != null) return false;
74-
return all_members_are_administrators != null ? all_members_are_administrators.equals(chat.all_members_are_administrators) : chat.all_members_are_administrators == null;
90+
if (all_members_are_administrators != null ? !all_members_are_administrators.equals(chat.all_members_are_administrators) : chat.all_members_are_administrators != null)
91+
return false;
92+
if (photo != null ? !photo.equals(chat.photo) : chat.photo != null) return false;
93+
if (description != null ? !description.equals(chat.description) : chat.description != null) return false;
94+
return invite_link != null ? invite_link.equals(chat.invite_link) : chat.invite_link == null;
7595
}
7696

7797
@Override
@@ -89,6 +109,9 @@ public String toString() {
89109
", username='" + username + '\'' +
90110
", title='" + title + '\'' +
91111
", all_members_are_administrators=" + all_members_are_administrators +
112+
", photo=" + photo +
113+
", description='" + description + '\'' +
114+
", invite_link='" + invite_link + '\'' +
92115
'}';
93116
}
94117
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.pengrad.telegrambot.model;
2+
3+
import java.io.Serializable;
4+
5+
/**
6+
* Stas Parshin
7+
* 01 July 2017
8+
*/
9+
public class ChatPhoto implements Serializable {
10+
private final static long serialVersionUID = 0L;
11+
12+
private String small_file_id;
13+
private String big_file_id;
14+
15+
public String smallFileId() {
16+
return small_file_id;
17+
}
18+
19+
public String bigFileId() {
20+
return big_file_id;
21+
}
22+
23+
@Override
24+
public boolean equals(Object o) {
25+
if (this == o) return true;
26+
if (o == null || getClass() != o.getClass()) return false;
27+
28+
ChatPhoto chatPhoto = (ChatPhoto) o;
29+
30+
if (small_file_id != null ? !small_file_id.equals(chatPhoto.small_file_id) : chatPhoto.small_file_id != null)
31+
return false;
32+
return big_file_id != null ? big_file_id.equals(chatPhoto.big_file_id) : chatPhoto.big_file_id == null;
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
int result = small_file_id != null ? small_file_id.hashCode() : 0;
38+
result = 31 * result + (big_file_id != null ? big_file_id.hashCode() : 0);
39+
return result;
40+
}
41+
42+
@Override
43+
public String toString() {
44+
return "ChatPhoto{" +
45+
"small_file_id='" + small_file_id + '\'' +
46+
", big_file_id='" + big_file_id + '\'' +
47+
'}';
48+
}
49+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.pengrad.telegrambot;
2+
3+
import com.pengrad.telegrambot.model.ChatPhoto;
4+
5+
import static org.junit.Assert.assertNotNull;
6+
7+
/**
8+
* Stas Parshin
9+
* 01 July 2017
10+
*/
11+
public class ChatPhotoTest {
12+
13+
public static void check(ChatPhoto photo) {
14+
assertNotNull(photo.smallFileId());
15+
assertNotNull(photo.bigFileId());
16+
}
17+
18+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class ChatTest {
1313
public static void checkChat(Chat chat) {
1414
assertNotNull(chat.id());
1515
assertNotNull(chat.type());
16+
if (chat.photo() != null) ChatPhotoTest.check(chat.photo());
1617
}
1718

1819
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ public void setClasses() {
2727
CallbackQuery.class,
2828
Chat.class,
2929
ChatMember.class,
30+
ChatPhoto.class,
3031
ChosenInlineResult.class,
3132
Contact.class,
3233
Document.class,

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
import java.io.File;
1313
import java.io.FileInputStream;
1414
import java.io.IOException;
15+
import java.net.MalformedURLException;
16+
import java.net.URISyntaxException;
17+
import java.net.URL;
1518
import java.nio.file.Files;
1619
import java.nio.file.Path;
1720
import java.nio.file.Paths;
@@ -321,10 +324,13 @@ private CallbackQuery getLastCallbackQuery() {
321324
}
322325

323326
@Test
324-
public void getChat() {
325-
GetChatResponse getChatResponse = bot.execute(new GetChat(chatId));
326-
assertTrue(getChatResponse.toString().contains(chatId.toString()));
327-
ChatTest.checkChat(getChatResponse.chat());
327+
public void getChat() throws MalformedURLException, URISyntaxException {
328+
Chat chat = bot.execute(new GetChat(groupId)).chat();
329+
ChatTest.checkChat(chat);
330+
assertEquals(chat.type(), Chat.Type.supergroup);
331+
assertTrue(chat.title().contains("Test Bot Group"));
332+
assertTrue(chat.description().contains("New desc"));
333+
assertNotNull(new URL(chat.inviteLink()).toURI());
328334
}
329335

330336
@Test

0 commit comments

Comments
 (0)