use of org.awesomeapp.messenger.model.Contact 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.Contact in project Zom-Android by zom.
the class XmppConnection method loadVCard.
private boolean loadVCard(ContentResolver resolver, String jid) {
try {
debug(TAG, "loading vcard for: " + jid);
EntityBareJid bareJid = JidCreate.entityBareFrom(jid);
VCardManager vCardManager = VCardManager.getInstanceFor(mConnection);
VCard vCard = vCardManager.loadVCard(bareJid);
Contact contact = mContactListManager.getContact(bareJid.toString());
if (!TextUtils.isEmpty(vCard.getNickName())) {
if (!vCard.getNickName().equals(contact.getName())) {
contact.setName(vCard.getNickName());
mContactListManager.doSetContactName(contact.getAddress().getBareAddress(), contact.getName());
}
}
// check for a forwarding address
if (vCard.getJabberId() != null && (!vCard.getJabberId().equals(bareJid.toString()))) {
contact.setForwardingAddress(vCard.getJabberId());
} else {
contact.setForwardingAddress(null);
}
// If VCard is loaded, then save the avatar to the personal folder.
String avatarHash = vCard.getAvatarHash();
if (avatarHash != null) {
byte[] avatarBytes = vCard.getAvatar();
if (avatarBytes != null) {
debug(TAG, "found avatar image in vcard for: " + bareJid.toString());
debug(TAG, "start avatar length: " + avatarBytes.length);
int rowsUpdated = DatabaseUtils.updateAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, avatarBytes, bareJid.toString());
if (rowsUpdated <= 0)
DatabaseUtils.insertAvatarBlob(resolver, Imps.Avatars.CONTENT_URI, mProviderId, mAccountId, avatarBytes, avatarHash, bareJid.toString());
return true;
}
}
} catch (Exception e) {
debug(TAG, "err loading vcard: " + e.toString());
if (e.getMessage() != null) {
String streamErr = e.getMessage();
if (streamErr != null && (streamErr.contains("404") || streamErr.contains("503"))) {
return false;
}
}
}
return false;
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class XmppConnection method makeUser.
private synchronized Contact makeUser(Imps.ProviderSettings.QueryMap providerSettings, ContentResolver contentResolver) {
Contact contactUser = null;
String nickname = Imps.Account.getNickname(contentResolver, mAccountId);
String userName = Imps.Account.getUserName(contentResolver, mAccountId);
String domain = providerSettings.getDomain();
String xmppName = userName + '@' + domain + '/' + providerSettings.getXmppResource();
contactUser = new Contact(new XmppAddress(xmppName), nickname, Imps.Contacts.TYPE_NORMAL);
return contactUser;
}
use of org.awesomeapp.messenger.model.Contact in project Zom-Android by zom.
the class ImUrlActivity method startChat.
public void startChat(long providerId, long accountId, String username, final boolean openChat) {
if (username != null)
new ChatSessionInitTask(((ImApp) getApplication()), providerId, accountId, Imps.Contacts.TYPE_NORMAL, true) {
@Override
protected void onPostExecute(Long chatId) {
if (chatId != -1 && openChat) {
Intent intent = new Intent(ImUrlActivity.this, ConversationDetailActivity.class);
intent.putExtra("id", chatId);
startActivity(intent);
}
finish();
super.onPostExecute(chatId);
}
}.executeOnExecutor(ImApp.sThreadPoolExecutor, new Contact(new XmppAddress(username)));
}
use of org.awesomeapp.messenger.model.Contact 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);
}
Aggregations