Commit 75a4e23b authored by Grigory Fedorov's avatar Grigory Fedorov

Avatar hash now send with presence stanzas.

parent 17112aec
...@@ -23,6 +23,7 @@ import android.graphics.drawable.ColorDrawable; ...@@ -23,6 +23,7 @@ import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable; import android.graphics.drawable.LayerDrawable;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.xabber.android.R; import com.xabber.android.R;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
...@@ -230,8 +231,8 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -230,8 +231,8 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
* avatar or avatar doesn't exists. * avatar or avatar doesn't exists.
*/ */
private Bitmap getBitmap(String bareAddress) { private Bitmap getBitmap(String bareAddress) {
String hash = hashes.get(bareAddress); String hash = getHash(bareAddress);
if (hash == null || hash.equals(EMPTY_HASH)) { if (hash == null) {
return null; return null;
} }
Bitmap bitmap = bitmaps.get(hash); Bitmap bitmap = bitmaps.get(hash);
...@@ -242,6 +243,15 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac ...@@ -242,6 +243,15 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
} }
} }
@Nullable
public String getHash(String bareAddress) {
String hash = hashes.get(bareAddress);
if (hash == null || hash.equals(EMPTY_HASH)) {
return null;
}
return hash;
}
/** /**
* Sets avatar's value. * Sets avatar's value.
* *
......
...@@ -18,6 +18,7 @@ import android.database.Cursor; ...@@ -18,6 +18,7 @@ import android.database.Cursor;
import com.xabber.android.data.Application; import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager; import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.OnLoadListener; import com.xabber.android.data.OnLoadListener;
import com.xabber.android.data.SettingsManager; import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountItem; import com.xabber.android.data.account.AccountItem;
...@@ -30,6 +31,7 @@ import com.xabber.android.data.connection.OnPacketListener; ...@@ -30,6 +31,7 @@ import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.extension.avatar.AvatarManager; import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.roster.OnRosterChangedListener; import com.xabber.android.data.roster.OnRosterChangedListener;
import com.xabber.android.data.roster.OnRosterReceivedListener; import com.xabber.android.data.roster.OnRosterReceivedListener;
import com.xabber.android.data.roster.PresenceManager;
import com.xabber.android.data.roster.RosterContact; import com.xabber.android.data.roster.RosterContact;
import com.xabber.android.data.roster.RosterManager; import com.xabber.android.data.roster.RosterManager;
import com.xabber.android.data.roster.StructuredName; import com.xabber.android.data.roster.StructuredName;
...@@ -332,7 +334,9 @@ public class VCardManager implements OnLoadListener, OnPacketListener, ...@@ -332,7 +334,9 @@ public class VCardManager implements OnLoadListener, OnPacketListener,
vCardSaveRequests.add(account); vCardSaveRequests.add(account);
try { try {
vCardManager.saveVCard(vCard); vCardManager.saveVCard(vCard);
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException | SmackException.NotConnectedException e) { PresenceManager.getInstance().sendVCardUpdatePresence(account, vCard.getAvatarHash());
} catch (SmackException.NoResponseException | XMPPException.XMPPErrorException
| SmackException.NotConnectedException | NetworkException e) {
LogManager.w(this, "Error saving vCard: " + e.getMessage()); LogManager.w(this, "Error saving vCard: " + e.getMessage());
isSuccess = false; isSuccess = false;
} }
......
...@@ -28,9 +28,11 @@ import com.xabber.android.data.connection.OnDisconnectListener; ...@@ -28,9 +28,11 @@ import com.xabber.android.data.connection.OnDisconnectListener;
import com.xabber.android.data.connection.OnPacketListener; import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.entity.NestedMap; import com.xabber.android.data.entity.NestedMap;
import com.xabber.android.data.extension.archive.OnArchiveModificationsReceivedListener; import com.xabber.android.data.extension.archive.OnArchiveModificationsReceivedListener;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.notification.EntityNotificationProvider; import com.xabber.android.data.notification.EntityNotificationProvider;
import com.xabber.android.data.notification.NotificationManager; import com.xabber.android.data.notification.NotificationManager;
import com.xabber.xmpp.address.Jid; import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.avatar.VCardUpdate;
import org.jivesoftware.smack.packet.IQ; import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence; import org.jivesoftware.smack.packet.Presence;
...@@ -379,10 +381,18 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener, ...@@ -379,10 +381,18 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
* @throws NetworkException * @throws NetworkException
*/ */
public void resendPresence(String account) throws NetworkException { public void resendPresence(String account) throws NetworkException {
sendVCardUpdatePresence(account, AvatarManager.getInstance().getHash(Jid.getBareAddress(account)));
}
public void sendVCardUpdatePresence(String account, String hash) throws NetworkException {
if (!readyAccounts.contains(account)) if (!readyAccounts.contains(account))
throw new NetworkException(R.string.NOT_CONNECTED); throw new NetworkException(R.string.NOT_CONNECTED);
ConnectionManager.getInstance().sendStanza(account, final Presence presence = AccountManager.getInstance().getAccount(account).getPresence();
AccountManager.getInstance().getAccount(account).getPresence());
final VCardUpdate vCardUpdate = new VCardUpdate();
vCardUpdate.setPhotoHash(hash);
presence.addExtension(vCardUpdate);
ConnectionManager.getInstance().sendStanza(account, presence);
} }
} }
...@@ -93,8 +93,11 @@ public class VCardUpdate extends PacketExtension { ...@@ -93,8 +93,11 @@ public class VCardUpdate extends PacketExtension {
@Override @Override
public void serializeContent(XmlSerializer serializer) throws IOException { public void serializeContent(XmlSerializer serializer) throws IOException {
if (photoHash != null) if (photoHash != null) {
SerializerUtils.addTextTag(serializer, PHOTO_NAME, photoHash); SerializerUtils.addTextTag(serializer, PHOTO_NAME, photoHash);
} else {
SerializerUtils.addEmtpyTag(serializer, PHOTO_NAME);
}
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment