download own vcard avatar if none is set. fixes #2008

This commit is contained in:
Daniel Gultsch 2016-09-09 11:04:05 +02:00
parent edf0ae9aa6
commit c3b11e515e
4 changed files with 23 additions and 11 deletions

View File

@ -116,7 +116,7 @@ public class MucOptions {
public enum Error { public enum Error {
NO_RESPONSE, NO_RESPONSE,
SEVRER_NOT_FOUND, SERVER_NOT_FOUND,
NONE, NONE,
NICK_IN_USE, NICK_IN_USE,
PASSWORD_REQUIRED, PASSWORD_REQUIRED,

View File

@ -184,10 +184,16 @@ public class PresenceParser extends AbstractParser implements
final String resource = from.isBareJid() ? "" : from.getResourcepart(); final String resource = from.isBareJid() ? "" : from.getResourcepart();
contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick")); contact.setPresenceName(packet.findChildContent("nick", "http://jabber.org/protocol/nick"));
Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update")); 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(); avatar.owner = from.toBareJid();
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) { 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.getAvatarService().clear(contact);
mXmppConnectionService.updateConversationUi(); mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi(); mXmppConnectionService.updateRosterUi();

View File

@ -2036,7 +2036,7 @@ public class XmppConnectionService extends Service {
@Override @Override
public void onFetchFailed(final Conversation conversation, Element error) { public void onFetchFailed(final Conversation conversation, Element error) {
if (error != null && "remote-server-not-found".equals(error.getName())) { 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 { } else {
join(conversation); join(conversation);
fetchConferenceConfiguration(conversation); fetchConferenceConfiguration(conversation);
@ -2739,12 +2739,19 @@ public class XmppConnectionService extends Service {
Log.d(Config.LOGTAG, account.getJid().toBareJid() Log.d(Config.LOGTAG, account.getJid().toBareJid()
+ ": successfully fetched vCard avatar for " + avatar.owner); + ": successfully fetched vCard avatar for " + avatar.owner);
if (avatar.owner.isBareJid()) { if (avatar.owner.isBareJid()) {
Contact contact = account.getRoster() if (account.getJid().toBareJid().equals(avatar.owner) && account.getAvatar() == null) {
.getContact(avatar.owner); Log.d(Config.LOGTAG,account.getJid().toBareJid()+": had no avatar. replacing with vcard");
contact.setAvatar(avatar); account.setAvatar(avatar.getFilename());
getAvatarService().clear(contact); databaseBackend.updateAccount(account);
getAvatarService().clear(account);
updateAccountUi();
} else {
Contact contact = account.getRoster().getContact(avatar.owner);
contact.setAvatar(avatar);
getAvatarService().clear(contact);
updateRosterUi();
}
updateConversationUi(); updateConversationUi();
updateRosterUi();
} else { } else {
Conversation conversation = find(account, avatar.owner.toBareJid()); Conversation conversation = find(account, avatar.owner.toBareJid());
if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) { if (conversation != null && conversation.getMode() == Conversation.MODE_MULTI) {

View File

@ -43,7 +43,6 @@ import java.util.UUID;
import eu.siacs.conversations.Config; import eu.siacs.conversations.Config;
import eu.siacs.conversations.R; import eu.siacs.conversations.R;
import eu.siacs.conversations.crypto.axolotl.AxolotlService;
import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
@ -865,7 +864,7 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa
case NO_RESPONSE: case NO_RESPONSE:
showSnackbar(R.string.joining_conference, 0, null); showSnackbar(R.string.joining_conference, 0, null);
break; break;
case SEVRER_NOT_FOUND: case SERVER_NOT_FOUND:
showSnackbar(R.string.remote_server_not_found,R.string.leave, leaveMuc); showSnackbar(R.string.remote_server_not_found,R.string.leave, leaveMuc);
break; break;
case PASSWORD_REQUIRED: case PASSWORD_REQUIRED: