diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-04-26 23:12:05 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-04-26 23:12:22 +0200 |
commit | f9f07063876ec5f3917ce72385b015e1b5f31d7e (patch) | |
tree | 093f9ded3021800b20e1e8dcb22d4d8ac17dc7db /src/main/java/de/pixart/messenger/http/services | |
parent | 35276c6519afa1da6042dd485ddae09b06c68aeb (diff) |
implement channel discovery
refactor muc search to use http
cache channel search results
Diffstat (limited to 'src/main/java/de/pixart/messenger/http/services')
-rw-r--r-- | src/main/java/de/pixart/messenger/http/services/MuclumbusService.java | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/src/main/java/de/pixart/messenger/http/services/MuclumbusService.java b/src/main/java/de/pixart/messenger/http/services/MuclumbusService.java new file mode 100644 index 000000000..7c8ca9e32 --- /dev/null +++ b/src/main/java/de/pixart/messenger/http/services/MuclumbusService.java @@ -0,0 +1,92 @@ +package de.pixart.messenger.http.services; + +import com.google.common.base.Objects; + +import java.util.Collections; +import java.util.List; +import java.util.Set; + +import de.pixart.messenger.services.AvatarService; +import de.pixart.messenger.utils.UIHelper; +import retrofit2.Call; +import retrofit2.http.Body; +import retrofit2.http.GET; +import retrofit2.http.POST; +import retrofit2.http.Query; +import rocks.xmpp.addr.Jid; + +public interface MuclumbusService { + + @GET("/api/1.0/rooms/unsafe") + Call<Rooms> getRooms(@Query("p") int page); + + @POST("/api/1.0/search") + Call<SearchResult> search(@Body SearchRequest searchRequest); + + class Rooms { + int page; + int total; + int pages; + public List<Room> items; + } + + class Room implements AvatarService.Avatarable { + + public String address; + public String name; + public String description; + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public Jid getRoom() { + try { + return Jid.of(address); + } catch (IllegalArgumentException e) { + return null; + } + } + + @Override + public int getAvatarBackgroundColor() { + Jid room = getRoom(); + return UIHelper.getColorForName(room != null ? room.asBareJid().toEscapedString() : name); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Room room = (Room) o; + return Objects.equal(address, room.address) && + Objects.equal(name, room.name) && + Objects.equal(description, room.description); + } + + @Override + public int hashCode() { + return Objects.hashCode(address, name, description); + } + } + + class SearchRequest { + public Set<String> keywords; + + public SearchRequest(String keyword) { + this.keywords = Collections.singleton(keyword); + } + } + + class SearchResult { + public Result result; + } + + class Result { + public List<Room> items; + } +}
\ No newline at end of file |