use display name to generate own avatar

This commit is contained in:
Daniel Gultsch 2018-11-11 10:13:45 +01:00
parent 4c88fce3b8
commit ab43a4bcf9
4 changed files with 18 additions and 1 deletions

View File

@ -28,6 +28,7 @@ import eu.siacs.conversations.entities.ReceiptRequest;
import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.http.HttpConnectionManager;
import eu.siacs.conversations.http.P1S3UrlStreamHandler; import eu.siacs.conversations.http.P1S3UrlStreamHandler;
import eu.siacs.conversations.services.MessageArchiveService; import eu.siacs.conversations.services.MessageArchiveService;
import eu.siacs.conversations.services.QuickConversationsService;
import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper; import eu.siacs.conversations.utils.CryptoHelper;
import eu.siacs.conversations.xml.Namespace; 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) { private void setNick(Account account, Jid user, String nick) {
if (user.asBareJid().equals(account.getJid().asBareJid())) { if (user.asBareJid().equals(account.getJid().asBareJid())) {
account.setDisplayName(nick); account.setDisplayName(nick);
if (QuickConversationsService.isQuicksy()) {
mXmppConnectionService.getAvatarService().clear(account);
}
} else { } else {
Contact contact = account.getRoster().getContact(user); Contact contact = account.getRoster().getContact(user);
if (contact.setPresenceName(nick)) { if (contact.setPresenceName(nick)) {

View File

@ -11,6 +11,7 @@ import android.graphics.Rect;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.net.Uri; import android.net.Uri;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.util.Log; import android.util.Log;
import android.util.LruCache; import android.util.LruCache;
@ -392,7 +393,13 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
} }
avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size); avatar = mXmppConnectionService.getFileBackend().getAvatar(account.getAvatar(), size);
if (avatar == null) { 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); mXmppConnectionService.getBitmapCache().put(KEY, avatar);
return avatar; return avatar;

View File

@ -3849,6 +3849,7 @@ public class XmppConnectionService extends Service {
} else { } else {
request = mIqGenerator.publishNick(displayName); request = mIqGenerator.publishNick(displayName);
} }
mAvatarService.clear(account);
sendIqPacket(account, request, (account1, packet) -> { sendIqPacket(account, request, (account1, packet) -> {
if (packet.getType() == IqPacket.TYPE.ERROR) { if (packet.getType() == IqPacket.TYPE.ERROR) {
Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": unable to modify nick name "+packet.toString()); Log.d(Config.LOGTAG, account1.getJid().asBareJid() + ": unable to modify nick name "+packet.toString());

View File

@ -567,10 +567,15 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat
updateDisplayName(displayName); updateDisplayName(displayName);
mAccount.setDisplayName(displayName); mAccount.setDisplayName(displayName);
xmppConnectionService.publishDisplayName(mAccount); xmppConnectionService.publishDisplayName(mAccount);
refreshAvatar();
return null; return null;
}, true); }, true);
} }
private void refreshAvatar() {
binding.avater.setImageBitmap(avatarService().get(mAccount, (int) getResources().getDimension(R.dimen.avatar_on_details_screen_size)));
}
@Override @Override
public boolean onCreateOptionsMenu(final Menu menu) { public boolean onCreateOptionsMenu(final Menu menu) {
super.onCreateOptionsMenu(menu); super.onCreateOptionsMenu(menu);