use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class XmppConnection method makeContact.
private Contact makeContact(String address) {
Contact contact = null;
// load from roster if we don't have the contact
RosterEntry rEntry = null;
try {
if (mConnection != null)
rEntry = mRoster.getEntry(JidCreate.bareFrom(address));
if (rEntry != null) {
XmppAddress xAddress = new XmppAddress(address);
String name = rEntry.getName();
if (name == null)
name = xAddress.getUser();
// TODO we should check the type from here
contact = new Contact(xAddress, name, Imps.Contacts.TYPE_NORMAL);
} else {
XmppAddress xAddress = new XmppAddress(address);
contact = new Contact(xAddress, xAddress.getUser(), Imps.Contacts.TYPE_NORMAL);
}
} catch (XmppStringprepException xe) {
// nothing return null;
}
return contact;
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class XmppConnection method handleSubscribeRequest.
private void handleSubscribeRequest(Jid jid) throws ImException, RemoteException {
Contact contact = mContactListManager.getContact(jid.asBareJid().toString());
if (contact == null) {
XmppAddress xAddr = new XmppAddress(jid.toString());
contact = new Contact(xAddr, xAddr.getUser(), Imps.Contacts.TYPE_NORMAL);
}
if (contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_BOTH || contact.getSubscriptionType() == Imps.Contacts.SUBSCRIPTION_TYPE_TO) {
mContactListManager.approveSubscriptionRequest(contact);
} else {
ContactList cList = getContactListManager().getDefaultContactList();
contact.setSubscriptionStatus(Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING);
contact.setSubscriptionType(Imps.Contacts.SUBSCRIPTION_TYPE_FROM);
mContactListManager.doAddContactToListAsync(contact, cList, false);
mContactListManager.getSubscriptionRequestListener().onSubScriptionRequest(contact, mProviderId, mAccountId);
}
ChatSession session = findOrCreateSession(jid.toString(), false);
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class XmppConnection method handlePresenceChanged.
private Contact handlePresenceChanged(org.jivesoftware.smack.packet.Presence presence) {
if (// our presence isn't really valid
presence == null)
return null;
if (TextUtils.isEmpty(presence.getFrom()))
return null;
if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.error)
return null;
if (// ignore presence from yourself
presence.getFrom().toString().startsWith(mUser.getAddress().getBareAddress()))
return null;
XmppAddress xaddress = new XmppAddress(presence.getFrom().toString());
Presence p = new Presence(parsePresence(presence), presence.getStatus(), null, null, Presence.CLIENT_TYPE_MOBILE, null, xaddress.getResource());
// this is only persisted in memory
p.setPriority(presence.getPriority());
if (mContactListManager == null)
// we may have logged out
return null;
Contact contact = mContactListManager.getContact(xaddress.getBareAddress());
BareJid jid = presence.getFrom().asBareJid();
if (presence.getFrom().hasResource())
p.setResource(presence.getFrom().getResourceOrEmpty().toString());
if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.subscribe) {
debug(TAG, "got subscribe request: " + presence.getFrom());
try {
handleSubscribeRequest(presence.getFrom());
} catch (Exception e) {
Log.e(TAG, "remote exception on subscription handling", e);
}
} else if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.subscribed) {
debug(TAG, "got subscribed confirmation: " + presence.getFrom());
try {
if (contact == null) {
XmppAddress xAddr = new XmppAddress(presence.getFrom().toString());
contact = new Contact(xAddr, xAddr.getUser(), Imps.Contacts.TYPE_NORMAL);
mContactListManager.doAddContactToListAsync(contact, getContactListManager().getDefaultContactList(), false);
}
if (contact.getSubscriptionStatus() == Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING) {
mContactListManager.approveSubscriptionRequest(contact);
mContactListManager.getSubscriptionRequestListener().onSubscriptionApproved(contact, mProviderId, mAccountId);
}
if (getOmemo().getManager().contactSupportsOmemo(jid)) {
getOmemo().getManager().requestDeviceListUpdateFor(jid);
getOmemo().getManager().buildSessionsWith(jid);
}
} catch (Exception e) {
Log.e(TAG, "remote exception on subscription handling", e);
}
} else if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.unsubscribe) {
debug(TAG, "got unsubscribe request: " + presence.getFrom());
// TBD how to handle this
// mContactListManager.getSubscriptionRequestListener().onUnSubScriptionRequest(contact);
} else if (presence.getType() == org.jivesoftware.smack.packet.Presence.Type.unsubscribed) {
debug(TAG, "got unsubscribe request: " + presence.getFrom());
try {
mContactListManager.getSubscriptionRequestListener().onSubscriptionDeclined(contact, mProviderId, mAccountId);
} catch (RemoteException e) {
Log.e(TAG, "remote exception on subscription handling", e);
}
}
// this is typical presence, let's get the latest/highest priority
debug(TAG, "got presence: " + presence.getFrom() + "=" + presence.getType());
if (contact != null) {
if (contact.getPresence() != null) {
Presence pOld = contact.getPresence();
if (pOld != null && pOld.getLastSeen() != null && p.getLastSeen() == null)
p.setLastSeen(pOld.getLastSeen());
if (pOld == null || pOld.getResource() == null) {
contact.setPresence(p);
} else if (// if the same resource as the existing one, then update it
pOld.getResource() != null && pOld.getResource().equals(p.getResource())) {
contact.setPresence(p);
} else if (// if priority is higher, then override
p.getPriority() >= pOld.getPriority()) {
contact.setPresence(p);
}
} else
contact.setPresence(p);
if (contact.getPresence().getLastSeen() == null) {
getLastSeen(contact);
}
ExtensionElement packetExtension = presence.getExtension("x", "vcard-temp:x:update");
if (packetExtension != null) {
StandardExtensionElement o = (StandardExtensionElement) packetExtension;
String hash = o.getAttributeValue("photo");
if (hash != null) {
boolean hasMatches = DatabaseUtils.doesAvatarHashExist(mContext.getContentResolver(), Imps.Avatars.CONTENT_URI, contact.getAddress().getBareAddress(), hash);
if (// we must reload
!hasMatches)
qAvatar.put(contact.getAddress().getAddress(), hash);
} else {
for (StandardExtensionElement element : o.getElements()) {
if (element.getElementName().equals("photo")) {
hash = element.getText();
if (hash != null) {
boolean hasMatches = DatabaseUtils.doesAvatarHashExist(mContext.getContentResolver(), Imps.Avatars.CONTENT_URI, contact.getAddress().getBareAddress(), hash);
if (// we must reload
!hasMatches)
qAvatar.put(contact.getAddress().getAddress(), hash);
}
break;
}
}
}
} else {
boolean hasAvatar = DatabaseUtils.hasAvatarContact(mContext.getContentResolver(), Imps.Avatars.CONTENT_URI, contact.getAddress().getBareAddress());
if (!hasAvatar) {
qAvatar.put(contact.getAddress().getAddress(), "");
}
}
}
return contact;
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class XmppConnection method initPresenceProcessor.
private void initPresenceProcessor() {
mTimerPresence = new Timer();
mTimerPresence.schedule(new TimerTask() {
public void run() {
if (qPresence.size() > 0) {
try {
ContactList cList = getContactListManager().getDefaultContactList();
if (cList == null)
// not ready yet
return;
} catch (Exception e) {
// not ready yet
return;
}
Map<String, Contact> alUpdate = new HashMap<String, Contact>();
org.jivesoftware.smack.packet.Presence p = null;
Contact contact = null;
final int maxBatch = 20;
while (qPresence.peek() != null && alUpdate.size() < maxBatch) {
p = qPresence.poll();
contact = handlePresenceChanged(p);
if (contact != null) {
alUpdate.put(contact.getAddress().getBareAddress(), contact);
}
}
if (alUpdate.size() > 0) {
loadVCardsAsync();
// Log.d(TAG,"XMPP processed presence q=" + alUpdate.size());
Collection<Contact> contactsUpdate = alUpdate.values();
if (mContactListManager != null)
mContactListManager.notifyContactsPresenceUpdated(contactsUpdate.toArray(new Contact[contactsUpdate.size()]));
}
}
}
}, 500, 500);
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class ChatSessionAdapter method initOtrChatSession.
private void initOtrChatSession(ImEntity participant) {
try {
if (mConnection != null) {
mDataHandler = new OtrDataHandler(mChatSession);
mDataHandler.setDataListener(mDataHandlerListener);
OtrChatManager cm = service.getOtrChatManager();
cm.addOtrEngineListener(mListenerAdapter);
mChatSession.setMessageListener(new OtrChatListener(cm, mListenerAdapter));
if (participant instanceof Contact) {
String key = participant.getAddress().getAddress();
if (!mOtrChatSessions.containsKey(key)) {
OtrChatSessionAdapter adapter = new OtrChatSessionAdapter(mConnection.getLoginUser().getAddress().getAddress(), participant, cm);
mOtrChatSessions.put(key, adapter);
}
} else if (participant instanceof ChatGroup) {
}
mDataHandler.setChatId(getId());
}
} catch (NullPointerException npe) {
Log.e(ImApp.LOG_TAG, "error init OTR session", npe);
}
}
Aggregations