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.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)) {

View File

@ -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;

View File

@ -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());

View File

@ -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);