use of com.fanap.podchat.model.ResultParticipant in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method loadAdminsFromCache.
private void loadAdminsFromCache(String uniqueId, int count, int offset, long threadId) {
try {
messageDatabaseHelper.getThreadAdmins(offset, count, threadId, (obj, listData) -> {
List<Participant> participants = (List<Participant>) listData;
long participantCount = (long) obj;
if (participants != null) {
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setThreadId(threadId);
resultParticipant.setContentCount(participants.size());
resultParticipant.setHasNext(participants.size() + offset < participantCount);
resultParticipant.setParticipants(participants);
chatResponse.setResult(resultParticipant);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
chatResponse.setSubjectId(threadId);
resultParticipant.setNextOffset(offset + participants.size());
String jsonParticipant = gson.toJson(chatResponse);
OutPutParticipant outPutParticipant = new OutPutParticipant();
outPutParticipant.setResult(resultParticipant);
listenerManager.callOnGetThreadAdmin(jsonParticipant, chatResponse);
showLog("RECEIVE ADMINS FROM CACHE", jsonParticipant);
}
});
} catch (RoomIntegrityException e) {
disableCache();
}
}
use of com.fanap.podchat.model.ResultParticipant in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method loadParticipantsFromCache.
@SuppressWarnings("unchecked")
private void loadParticipantsFromCache(String uniqueId, int count, int offset, long threadId) {
try {
messageDatabaseHelper.getThreadParticipant(offset, count, threadId, (obj, listData) -> {
if (listData != null) {
List<Participant> participantsList = (List<Participant>) listData;
long participantCount = (long) obj;
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setContentCount(participantsList.size());
resultParticipant.setHasNext(participantsList.size() + offset < participantCount);
resultParticipant.setParticipants(participantsList);
chatResponse.setResult(resultParticipant);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
resultParticipant.setNextOffset(offset + participantsList.size());
String jsonParticipant = gson.toJson(chatResponse);
listenerManager.callOnGetThreadParticipant(jsonParticipant, chatResponse);
showLog("PARTICIPANT FROM CACHE", jsonParticipant);
}
});
} catch (RoomIntegrityException e) {
disableCache();
}
}
use of com.fanap.podchat.model.ResultParticipant in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatThreadParticipants.
private ChatResponse<ResultParticipant> reformatThreadParticipants(Callback callback, ChatMessage chatMessage) {
ArrayList<Participant> participants = new ArrayList<>();
if (!Util.isNullOrEmpty(chatMessage.getContent())) {
try {
participants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
}.getType());
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
if (cache) {
List<CacheParticipant> cacheParticipants = new ArrayList<>();
if (!Util.isNullOrEmpty(chatMessage.getContent())) {
try {
cacheParticipants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CacheParticipant>>() {
}.getType());
} catch (JsonSyntaxException e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
if (!cacheParticipants.isEmpty())
messageDatabaseHelper.saveParticipants(cacheParticipants, chatMessage.getSubjectId(), getExpireAmount());
}
ChatResponse<ResultParticipant> outPutParticipant = new ChatResponse<>();
outPutParticipant.setErrorCode(0);
outPutParticipant.setErrorMessage("");
outPutParticipant.setHasError(false);
outPutParticipant.setUniqueId(chatMessage.getUniqueId());
outPutParticipant.setSubjectId(chatMessage.getSubjectId());
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setThreadId(chatMessage.getSubjectId());
if (callback != null) {
resultParticipant.setHasNext(participants.size() + callback.getOffset() < chatMessage.getContentCount());
resultParticipant.setNextOffset(callback.getOffset() + participants.size());
}
resultParticipant.setParticipants(participants);
outPutParticipant.setResult(resultParticipant);
return outPutParticipant;
}
use of com.fanap.podchat.model.ResultParticipant in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method prepareSeenMessageListResponse.
public static ChatResponse<ResultParticipant> prepareSeenMessageListResponse(ChatMessage chatMessage, long offset) {
ChatResponse<ResultParticipant> chatResponse = new ChatResponse<>();
chatResponse.setUniqueId(chatMessage.getUniqueId());
ResultParticipant resultParticipant = new ResultParticipant();
List<Participant> participants = App.getGson().fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
}.getType());
resultParticipant.setParticipants(participants);
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setNextOffset(offset + participants.size());
resultParticipant.setContentCount(chatMessage.getContentCount());
if (participants.size() + offset < chatMessage.getContentCount()) {
resultParticipant.setHasNext(true);
} else {
resultParticipant.setHasNext(false);
}
chatResponse.setResult(resultParticipant);
return chatResponse;
}
use of com.fanap.podchat.model.ResultParticipant in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method reformatThreadParticipantsForRemove.
private ChatResponse<ResultParticipant> reformatThreadParticipantsForRemove(Callback callback, ChatMessage chatMessage) {
ArrayList<Participant> participants = new ArrayList<>();
if (!Util.isNullOrEmpty(chatMessage.getContent())) {
try {
participants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<Participant>>() {
}.getType());
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
if (cache) {
List<CacheParticipant> cacheParticipants = new ArrayList<>();
if (!Util.isNullOrEmpty(chatMessage.getContent())) {
try {
cacheParticipants = gson.fromJson(chatMessage.getContent(), new TypeToken<ArrayList<CacheParticipant>>() {
}.getType());
} catch (JsonSyntaxException e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
if (!cacheParticipants.isEmpty()) {
messageDatabaseHelper.deleteParticipant(chatMessage.getSubjectId(), cacheParticipants.get(0).getId());
}
}
ChatResponse<ResultParticipant> outPutParticipant = new ChatResponse<>();
outPutParticipant.setErrorCode(0);
outPutParticipant.setErrorMessage("");
outPutParticipant.setHasError(false);
outPutParticipant.setUniqueId(chatMessage.getUniqueId());
outPutParticipant.setSubjectId(chatMessage.getSubjectId());
ResultParticipant resultParticipant = new ResultParticipant();
resultParticipant.setContentCount(chatMessage.getContentCount());
resultParticipant.setThreadId(chatMessage.getSubjectId());
if (callback != null) {
resultParticipant.setHasNext(participants.size() + callback.getOffset() < chatMessage.getContentCount());
resultParticipant.setNextOffset(callback.getOffset() + participants.size());
}
resultParticipant.setParticipants(participants);
outPutParticipant.setResult(resultParticipant);
return outPutParticipant;
}
Aggregations