From ab43a4bcf9d2720e1f91c8472afcdcc9555cf2cc Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Sun, 11 Nov 2018 10:13:45 +0100 Subject: [PATCH] use display name to generate own avatar --- .../eu/siacs/conversations/parser/MessageParser.java | 4 ++++ .../eu/siacs/conversations/services/AvatarService.java | 9 ++++++++- .../conversations/services/XmppConnectionService.java | 1 + .../eu/siacs/conversations/ui/EditAccountActivity.java | 5 +++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/main/java/eu/siacs/conversations/parser/MessageParser.java b/src/main/java/eu/siacs/conversations/parser/MessageParser.java index ae3af375b..e21c759f8 100644 --- a/src/main/java/eu/siacs/conversations/parser/MessageParser.java +++ b/src/main/java/eu/siacs/conversations/parser/MessageParser.java @@ -28,6 +28,7 @@ import eu.siacs.conversations.entities.ReceiptRequest; import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.http.P1S3UrlStreamHandler; import eu.siacs.conversations.services.MessageArchiveService; +import eu.siacs.conversations.services.QuickConversationsService; import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.xml.Namespace; @@ -229,6 +230,9 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece private void setNick(Account account, Jid user, String nick) { if (user.asBareJid().equals(account.getJid().asBareJid())) { account.setDisplayName(nick); + if (QuickConversationsService.isQuicksy()) { + mXmppConnectionService.getAvatarService().clear(account); + } } else { Contact contact = account.getRoster().getContact(user); if (contact.setPresenceName(nick)) { diff --git a/src/main/java/eu/siacs/conversations/services/AvatarService.java b/src/main/java/eu/siacs/conversations/services/AvatarService.java index cfd3d612d..dbd0f3fca 100644 --- a/src/main/java/eu/siacs/conversations/services/AvatarService.java +++ b/src/main/java/eu/siacs/conversations/services/AvatarService.java @@ -11,6 +11,7 @@ import android.graphics.Rect; import android.graphics.Typeface; import android.net.Uri; import android.support.annotation.Nullable; +import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; import android.util.LruCache; @@ -392,7 +393,13 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size); if (avatar == null) { - avatar = get(account.getJid().asBareJid().toString(), null, size, false); + final String displayName = account.getDisplayName(); + final String jid = account.getJid().asBareJid().toEscapedString(); + if (QuickConversationsService.isQuicksy() && !TextUtils.isEmpty(displayName)) { + avatar = get(displayName, jid, size, false); + } else { + avatar = get(jid, null, size, false); + } } mXmppConnectionService.getBitmapCache().put(KEY, avatar); return avatar; diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index a3f244930..a43843da5 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -3849,6 +3849,7 @@ public class XmppConnectionService extends Service { } else { request = mIqGenerator.publishNick(displayName); } + mAvatarService.clear(account); sendIqPacket(account, request, (account1, packet) -> { if (packet.getType() == IqPacket.TYPE.ERROR) { Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": unable to modify nick name "+packet.toString()); diff --git a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java index 868658b77..eeecf0635 100644 --- a/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/EditAccountActivity.java @@ -567,10 +567,15 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat updateDisplayName(displayName); mAccount.setDisplayName(displayName); xmppConnectionService.publishDisplayName(mAccount); + refreshAvatar(); return null; }, true); } + private void refreshAvatar() { + binding.avater.setImageBitmap(avatarService().get(mAccount, (int) getResources().getDimension(R.dimen.avatar_on_details_screen_size))); + } + @Override public boolean onCreateOptionsMenu(final Menu menu) { super.onCreateOptionsMenu(menu);