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;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.xabber.android.R;
import com.xabber.android.data.Application;
......@@ -230,8 +231,8 @@ public class AvatarManager implements OnLoadListener, OnLowMemoryListener, OnPac
* avatar or avatar doesn't exists.
*/
private Bitmap getBitmap(String bareAddress) {
String hash = hashes.get(bareAddress);
if (hash == null || hash.equals(EMPTY_HASH)) {
String hash = getHash(bareAddress);
if (hash == null) {
return null;
}
Bitmap bitmap = bitmaps.get(hash);
......@@ -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.
*
......
......@@ -18,6 +18,7 @@ import android.database.Cursor;
import com.xabber.android.data.Application;
import com.xabber.android.data.LogManager;
import com.xabber.android.data.NetworkException;
import com.xabber.android.data.OnLoadListener;
import com.xabber.android.data.SettingsManager;
import com.xabber.android.data.account.AccountItem;
......@@ -30,6 +31,7 @@ import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.extension.avatar.AvatarManager;
import com.xabber.android.data.roster.OnRosterChangedListener;
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.RosterManager;
import com.xabber.android.data.roster.StructuredName;
......@@ -332,7 +334,9 @@ public class VCardManager implements OnLoadListener, OnPacketListener,
vCardSaveRequests.add(account);
try {
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());
isSuccess = false;
}
......
......@@ -28,9 +28,11 @@ import com.xabber.android.data.connection.OnDisconnectListener;
import com.xabber.android.data.connection.OnPacketListener;
import com.xabber.android.data.entity.NestedMap;
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.NotificationManager;
import com.xabber.xmpp.address.Jid;
import com.xabber.xmpp.avatar.VCardUpdate;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Presence;
......@@ -379,10 +381,18 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
* @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))
throw new NetworkException(R.string.NOT_CONNECTED);
ConnectionManager.getInstance().sendStanza(account,
AccountManager.getInstance().getAccount(account).getPresence());
final Presence presence = 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 {
@Override
public void serializeContent(XmlSerializer serializer) throws IOException {
if (photoHash != null)
if (photoHash != null) {
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