use of org.jivesoftware.smackx.vcardtemp.VCardManager 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.jivesoftware.smackx.vcardtemp.VCardManager in project Zom-Android by zom.
the class XmppConnection method sendVCard.
public void sendVCard(String migrateJabberId, boolean forceAvatarRefresh) {
if (mConnection == null || getState() != ImConnection.LOGGED_IN)
return;
try {
String jid = mUser.getAddress().getBareAddress();
VCardManager vCardManager = VCardManager.getInstanceFor(mConnection);
VCard vCard = null;
try {
vCard = vCardManager.loadVCard(JidCreate.entityBareFrom(jid));
} catch (Exception e) {
// debug(TAG,"error loading vcard",e);
}
boolean setAvatar = true;
if (vCard == null) {
vCard = new VCard();
vCard.setJabberId(jid);
setAvatar = true;
} else if (vCard.getAvatarHash() != null) {
setAvatar = !DatabaseUtils.doesAvatarHashExist(mContext.getContentResolver(), Imps.Avatars.CONTENT_URI, mUser.getAddress().getBareAddress(), vCard.getAvatarHash());
}
vCard.setNickName(mUser.getName());
vCard.setFirstName(mUser.getName());
// if we have moved to a new account, send it here
if (migrateJabberId != null) {
vCard.setJabberId(migrateJabberId);
} else {
vCard.setJabberId(mUser.getAddress().getBareAddress());
}
if (setAvatar || forceAvatarRefresh) {
byte[] avatar = DatabaseUtils.getAvatarBytesFromAddress(mContext.getContentResolver(), mUser.getAddress().getBareAddress());
if (avatar != null) {
vCard.setAvatar(avatar, "image/jpeg");
}
}
if (mConnection != null && mConnection.isConnected() && mConnection.isAuthenticated()) {
debug(TAG, "Saving VCard for: " + mUser.getAddress().getAddress());
vCardManager.saveVCard(vCard);
}
} catch (Exception e) {
debug(TAG, "error saving vcard", e);
}
}
Aggregations