use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.
the class XmppConnection method handleChatState.
private void handleChatState(String from, String chatStateXml) throws RemoteException {
Presence p = null;
Contact contact = mContactListManager.getContact(from);
if (contact == null)
return;
boolean isTyping = false;
// handle is-typing, probably some indication on screen
if (chatStateXml.contains("'error'") || chatStateXml.contains("'cancel'")) {
// do nothing
} else if (chatStateXml.contains(ChatState.active.toString())) {
p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
p.setLastSeen(new Date());
} else if (chatStateXml.contains(ChatState.inactive.toString())) {
p = new Presence(Presence.AWAY, "", null, null, Presence.CLIENT_TYPE_MOBILE);
p.setLastSeen(new Date());
} else if (chatStateXml.contains(ChatState.composing.toString())) {
p = new Presence(Presence.AVAILABLE, "", null, null, Presence.CLIENT_TYPE_MOBILE);
isTyping = true;
p.setLastSeen(new Date());
} else if (chatStateXml.contains(ChatState.inactive.toString()) || chatStateXml.contains(ChatState.paused.toString())) {
} else if (chatStateXml.contains(ChatState.gone.toString())) {
}
IChatSession csa = mSessionManager.getAdapter().getChatSession(from);
if (csa != null)
csa.setContactTyping(contact, isTyping);
if (p != null) {
String[] presenceParts = from.split("/");
if (presenceParts.length > 1)
p.setResource(presenceParts[1]);
contact.setPresence(p);
Collection<Contact> contactsUpdate = new ArrayList<Contact>();
contactsUpdate.add(contact);
mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
}
}
use of org.awesomeapp.messenger.service.IChatSession in project Zom-Android by zom.
the class ChatSessionManagerAdapter method createChatSession.
public IChatSession createChatSession(String contactAddress, boolean isNewSession) {
ContactListManagerAdapter listManager = (ContactListManagerAdapter) mConnection.getContactListManager();
Contact contact = listManager.getContactByAddress(Address.stripResource(contactAddress));
if (contact == null) {
try {
contact = new Contact(new XmppAddress(contactAddress), contactAddress, Imps.Contacts.TYPE_NORMAL);
// long contactId = listManager.queryOrInsertContact(contact);
// String[] address = {Address.stripResource(contactAddress)};
// contact = listManager.createTemporaryContacts(address)[0];
} catch (IllegalArgumentException e) {
mSessionListenerAdapter.notifyChatSessionCreateFailed(contactAddress, new ImErrorInfo(ImErrorInfo.ILLEGAL_CONTACT_ADDRESS, "Invalid contact address:" + contactAddress));
return null;
}
}
if (contact != null) {
ChatSession session = getChatSessionManager().createChatSession(contact, isNewSession);
return getChatSessionAdapter(session, isNewSession);
} else
return null;
}
Aggregations