Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement
get_msg_reactions()
JSON-RPC API
- Loading branch information
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters