use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class PresenceEngine method handleNewConversationId.
private void handleNewConversationId(Conversation conversation) {
if (conversation.getTos() != null) {
String to = conversation.getTos().get(0);
if (mSendMessagesHash.containsKey(to)) {
ChatMessage message = mSendMessagesHash.get(to);
message.setConversationId(conversation.getConversationId());
/**
* Update the DB with an outgoing message. *
*/
updateChatDatabase(message, TimelineSummaryItem.Type.OUTGOING);
Chat.sendChatMessage(message);
// clean check if DB needs a cleaning (except for
// the current conversation id)
ChatDbUtils.cleanOldConversationsExceptForContact(message.getLocalContactId(), mDbHelper);
}
}
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class PresenceEngine method updateChatDatabase.
/**
* Updates the database with the given ChatMessage and Type.
*
* @param message ChatMessage.
* @param type TimelineSummaryItem.Type.
*/
private void updateChatDatabase(ChatMessage message, TimelineSummaryItem.Type type) {
ChatDbUtils.convertUserIds(message, mDbHelper);
LogUtils.logD("PresenceEngine.updateChatDatabase() with [" + type.name() + "] message");
if (message.getLocalContactId() == null || message.getLocalContactId() < 0) {
LogUtils.logE("PresenceEngine.updateChatDatabase() " + "WILL NOT UPDATE THE DB! - INVALID localContactId = " + message.getLocalContactId());
return;
}
/**
* We mark all incoming messages as unread. *
*/
ChatDbUtils.saveChatMessageAsATimeline(message, type, mDbHelper);
UiAgent uiAgent = mEventCallback.getUiAgent();
if (uiAgent != null && (message.getLocalContactId() != -1)) {
uiAgent.updateChat(message.getLocalContactId(), true, message.getNetworkId());
}
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class PresenceEngine method processUiRequest.
@Override
protected void processUiRequest(ServiceUiRequest requestId, Object data) {
if (!isFirstTimeSyncComplete()) {
LogUtils.logE("PresenceEngine.processUIRequest():" + " Can't run PresenceEngine before the contact list is downloaded:1");
return;
}
LogUtils.logW("PresenceEngine.processUiRequest() requestId.name[" + requestId.name() + "]");
if (data == null && requestId != ServiceUiRequest.GET_PRESENCE_LIST) {
LogUtils.logW("PresenceEngine.processUiRequest() skipping processing for request with no data!");
return;
}
switch(requestId) {
case SET_MY_AVAILABILITY:
Hashtable<String, String> presenceHash = (Hashtable<String, String>) data;
notifyUiAgentOfRequest(Presence.setMyAvailability(presenceHash), presenceHash);
break;
case GET_PRESENCE_LIST:
Presence.getPresenceList(EngineId.PRESENCE_ENGINE, null);
break;
case CREATE_CONVERSATION:
List<String> tos = ((ChatMessage) data).getTos();
LogUtils.logW("PresenceEngine processUiRequest() CREATE_CONVERSATION with: " + tos);
Chat.startChat(tos);
break;
case SEND_CHAT_MESSAGE:
ChatMessage msg = (ChatMessage) data;
updateChatDatabase(msg, TimelineSummaryItem.Type.OUTGOING);
// cache the message (necessary for failed message sending failures)
mSendMessagesHash.put(msg.getTos().get(0), msg);
Chat.sendChatMessage(msg);
break;
default:
LogUtils.logE("PresenceEngine processUiRequest() Unhandled UI request [" + requestId.name() + "]");
// don't complete with success and schedule the next runtime
return;
}
completeUiRequest(ServiceStatus.SUCCESS, null);
setTimeout(CHECK_FREQUENCY);
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class PresenceEngine method handleSystemNotification.
private void handleSystemNotification(SystemNotification sn) {
LogUtils.logE("PresenceEngine.handleServerResponse(): " + sn);
switch(sn.getSysCode()) {
case SEND_MESSAGE_FAILED:
ChatMessage msg = mSendMessagesHash.get(sn.getInfo().get(Tags.TOS.toString()));
if (msg != null) {
ChatDbUtils.deleteUnsentMessage(mDbHelper, msg);
}
showErrorNotification(ServiceUiRequest.UNSOLICITED_CHAT_ERROR_REFRESH, null);
break;
case CONVERSATION_NULL:
if (!mSendMessagesHash.isEmpty()) {
mSendMessagesHash.remove(sn.getInfo().get(Tags.TOS.toString()));
}
showErrorNotification(ServiceUiRequest.UNSOLICITED_CHAT_ERROR, null);
break;
case COMMUNITY_LOGOUT_SUCCESSFUL:
break;
default:
LogUtils.logE("PresenceEngine.handleServerResponse()" + " - unhandled notification: " + sn);
}
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class Chat method sendChatMessage.
// function?
/**
* Sends chat message to server
*
* @param msg - ChatMessage to be sent
* @return request id
*/
public static int sendChatMessage(ChatMessage msg) {
if (msg.getTos() == null) {
LogUtils.logE("Chat.sentChatMessage() msg.mTos can't be null");
return -1;
}
if (msg.getBody() == null) {
LogUtils.logE("Chat.sentChatMessage() msg.mBody can't be null");
return -1;
}
if (msg.getConversationId() == null) {
LogUtils.logE("Chat.sentChatMessage() msg.mConversationId can't be null");
return -1;
}
Request request = new Request(EMPTY, Request.Type.SEND_CHAT_MESSAGE, EngineId.PRESENCE_ENGINE, true, Settings.API_REQUESTS_TIMEOUT_CHAT_SEND_MESSAGE);
request.addData(ChatMessage.Tags.BODY.tag(), msg.getBody());
request.addData(ChatMessage.Tags.RECIPIENTS_LIST.tag(), msg.getTos());
request.addData(ChatMessage.Tags.CONVERSATION_ID.tag(), msg.getConversationId());
QueueManager queue = QueueManager.getInstance();
int requestId = queue.addRequest(request);
queue.fireQueueStateChanged();
return requestId;
}
Aggregations