use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method forwardMessage.
/**
* forward message
*
* @param threadId destination thread id
* @param messageIds Array of message ids that we want to forward them
*/
public List<String> forwardMessage(long threadId, ArrayList<Long> messageIds) {
ArrayList<String> uniqueIds = new ArrayList<>();
ArrayList<Callback> callbacks = new ArrayList<>();
for (long messageId : messageIds) {
String uniqueId = generateUniqueId();
uniqueIds.add(uniqueId);
callbacks.add(MessageManager.generateCallback(uniqueId));
/*
* add to message Queue
* */
SendingQueueCache sendingQueue = MessageManager.generateSendingQueueCache(threadId, messageId, uniqueId, getTypeCode(), getToken());
insertToSendQueue(uniqueId, sendingQueue);
}
if (log)
Log.i(TAG, "Messages " + messageIds + "with this" + "uniqueIds" + uniqueIds + "has been added to Message Queue");
if (chatReady) {
threadCallbacks.put(threadId, callbacks);
String jsonUniqueIds = Util.listToJson(uniqueIds, gson);
String asyncContent = MessageManager.generateForwardMessage(threadId, messageIds.toString(), jsonUniqueIds, getTypeCode(), getToken());
for (String uniqueId : uniqueIds) {
moveFromSendingQueueToWaitQueue(uniqueId);
}
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_FORWARD_MESSAGE");
} else {
if (Util.isNullOrEmpty(uniqueIds)) {
for (String uniqueId : uniqueIds) {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
}
}
return uniqueIds;
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method addTagParticipant.
/**
* Add user tags participant
*/
public String addTagParticipant(AddTagParticipantRequest request) {
String uniqueId = generateUniqueId();
if (chatReady) {
String message = TagManager.createAddTagParticipantRequest(request, uniqueId);
sendAsyncMessage(message, AsyncAckType.Constants.WITHOUT_ACK, "ADD_TAG_PARTICIPANT");
Callback callbackTagParticipant = new Callback(request.getTagId());
messageCallbacks.put(uniqueId, callbackTagParticipant);
} else {
onChatNotReady(uniqueId);
}
return uniqueId;
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleSent.
private void handleSent(ChatMessage chatMessage, String messageUniqueId, long threadId) {
if (cache) {
dataSource.deleteWaitQueueWithUniqueId(messageUniqueId);
} else {
waitQList.remove(messageUniqueId);
}
boolean found = false;
try {
if (threadCallbacks.containsKey(threadId)) {
ArrayList<Callback> callbacks = threadCallbacks.get(threadId);
if (callbacks != null) {
for (Callback callback : callbacks) {
if (messageUniqueId.equals(callback.getUniqueId())) {
if (callback.isSent()) {
found = true;
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
ResultMessage resultMessage = new ResultMessage();
chatResponse.setErrorCode(0);
chatResponse.setErrorMessage("");
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setSubjectId(chatMessage.getSubjectId());
resultMessage.setConversationId(chatMessage.getSubjectId());
try {
resultMessage.setMessageId(Long.parseLong(chatMessage.getContent()));
} catch (NumberFormatException e) {
captureError(new PodChatException(e.getMessage(), messageUniqueId, getToken()));
resultMessage.setMessageId(0);
}
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnSentMessage(json, chatResponse);
runOnUIThread(() -> {
if (handlerSend.get(callback.getUniqueId()) != null) {
ChatHandler handler = handlerSend.get(callback.getUniqueId());
if (handler != null) {
handler.onSentResult(chatMessage.getContent());
}
}
});
Callback callbackUpdateSent = new Callback();
callbackUpdateSent.setSent(false);
callbackUpdateSent.setDelivery(callback.isDelivery());
callbackUpdateSent.setSeen(callback.isSeen());
callbackUpdateSent.setUniqueId(callback.getUniqueId());
callbacks.set(callbacks.indexOf(callback), callbackUpdateSent);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_SENT_MESSAGE", json);
} else {
showLog("RECEIVED_SENT_MESSAGE");
}
}
break;
}
}
}
}
if (!found) {
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
ResultMessage resultMessage = new ResultMessage();
chatResponse.setErrorCode(0);
chatResponse.setErrorMessage("");
chatResponse.setHasError(false);
chatResponse.setUniqueId(messageUniqueId);
chatResponse.setSubjectId(chatMessage.getSubjectId());
resultMessage.setConversationId(chatMessage.getSubjectId());
resultMessage.setMessageId(Long.parseLong(chatMessage.getContent()));
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnSentMessage(json, chatResponse);
// Log.d("MTAG", "threadid isn't in callbacks!");
runOnUIThread(() -> {
if (handlerSend.get(messageUniqueId) != null) {
handlerSend.get(messageUniqueId).onSentResult(chatMessage.getContent());
}
});
Callback callbackUpdateSent = new Callback();
callbackUpdateSent.setSent(false);
callbackUpdateSent.setUniqueId(messageUniqueId);
if (sentryResponseLog) {
showLog("RECEIVED_SENT_MESSAGE", json);
} else {
showLog("RECEIVED_SENT_MESSAGE");
}
}
} catch (Throwable e) {
showErrorLog(e.getMessage());
onUnknownException(chatMessage.getUniqueId(), e);
}
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class MessageManager method generateCallback.
public static Callback generateCallback(String uniqueId) {
Callback callback = new Callback();
callback.setDelivery(true);
callback.setSeen(true);
callback.setSent(true);
callback.setUniqueId(uniqueId);
return callback;
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class DbTest method updateCacheFirstMsgIdAndLastMsgId1.
// first messsage and last message
// cache is not empty but server is empty
@Test
public void updateCacheFirstMsgIdAndLastMsgId1() {
long threadId = 2;
Callback callback = new Callback();
List<MessageVO> messageVOS = new ArrayList<>();
callback.setOffset(0);
callback.setCount(50);
callback.setOrder("asc");
callback.setFirstMessageId(9234);
callback.setLastMessageId(9235);
messageDatabaseHelper.updateGetHistoryResponse(callback, messageVOS, threadId, null);
}
Aggregations