use of com.fanap.podchat.model.ResultThreadsSummary in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getAllThreads.
private void getAllThreads() {
if (cache) {
String uniqueId = generateUniqueId();
JsonObject content = new JsonObject();
content.addProperty("summary", true);
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(content.toString());
chatMessage.setToken(getToken());
chatMessage.setType(Constants.GET_THREADS);
chatMessage.setTypeCode(getTypeCode());
chatMessage.setUniqueId(uniqueId);
ChatHandler handler = new ChatHandler() {
@Override
public void onGetThread(String data) {
super.onGetThread(data);
ArrayList<ResultThreadsSummary> result = gson.fromJson(data, new TypeToken<ArrayList<ResultThreadsSummary>>() {
}.getType());
ArrayList<Long> serverResultThreadIds = new ArrayList<>();
for (ResultThreadsSummary rts : result) {
serverResultThreadIds.add((long) rts.getId());
}
messageDatabaseHelper.getThreadIdsList(t -> {
try {
if (t == null)
return;
List<Long> threadsIdsInCache = (List<Long>) t;
if (threadsIdsInCache.size() > 0) {
threadsIdsInCache.removeAll(serverResultThreadIds);
if (serverResultThreadIds.size() > 0) {
messageDatabaseHelper.deleteThreads(new ArrayList<>(threadsIdsInCache));
showLog("THREADS CACHE UPDATED", "");
}
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
});
}
};
// callback
handlerSend.put(uniqueId, handler);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("contentCount");
jsonObject.remove("repliedTo");
jsonObject.remove("subjectId");
jsonObject.remove("time");
sendAsyncMessage(jsonObject.toString(), AsyncAckType.Constants.WITHOUT_ACK, "UPDATING_THREADS_CACHE");
}
}
Aggregations