use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class ChatDbUtils method saveChatMessageAsATimeline.
/**
* This method saves the supplied
*
* @param msg
* @param type
* @param databaseHelper
*/
protected static void saveChatMessageAsATimeline(ChatMessage message, TimelineSummaryItem.Type type, DatabaseHelper databaseHelper) {
TimelineSummaryItem item = new TimelineSummaryItem();
fillInContactDetails(message, item, databaseHelper, type);
SQLiteDatabase writableDatabase = databaseHelper.getWritableDatabase();
boolean isRead = true;
if (type == TimelineSummaryItem.Type.INCOMING) {
isRead = false;
}
if (ActivitiesTable.addChatTimelineEvent(item, isRead, writableDatabase) != -1) {
ConversationsTable.addNewConversationId(message, writableDatabase);
} else {
LogUtils.logE("The msg was not saved to the ActivitiesTable");
}
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class ChatDbUtils method fillInContactDetails.
/**
* Remove hard code
*
* @param msg
* @param item
* @param databaseHelper
* @param incoming
*/
private static void fillInContactDetails(ChatMessage msg, TimelineSummaryItem item, DatabaseHelper databaseHelper, TimelineSummaryItem.Type incoming) {
item.mTimestamp = System.currentTimeMillis();
// here we set the time stamp back into the chat message
// in order to be able to remove it from the chat history by time stamp in case its delivery fails
msg.setTimeStamp(item.mTimestamp);
item.mType = ActivityItem.Type.MESSAGE_IM_CONVERSATION;
item.mDescription = msg.getBody();
item.mTitle = DateFormat.getDateInstance().format(new Date(item.mTimestamp));
// we store sender's localContactId for incoming msgs and recipient's
// localContactId for outgoing msgs
item.mLocalContactId = msg.getLocalContactId();
if (item.mLocalContactId != null && item.mLocalContactId != -1) {
ContactDetail cd = ContactDetailsTable.fetchDetail(item.mLocalContactId, DetailKeys.VCARD_NAME, databaseHelper.getReadableDatabase());
if (cd == null || cd.getName() == null) {
// if we don't get any details, we have to check the summary
// table because gtalk contacts
// without name will be otherwise show as unknown
ContactSummary contactSummary = new ContactSummary();
ServiceStatus error = ContactSummaryTable.fetchSummaryItem(item.mLocalContactId, contactSummary, databaseHelper.getReadableDatabase());
if (error == ServiceStatus.SUCCESS) {
item.mContactName = (contactSummary.formattedName != null) ? contactSummary.formattedName : ContactDetail.UNKNOWN_NAME;
} else {
item.mContactName = ContactDetail.UNKNOWN_NAME;
}
} else {
/**
* Get name from contact details. *
*/
VCardHelper.Name name = cd.getName();
item.mContactName = (name != null) ? name.toString() : ContactDetail.UNKNOWN_NAME;
}
}
item.mIncoming = incoming;
item.mContactNetwork = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString();
item.mNativeItemType = TimelineNativeTypes.ChatLog.ordinal();
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class ChatDbUtilsTest method testConvertUserId.
/**
* Test ChatDbUtils.convertUserIds() method with a given parameter
* combination.
*
* @param userId User ID.
* @param networkId Network ID.
* @param localContactId Local Contact ID.
* @param expectedUserId Expected User ID.
* @param expectedNetwork Expected Network ID.
* @param expectedLocalContactId Expected Local Contact ID.
*/
private void testConvertUserId(final String userId, final int networkId, final Long localContactId, final String expectedUserId, final SocialNetwork expectedNetwork, final Long expectedLocalContactId) {
ChatMessage chatMessage = new ChatMessage();
chatMessage.setUserId(userId);
chatMessage.setNetworkId(networkId);
chatMessage.setLocalContactId(localContactId);
ChatDbUtils.convertUserIds(chatMessage, mDatabaseHelper);
assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected user ID", expectedUserId, chatMessage.getUserId());
assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected network ID [" + expectedNetwork + "]", expectedNetwork.ordinal(), chatMessage.getNetworkId());
assertEquals("ChatDbUtilsTest.checkChatMessage() Unexpected local contact ID", expectedLocalContactId, chatMessage.getLocalContactId());
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class ChatDbUtils method convertUserIds.
/**
* Set the user ID, network ID and local contact ID values in the given
* ChatMessage.
*
* The original msg.getUserId() is formatted <network>::<userId>, meaning
* if "::" is present the values are split, otherwise the original value is
* used.
*
* @param chatMessage ChatMessage to be altered.
* @param databaseHelper DatabaseHelper with a readable database.
*/
public static void convertUserIds(final ChatMessage chatMessage, final DatabaseHelper databaseHelper) {
/**
* Use original User ID, in case of NumberFormatException (see
* PAND-2356).
*/
final String originalUserId = chatMessage.getUserId();
int index = originalUserId.indexOf(COLUMNS);
if (index > -1) {
/**
* Parse a <networkId>::<userId> formatted user ID. *
*/
chatMessage.setUserId(originalUserId.substring(index + COLUMNS.length()));
String network = originalUserId.substring(0, index);
/**
* Parse the <networkId> component. *
*/
SocialNetwork sn = SocialNetwork.getValue(network);
if (sn != null) {
chatMessage.setNetworkId(sn.ordinal());
} else {
chatMessage.setNetworkId(SocialNetwork.INVALID.ordinal());
LogUtils.logE("ChatUtils.convertUserIds() Invalid Network ID [" + network + "] in [" + originalUserId + "]");
}
}
chatMessage.setLocalContactId(ContactDetailsTable.findLocalContactIdByKey(SocialNetwork.getSocialNetworkValue(chatMessage.getNetworkId()).toString(), chatMessage.getUserId(), ContactDetail.DetailKeys.VCARD_IMADDRESS, databaseHelper.getReadableDatabase()));
}
use of com.vodafone360.people.datatypes.ChatMessage in project 360-Engine-for-Android by 360.
the class PresenceEngine method sendMessage.
/**
* This method should be used to send a message to a contact
*
* @param tos - tlocalContactId of ContactSummary items the message is
* intended for. Current protocol version only supports a single
* recipient.
* @param body the message text
*/
public void sendMessage(long toLocalContactId, String body, int networkId) {
if (ConnectionManager.getInstance().getConnectionState() != STATE_CONNECTED) {
LogUtils.logD("PresenceEnfgine.sendMessage: skip - NO NETWORK CONNECTION");
return;
}
ChatMessage msg = new ChatMessage();
msg.setBody(body);
msg.setNetworkId(networkId);
msg.setLocalContactId(toLocalContactId);
ChatDbUtils.fillMessageByLocalContactIdAndNetworkId(msg, mDbHelper);
if (msg.getConversationId() != null) {
String fullUserId = SocialNetwork.getSocialNetworkValue(msg.getNetworkId()).toString() + ChatDbUtils.COLUMNS + msg.getUserId();
msg.setUserId(fullUserId);
addUiRequestToQueue(ServiceUiRequest.SEND_CHAT_MESSAGE, msg);
} else {
// need start a new one
if (msg.getUserId() == null) {
ChatDbUtils.findUserIdForMessageByLocalContactIdAndNetworkId(msg, mDbHelper);
createConversation(msg);
}
}
}
Aggregations