use of org.awesomeapp.messenger.model.ContactList in project Zom-Android by zom.
the class XmppConnection method initNewContactProcessor.
private void initNewContactProcessor() {
mTimerNewContacts = new Timer();
mTimerNewContacts.scheduleAtFixedRate(new TimerTask() {
public void run() {
try {
Contact contact = null;
if (qNewContact.size() > 0)
while (qNewContact.peek() != null) {
contact = qNewContact.poll();
if (mConnection == null || (!mConnection.isConnected())) {
debug(TAG, "postponed adding new contact" + " because we are not connected");
// return the packet to the stack
qNewContact.add(contact);
return;
} else {
try {
RosterEntry rEntry;
ContactList list = mContactListManager.getDefaultContactList();
String[] groups = new String[] { list.getName() };
BareJid jid = JidCreate.bareFrom(contact.getAddress().getBareAddress());
rEntry = mRoster.getEntry(jid);
RosterGroup rGroup = mRoster.getGroup(list.getName());
if (rGroup == null) {
if (rEntry == null) {
mRoster.createEntry(jid, contact.getName(), groups);
while ((rEntry = mRoster.getEntry(jid)) == null) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
} else if (rEntry == null) {
mRoster.createEntry(jid, contact.getName(), groups);
while ((rEntry = mRoster.getEntry(jid)) == null) {
try {
Thread.sleep(500);
} catch (Exception e) {
}
}
}
int subStatus = Imps.Contacts.SUBSCRIPTION_STATUS_NONE;
if (rEntry.isSubscriptionPending())
subStatus = Imps.Contacts.SUBSCRIPTION_STATUS_SUBSCRIBE_PENDING;
int subType = Imps.Contacts.SUBSCRIPTION_TYPE_NONE;
if (rEntry.canSeeHisPresence() && rEntry.canSeeMyPresence()) {
subType = Imps.Contacts.SUBSCRIPTION_TYPE_BOTH;
} else if (rEntry.canSeeHisPresence()) {
subType = Imps.Contacts.SUBSCRIPTION_TYPE_FROM;
if (rEntry.isSubscriptionPending()) {
try {
handleSubscribeRequest(rEntry.getJid());
} catch (Exception e) {
debug(TAG, "Error requesting subscribe notification", e);
}
}
} else if (rEntry.canSeeMyPresence()) {
// it is still pending
subType = Imps.Contacts.SUBSCRIPTION_TYPE_TO;
}
contact.setSubscriptionType(subType);
contact.setSubscriptionStatus(subStatus);
try {
mContactListManager.getSubscriptionRequestListener().onSubScriptionChanged(contact, mProviderId, mAccountId, subType, subStatus);
} catch (Exception e) {
}
} catch (XMPPException e) {
debug(TAG, "error updating remote roster", e);
// try again later
qNewContact.add(contact);
} catch (Exception e) {
String msg = "Not logged in to server while updating remote roster";
debug(TAG, msg, e);
// try again later
qNewContact.add(contact);
}
}
}
} catch (Exception e) {
Log.e(TAG, "error sending packet", e);
}
}
}, 500, 500);
}
use of org.awesomeapp.messenger.model.ContactList in project Zom-Android by zom.
the class LoopbackConnection method doUpdateUserPresenceAsync.
@Override
protected void doUpdateUserPresenceAsync(Presence presence) {
// mimic presence
ContactList cl;
try {
cl = mContactListManager.getDefaultContactList();
} catch (ImException e) {
throw new RuntimeException(e);
}
if (cl == null)
return;
Collection<Contact> contacts = cl.getContacts();
for (Iterator<Contact> iter = contacts.iterator(); iter.hasNext(); ) {
Contact contact = iter.next();
contact.setPresence(presence);
}
Contact[] contacts_array = new Contact[contacts.size()];
contacts.toArray(contacts_array);
mContactListManager.doPresence(contacts_array);
}
use of org.awesomeapp.messenger.model.ContactList 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.ContactList 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);
}
Aggregations