use of com.meisolsson.githubsdk.model.Reaction in project gh4a by slapperwan.
the class ReactionBar method toggleReaction.
private static Single<Optional<Reaction>> toggleReaction(String content, long id, List<Reaction> existingDetails, Callback callback, Item item, ReactionDetailsCache cache) {
final Single<Optional<Reaction>> resultSingle;
if (id == 0) {
resultSingle = callback.addReaction(item, content).map(Optional::of);
} else {
ReactionService service = ServiceFactory.get(ReactionService.class, false);
resultSingle = service.deleteReaction(id).map(response -> Optional.absent());
}
return resultSingle.compose(RxUtils::doInBackground).doOnSuccess(reactionOpt -> {
if (reactionOpt.isPresent()) {
existingDetails.add(reactionOpt.get());
} else {
for (int i = 0; i < existingDetails.size(); i++) {
Reaction reaction = existingDetails.get(i);
if (reaction.id() == id) {
existingDetails.remove(i);
break;
}
}
}
cache.putEntry(item, existingDetails);
});
}
Aggregations