mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
implement get_msg_reactions() JSON-RPC API
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package com.b44t.messenger.rpc;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class Reaction {
|
||||
// The reaction text string.
|
||||
private final String text;
|
||||
// The count of users that have reacted with this reaction.
|
||||
private final int count;
|
||||
|
||||
public Reaction(String text, int count) {
|
||||
this.text = text;
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public int getCount() {
|
||||
return count;
|
||||
}
|
||||
|
||||
public static class ReactionDeserializer implements JsonDeserializer<Reaction> {
|
||||
@Override
|
||||
public Reaction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonArray tuple = json.getAsJsonArray();
|
||||
return new Reaction(tuple.get(0).getAsString(), tuple.get(1).getAsInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.b44t.messenger.rpc;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class Reactions {
|
||||
// Map from a contact to it's reaction to message.
|
||||
private HashMap<Integer, String[]> reactionsByContact;
|
||||
// Unique reactions, sorted in descending order.
|
||||
private Reaction[] reactions;
|
||||
|
||||
public Reactions(HashMap<Integer, String[]> reactionsByContact, Reaction[] reactions) {
|
||||
this.reactionsByContact = reactionsByContact;
|
||||
this.reactions = reactions;
|
||||
}
|
||||
|
||||
public HashMap<Integer, String[]> getReactionsByContact() {
|
||||
return reactionsByContact;
|
||||
}
|
||||
|
||||
public Reaction[] getReactions() {
|
||||
return reactions;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.b44t.messenger.rpc;
|
||||
|
||||
import static com.b44t.messenger.rpc.Reaction.ReactionDeserializer;
|
||||
|
||||
import com.b44t.messenger.DcJsonrpcInstance;
|
||||
import com.b44t.messenger.util.concurrent.SettableFuture;
|
||||
import com.google.gson.Gson;
|
||||
@@ -8,7 +10,6 @@ import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
@@ -17,10 +18,14 @@ public class Rpc {
|
||||
private final Map<Integer, SettableFuture<JsonElement>> requestFutures = new ConcurrentHashMap<>();
|
||||
private final DcJsonrpcInstance dcJsonrpcInstance;
|
||||
private int requestId = 0;
|
||||
private final Gson gson = new GsonBuilder().serializeNulls().create();
|
||||
private final Gson gson;
|
||||
|
||||
public Rpc(DcJsonrpcInstance dcJsonrpcInstance) {
|
||||
this.dcJsonrpcInstance = dcJsonrpcInstance;
|
||||
|
||||
GsonBuilder gsonBuilder = new GsonBuilder();
|
||||
gsonBuilder.registerTypeAdapter(Reaction.class, new ReactionDeserializer());
|
||||
this.gson = gsonBuilder.serializeNulls().create();
|
||||
}
|
||||
|
||||
private void processResponse() throws JsonSyntaxException {
|
||||
@@ -100,6 +105,10 @@ public class Rpc {
|
||||
return gson.fromJson(getResult("get_http_response", accountId, url), HttpResponse.class);
|
||||
}
|
||||
|
||||
public Reactions getMsgReactions(int accountId, int msgId) throws RpcException {
|
||||
return gson.fromJson(getResult("get_msg_reactions", accountId, msgId), Reactions.class);
|
||||
}
|
||||
|
||||
|
||||
private static class Request {
|
||||
public String jsonrpc = "2.0";
|
||||
|
||||
Reference in New Issue
Block a user