From c3b11e515edada04b769821e0f3b9b2ba4f0d627 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 9 Sep 2016 11:04:05 +0200 Subject: [PATCH] download own vcard avatar if none is set. fixes #2008 --- .../conversations/entities/MucOptions.java | 2 +- .../conversations/parser/PresenceParser.java | 10 ++++++++-- .../services/XmppConnectionService.java | 19 +++++++++++++------ .../ui/ConversationFragment.java | 3 +-- 4 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/MucOptions.java b/src/main/java/eu/siacs/conversations/entities/MucOptions.java index 097f4e301..9d54a86d6 100644 --- a/src/main/java/eu/siacs/conversations/entities/MucOptions.java +++ b/src/main/java/eu/siacs/conversations/entities/MucOptions.java @@ -116,7 +116,7 @@ public class MucOptions { public enum Error { NO_RESPONSE, - SEVRER_NOT_FOUND, + SERVER_NOT_FOUND, NONE, NICK_IN_USE, PASSWORD_REQUIRED, diff --git a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java index d812b85de..46ce61b75 100644 --- a/src/main/java/eu/siacs/conversations/parser/PresenceParser.java +++ b/src/main/java/eu/siacs/conversations/parser/PresenceParser.java @@ -184,10 +184,16 @@ public class PresenceParser extends AbstractParser implements final String resource = from.isBareJid() ? "" : from.getResourcepart(); contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick")); Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); - if (avatar != null && !contact.isSelf()) { + if (avatar != null && (!contact.isSelf() || account.getAvatar() == null)) { avatar.owner = from.toBareJid(); if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) { - if (contact.setAvatar(avatar)) { + if (avatar.owner.equals(account.getJid().toBareJid())) { + account.setAvatar(avatar.getFilename()); + mXmppConnectionService.databaseBackend.updateAccount(account); + mXmppConnectionService.getAvatarService().clear(account); + mXmppConnectionService.updateConversationUi(); + mXmppConnectionService.updateAccountUi(); + } else if (contact.setAvatar(avatar)) { mXmppConnectionService.getAvatarService().clear(contact); mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateRosterUi(); diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 2fb33bb60..4374b3f61 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -2036,7 +2036,7 @@ public class XmppConnectionService extends Service { @Override public void onFetchFailed(final Conversation conversation, Element error) { if (error != null && "remote-server-not-found".equals(error.getName())) { - conversation.getMucOptions().setError(MucOptions.Error.SEVRER_NOT_FOUND); + conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND); } else { join(conversation); fetchConferenceConfiguration(conversation); @@ -2739,12 +2739,19 @@ public class XmppConnectionService extends Service { Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": successfully fetched vCard avatar for " + avatar.owner); if (avatar.owner.isBareJid()) { - Contact contact = account.getRoster() - .getContact(avatar.owner); - contact.setAvatar(avatar); - getAvatarService().clear(contact); + if (account.getJid().toBareJid().equals(avatar.owner) && account.getAvatar() == null) { + Log.d(Config.LOGTAG,account.getJid().toBareJid()+": had no avatar. replacing with vcard"); + account.setAvatar(avatar.getFilename()); + databaseBackend.updateAccount(account); + getAvatarService().clear(account); + updateAccountUi(); + } else { + Contact contact = account.getRoster().getContact(avatar.owner); + contact.setAvatar(avatar); + getAvatarService().clear(contact); + updateRosterUi(); + } updateConversationUi(); - updateRosterUi(); } else { Conversation conversation = find(account, avatar.owner.toBareJid()); if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 5fd654fa9..edee551bb 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -43,7 +43,6 @@ import java.util.UUID; import eu.siacs.conversations.Config; import eu.siacs.conversations.R; -import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; @@ -865,7 +864,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa case NO_RESPONSE: showSnackbar(R.string.joining_conference, 0, null); break; - case SEVRER_NOT_FOUND: + case SERVER_NOT_FOUND: showSnackbar(R.string.remote_server_not_found,R.string.leave, leaveMuc); break; case PASSWORD_REQUIRED: