1package eu.siacs.conversations.http.services;
2
3import com.google.common.base.Objects;
4
5import java.util.Collections;
6import java.util.List;
7import java.util.Set;
8
9import eu.siacs.conversations.services.AvatarService;
10import eu.siacs.conversations.utils.UIHelper;
11import retrofit2.Call;
12import retrofit2.http.Body;
13import retrofit2.http.GET;
14import retrofit2.http.POST;
15import retrofit2.http.Query;
16import rocks.xmpp.addr.Jid;
17
18public interface MuclumbusService {
19
20 @GET("/api/1.0/rooms/unsafe")
21 Call<Rooms> getRooms(@Query("p") int page);
22
23 @POST("/api/1.0/search")
24 Call<SearchResult> search(@Body SearchRequest searchRequest);
25
26 class Rooms {
27 int page;
28 int total;
29 int pages;
30 public List<Room> items;
31 }
32
33 class Room implements AvatarService.Avatarable {
34
35 public String address;
36 public String name;
37 public String description;
38
39 public String getName() {
40 return name;
41 }
42
43 public String getDescription() {
44 return description;
45 }
46
47 public Jid getRoom() {
48 try {
49 return Jid.of(address);
50 } catch (IllegalArgumentException e) {
51 return null;
52 }
53 }
54
55 @Override
56 public int getAvatarBackgroundColor() {
57 Jid room = getRoom();
58 return UIHelper.getColorForName(room != null ? room.asBareJid().toEscapedString() : name);
59 }
60
61 @Override
62 public boolean equals(Object o) {
63 if (this == o) return true;
64 if (o == null || getClass() != o.getClass()) return false;
65 Room room = (Room) o;
66 return Objects.equal(address, room.address) &&
67 Objects.equal(name, room.name) &&
68 Objects.equal(description, room.description);
69 }
70
71 @Override
72 public int hashCode() {
73 return Objects.hashCode(address, name, description);
74 }
75 }
76
77 class SearchRequest {
78
79 public Set<String> keywords;
80
81 public SearchRequest(String keyword) {
82 this.keywords = Collections.singleton(keyword);
83 }
84 }
85
86 class SearchResult {
87
88 public Result result;
89
90 }
91
92 class Result {
93
94 public List<Room> items;
95
96 }
97
98}