use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method clearHistory.
public String clearHistory(RequestClearHistory requestClearHistory) {
String uniqueId = generateUniqueId();
long threadId = requestClearHistory.getThreadId();
if (chatReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.CLEAR_HISTORY);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
chatMessage.setSubjectId(threadId);
chatMessage.setUniqueId(uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
jsonObject.remove("systemMetadata");
jsonObject.remove("metadata");
jsonObject.remove("repliedTo");
jsonObject.remove("contentCount");
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, true, Constants.CLEAR_HISTORY, null, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_CLEAR_HISTORY");
}
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getChatMessage.
@NonNull
private ChatMessage getChatMessage(String contentThreadChat, String uniqueId, String typeCode) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setContent(contentThreadChat);
chatMessage.setType(Constants.INVITATION);
chatMessage.setToken(getToken());
chatMessage.setUniqueId(uniqueId);
chatMessage.setTokenIssuer("1");
if (typeCode != null && !typeCode.isEmpty()) {
chatMessage.setTypeCode(typeCode);
} else {
chatMessage.setTypeCode(getTypeCode());
}
return chatMessage;
}
use of com.fanap.podchat.mainmodel.ChatMessage 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.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method getUserInfo.
/**
* It Gets the information of the current user
*/
public String getUserInfo(ChatHandler handler) {
String uniqueId = generateUniqueId();
Runnable cacheLoading = () -> {
if (permit && cache && handler != null) {
try {
UserInfo userInfo = messageDatabaseHelper.getUserInfo();
if (userInfo != null) {
ChatResponse<ResultUserInfo> chatResponse = new ChatResponse<>();
ResultUserInfo result = new ResultUserInfo();
setUserId(userInfo.getId());
result.setUser(userInfo);
chatResponse.setResult(result);
chatResponse.setCache(true);
chatResponse.setUniqueId(uniqueId);
String userInfoJson = gson.toJson(chatResponse);
listenerManager.callOnUserInfo(userInfoJson, chatResponse);
showLog("CACHE_USER_INFO", userInfoJson);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
}
};
Runnable requestServer = () -> {
if (asyncReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.USER_INFO);
chatMessage.setUniqueId(uniqueId);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
setCallBacks(null, null, null, true, Constants.USER_INFO, null, uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
showLog("SEND_USER_INFO", asyncContent);
async.sendMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK);
if (handler != null) {
handler.onGetUserInfo(uniqueId);
}
}
};
new PodThreadManager().addNewTask(cacheLoading).addNewTask(requestServer).runTasksSynced();
return uniqueId;
}
use of com.fanap.podchat.mainmodel.ChatMessage in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method unMuteThread.
/**
* Un mute the thread so notification is on for that thread
*/
public String unMuteThread(long threadId, ChatHandler handler) {
String uniqueId;
uniqueId = generateUniqueId();
try {
if (chatReady) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setType(Constants.UN_MUTE_THREAD);
chatMessage.setToken(getToken());
chatMessage.setTokenIssuer("1");
chatMessage.setSubjectId(threadId);
chatMessage.setUniqueId(uniqueId);
JsonObject jsonObject = (JsonObject) gson.toJsonTree(chatMessage);
if (Util.isNullOrEmpty(getTypeCode())) {
jsonObject.remove("typeCode");
} else {
jsonObject.remove("typeCode");
jsonObject.addProperty("typeCode", getTypeCode());
}
String asyncContent = jsonObject.toString();
setCallBacks(null, null, null, true, Constants.UN_MUTE_THREAD, null, uniqueId);
sendAsyncMessage(asyncContent, AsyncAckType.Constants.WITHOUT_ACK, "SEND_UN_MUTE_THREAD");
if (handler != null) {
handler.onUnMuteThread(uniqueId);
}
} else {
captureError(ChatConstant.ERROR_CHAT_READY, ChatConstant.ERROR_CODE_CHAT_READY, uniqueId);
}
} catch (Exception e) {
showErrorLog(e.getMessage());
onUnknownException(uniqueId, e);
}
return uniqueId;
}
Aggregations