use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method setThreadCallbacks.
private void setThreadCallbacks(long threadId, String uniqueId) {
try {
if (chatReady) {
Callback callback = new Callback();
callback.setDelivery(true);
callback.setSeen(true);
callback.setSent(true);
callback.setUniqueId(uniqueId);
ArrayList<Callback> callbackList = threadCallbacks.get(threadId);
if (!Util.isNullOrEmpty(callbackList)) {
callbackList.add(callback);
threadCallbacks.put(threadId, callbackList);
} else {
ArrayList<Callback> callbacks = new ArrayList<>();
callbacks.add(callback);
threadCallbacks.put(threadId, callbacks);
}
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method handleSeen.
private void handleSeen(ChatMessage chatMessage, String messageUniqueId, long threadId) {
if (threadCallbacks.containsKey(threadId)) {
ArrayList<Callback> callbacks = threadCallbacks.get(threadId);
if (callbacks != null) {
for (Callback callback : callbacks) {
if (messageUniqueId.equals(callback.getUniqueId())) {
int indexUnique = callbacks.indexOf(callback);
while (indexUnique > -1) {
if (callbacks.get(indexUnique).isSeen()) {
ResultMessage resultMessage = gson.fromJson(chatMessage.getContent(), ResultMessage.class);
if (callbacks.get(indexUnique).isDelivery()) {
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
chatResponse.setErrorMessage("");
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnDeliveryMessage(json, chatResponse);
Callback callbackUpdateSent = new Callback();
callbackUpdateSent.setSent(callback.isSent());
callbackUpdateSent.setDelivery(false);
callbackUpdateSent.setSeen(callback.isSeen());
callbackUpdateSent.setUniqueId(callback.getUniqueId());
callbacks.set(indexUnique, callbackUpdateSent);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_DELIVERED_MESSAGE", json);
} else {
showLog("RECEIVED_DELIVERED_MESSAGE");
}
}
ChatResponse<ResultMessage> chatResponse = new ChatResponse<>();
chatResponse.setErrorMessage("");
chatResponse.setErrorCode(0);
chatResponse.setHasError(false);
chatResponse.setUniqueId(callback.getUniqueId());
chatResponse.setResult(resultMessage);
String json = gson.toJson(chatResponse);
listenerManager.callOnSeenMessage(json, chatResponse);
callbacks.remove(indexUnique);
threadCallbacks.put(threadId, callbacks);
if (sentryResponseLog) {
showLog("RECEIVED_SEEN_MESSAGE", json);
} else {
showLog("RECEIVED_SEEN_MESSAGE");
}
}
indexUnique--;
}
break;
}
}
}
}
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method setCallBacks.
protected void setCallBacks(Boolean delivery, Boolean sent, Boolean seen, Boolean result, int requestType, Long offset, String uniqueId) {
try {
if (chatReady || asyncReady) {
delivery = delivery != null ? delivery : false;
sent = sent != null ? sent : false;
seen = seen != null ? seen : false;
result = result != null ? result : false;
offset = offset != null ? offset : 0;
Callback callback = new Callback();
callback.setDelivery(delivery);
callback.setOffset(offset);
callback.setSeen(seen);
callback.setSent(sent);
callback.setRequestType(requestType);
callback.setResult(result);
messageCallbacks.put(uniqueId, callback);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method onReceivedMessage.
/**
* First we check the message messageType and then we set the
* the callback for it.
* Here its showed the raw log.
*/
@Override
public void onReceivedMessage(String textMessage) throws IOException {
super.onReceivedMessage(textMessage);
int messageType = 0;
ChatMessage chatMessage = gson.fromJson(textMessage, ChatMessage.class);
if (rawLog) {
Log.i(TAG, "RAW_LOG");
Log.i(TAG, textMessage);
}
String messageUniqueId = chatMessage != null ? chatMessage.getUniqueId() : null;
long threadId = chatMessage != null ? chatMessage.getSubjectId() : 0;
Callback callback = null;
if (messageCallbacks.containsKey(messageUniqueId)) {
callback = messageCallbacks.get(messageUniqueId);
}
if (chatMessage != null) {
messageType = chatMessage.getType();
}
@Constants int currentMessageType = messageType;
switch(currentMessageType) {
case Constants.ADD_PARTICIPANT:
case Constants.SEEN_MESSAGE_LIST:
case Constants.DELIVERED_MESSAGE_LIST:
case Constants.UNBLOCK:
case Constants.GET_CONTACTS:
case Constants.MUTE_THREAD:
case Constants.GET_BLOCKED:
case Constants.RENAME:
case Constants.THREAD_PARTICIPANTS:
case Constants.UN_MUTE_THREAD:
case Constants.USER_INFO:
case Constants.LOCATION_PING:
case Constants.GET_ACTIVE_CALL_PARTICIPANTS:
handleResponseMessage(callback, chatMessage, messageUniqueId);
break;
case Constants.MUTE_CALL_PARTICIPANT:
{
handleOnCallParticipantMuted(callback, chatMessage);
break;
}
case Constants.UN_MUTE_CALL_PARTICIPANT:
{
handleOnCallParticipantUnMuted(callback, chatMessage);
break;
}
case Constants.CALL_CREATED:
if (callback != null)
handleOnCallCreated(chatMessage);
break;
case Constants.CONTACT_SYNCED:
{
handleOnContactsSynced(chatMessage);
break;
}
case Constants.CLOSE_THREAD:
{
handleOnThreadClosed(chatMessage);
break;
}
case Constants.CHANGE_THREAD_TYPE:
{
handleOnChangeThreadType(chatMessage);
break;
}
case Constants.CREATE_BOT:
{
handleOnBotCreated(chatMessage);
break;
}
case Constants.DEFINE_BOT_COMMAND:
{
handleOnBotCommandDefined(chatMessage);
break;
}
case Constants.START_BOT:
{
handleOnBotStarted(chatMessage);
break;
}
case Constants.GET_USER_BOTS:
{
handleOnUserBots(chatMessage);
break;
}
case Constants.STOP_BOT:
{
handleOnBotStopped(chatMessage);
break;
}
case Constants.REGISTER_FCM_USER_DEVICE:
{
PodNotificationManager.handleOnUserAndDeviceRegistered(chatMessage, context);
break;
}
case Constants.UPDATE_FCM_APP_USERS_DEVICE:
{
PodNotificationManager.handleOnFCMTokenRefreshed(chatMessage, context);
break;
}
case Constants.CALL_REQUEST:
handleOnCallRequestReceived(chatMessage);
break;
case Constants.GROUP_CALL_REQUEST:
handleOnGroupCallRequestReceived(chatMessage);
break;
case Constants.DELIVER_CALL_REQUEST:
handleOnCallRequestDelivered(chatMessage, callback);
break;
case Constants.REJECT_CALL:
handleOnCallRequestRejected(chatMessage);
break;
case Constants.CANCEL_GROUP_CALL:
handleOnCallParticipantCanceledCall(chatMessage);
break;
// todo: handle multiple device start call
case Constants.START_CALL:
handleOnCallStarted(callback, chatMessage);
break;
case Constants.END_CALL:
handleOnVoiceCallEnded(chatMessage);
break;
case Constants.LEAVE_CALL:
handleOnCallParticipantLeft(chatMessage);
break;
case Constants.CALL_PARTICIPANT_JOINED:
handleOnNewCallParticipantJoined(chatMessage);
break;
case Constants.REMOVE_CALL_PARTICIPANT:
handleOnCallParticipantRemoved(chatMessage);
break;
case Constants.TURN_ON_VIDEO_CALL:
handOnCallParticipantAddedVideo(chatMessage);
break;
case Constants.TURN_OFF_VIDEO_CALL:
handleOnCallParticipantRemovedVideo(chatMessage);
break;
case Constants.START_SHARE_SCREEN:
handOnShareScreenStarted(chatMessage, callback);
break;
case Constants.END_SHARE_SCREEN:
handOnShareScreenEnded(chatMessage, callback);
break;
case Constants.START_RECORD_CALL:
handleOnStartedCallRecord(chatMessage, callback);
break;
case Constants.END_RECORD_CALL:
handleOnEndedCallRecord(chatMessage, callback);
break;
case Constants.GET_CALLS:
handleOnGetCallsHistory(chatMessage, callback);
break;
case Constants.GET_CALLS_TO_JOIN:
handleOnGetActiveCalls(chatMessage, callback);
break;
case Constants.CALL_RECONNECT:
handleOnReceivedCallReconnect(chatMessage);
break;
case Constants.CALL_CONNECT:
handleOnReceivedCallConnect(chatMessage);
break;
case Constants.CALL_CLIENT_ERRORS:
handleOnReceivedClientCallErrors(chatMessage);
break;
case Constants.ALL_UNREAD_MESSAGE_COUNT:
handleOnGetUnreadMessagesCount(chatMessage);
break;
case Constants.IS_NAME_AVAILABLE:
handleIsNameAvailable(chatMessage);
break;
case Constants.JOIN_THREAD:
handleOnJoinPublicThread(chatMessage);
break;
case Constants.UPDATE_CHAT_PROFILE:
{
handleOnChatProfileUpdated(chatMessage);
break;
}
case Constants.REGISTER_ASSISTANT:
{
handleOnRegisterAssistant(chatMessage);
break;
}
case Constants.DEACTIVE_ASSISTANT:
{
handleOnDeActiveAssistant(chatMessage);
break;
}
case Constants.GET_ASSISTANTS:
{
handleOnGetAssistants(chatMessage);
break;
}
case Constants.GET_ASSISTANT_HISTORY:
{
handleOnGetAssistantHistory(chatMessage);
break;
}
case Constants.MUTUAL_GROUPS:
{
handleOnGetMutualGroups(chatMessage);
break;
}
case Constants.BLOCK_ASSISTANT:
{
handleOnAssistantBlocked(chatMessage);
break;
}
case Constants.UNBLOCK_ASSISTANT:
{
handleOnAssistantUnBlocked(chatMessage);
break;
}
case Constants.GET_BLOCKED_ASSISTANTS:
{
handleOnAssistantsBlocks(chatMessage);
break;
}
case Constants.GET_USER_ROLES:
{
handleOnGetUserRoles(chatMessage);
break;
}
case Constants.UPDATE_LAST_SEEN:
{
handleUpdateLastSeen(chatMessage);
break;
}
case Constants.PIN_MESSAGE:
{
handleOnPinMessage(chatMessage);
break;
}
case Constants.UNPIN_MESSAGE:
{
handleOnUnPinMessage(chatMessage);
break;
}
case Constants.EDIT_MESSAGE:
handleEditMessage(chatMessage, messageUniqueId);
break;
case Constants.DELETE_MESSAGE:
handleOutPutDeleteMsg(chatMessage);
break;
case Constants.UPDATE_THREAD_INFO:
handleUpdateThreadInfo(chatMessage, messageUniqueId, callback);
break;
case Constants.BLOCK:
handleOutPutBlock(chatMessage, messageUniqueId);
break;
case Constants.CHANGE_TYPE:
case Constants.USER_STATUS:
case Constants.RELATION_INFO:
case Constants.GET_STATUS:
break;
case Constants.CREATE_TAG:
handleOutPutAddTag(chatMessage, messageUniqueId);
break;
case Constants.EDIT_TAG:
handleOutPutEditTag(chatMessage, messageUniqueId);
break;
case Constants.DELETE_TAG:
handleOutPutDeleteTag(chatMessage, messageUniqueId);
break;
case Constants.ADD_TAG_PARTICIPANT:
if (callback != null)
handleOutPutAddParticipantTag(chatMessage, messageUniqueId, callback.getTagId());
break;
case Constants.ADD_CONTACT:
handleOutPutAddContact(chatMessage);
break;
case Constants.REMOVE_CONTACT:
if (callback != null)
handleOutPutRemoveContact(chatMessage, callback.getUserId());
break;
case Constants.REMOVE_TAG_PARTICIPANT:
if (callback != null)
handleOutPutRemoveParticipantTag(chatMessage, messageUniqueId, callback.getTagId());
break;
case Constants.GET_TAG_LIST:
handleOnTagList(chatMessage);
break;
case Constants.SENT:
handleSent(chatMessage, messageUniqueId, threadId);
break;
case Constants.DELIVERY:
handleDelivery(chatMessage, messageUniqueId, threadId);
break;
case Constants.SEEN:
handleSeen(chatMessage, messageUniqueId, threadId);
break;
case Constants.ERROR:
handleError(chatMessage);
break;
case Constants.FORWARD_MESSAGE:
handleForwardMessage(chatMessage);
break;
case Constants.GET_HISTORY:
/*Remove uniqueIds from waitQueue /***/
if (callback == null) {
if (hashTagCallBacks.get(messageUniqueId) != null) {
handleOnGetHashTagList(chatMessage);
hashTagCallBacks.remove(chatMessage.getUniqueId());
} else if (handlerSend.get(messageUniqueId) != null)
handleRemoveFromWaitQueue(chatMessage);
else
handleOnGetMentionList(chatMessage);
} else {
handleOnGetThreadHistory(callback, chatMessage);
}
break;
case Constants.GET_THREADS:
{
if (threadInfoCompletor.containsKey(messageUniqueId)) {
threadInfoCompletor.get(messageUniqueId).onThreadInfoReceived(chatMessage);
} else if (callback == null) {
handleGetThreads(null, chatMessage, messageUniqueId);
} else
handleResponseMessage(callback, chatMessage, messageUniqueId);
break;
}
case Constants.INVITATION:
if (callback == null) {
handleCreateThread(chatMessage, messageUniqueId);
} else
handleResponseMessage(callback, chatMessage, messageUniqueId);
break;
case Constants.REMOVED_FROM_THREAD:
handleRemoveFromThread(chatMessage);
break;
case Constants.LEAVE_THREAD:
handleOutPutLeaveThread(null, chatMessage, messageUniqueId);
break;
case Constants.MESSAGE:
{
handleNewMessage(chatMessage);
break;
}
case Constants.PING:
handleOnPing(chatMessage);
break;
case Constants.REMOVE_PARTICIPANT:
if (callback == null) {
handleOutPutRemoveParticipant(null, chatMessage, messageUniqueId);
} else
handleResponseMessage(callback, chatMessage, messageUniqueId);
break;
case Constants.THREAD_INFO_UPDATED:
handleThreadInfoUpdated(chatMessage);
break;
case Constants.LAST_MESSAGE_DELETED:
{
handleOnLastMessageDeleted(chatMessage);
break;
}
case Constants.LAST_MESSAGE_EDITED:
{
handleOnLastMessageEdited(chatMessage);
break;
}
case Constants.LAST_SEEN_UPDATED:
handleLastSeenUpdated(chatMessage);
break;
case Constants.SPAM_PV_THREAD:
handleOutPutSpamPVThread(chatMessage, messageUniqueId);
break;
case Constants.SET_ROLE_TO_USER:
handleSetRole(chatMessage);
break;
case Constants.REMOVE_ROLE_FROM_USER:
handleRemoveRole(chatMessage);
break;
case Constants.CLEAR_HISTORY:
handleClearHistory(chatMessage);
break;
case Constants.PIN_THREAD:
handleOnPinThread(chatMessage);
break;
case Constants.UNPIN_THREAD:
handOnUnPinThread(chatMessage);
break;
case Constants.GET_NOT_SEEN_DURATION:
handleGetNotSeenDuration(callback, chatMessage, messageUniqueId);
break;
case Constants.SYSTEM_MESSAGE:
handleSystemMessage(callback, chatMessage, messageUniqueId);
break;
}
}
use of com.fanap.podchat.util.Callback in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method removeTagParticipant.
/**
* Remove user tags participant
*/
public String removeTagParticipant(RemoveTagParticipantRequest request) {
String uniqueId = generateUniqueId();
if (chatReady) {
String message = TagManager.createRemoveTagParticipantRequest(request, uniqueId);
sendAsyncMessage(message, AsyncAckType.Constants.WITHOUT_ACK, "REMOVE_TAG_PARTICIPANT");
Callback callbackTagParticipant = new Callback(request.getTagId());
messageCallbacks.put(uniqueId, callbackTagParticipant);
} else {
onChatNotReady(uniqueId);
}
return uniqueId;
}
Aggregations