fix deleting own avatar (Christian Schneppe)

This commit is contained in:
Arne 2022-02-16 20:43:20 +01:00
parent 5df9930d60
commit d3d4b962a3
7 changed files with 30 additions and 9 deletions

View file

@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.4'
classpath 'com.android.tools.build:gradle:7.1.1'
}
}
@ -69,8 +69,8 @@ dependencies {
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.cardview:cardview:1.0.0' // for compatibility
implementation 'com.davemorrissey.labs:subsampling-scale-image-view:3.10.0'
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.0'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.15.0'
implementation 'com.google.android.exoplayer:exoplayer-core:2.16.1'
implementation 'com.google.android.exoplayer:exoplayer-ui:2.16.1'
implementation 'com.wefika:flowlayout:0.4.1'
implementation 'com.googlecode.ez-vcard:ez-vcard:0.10.5'
implementation 'org.jxmpp:jxmpp-jid:1.0.2'
@ -106,8 +106,8 @@ android {
targetSdkVersion 31
//versionNameSuffix " beta_(2021-12-19)" // " beta_(XXXX-XX-XX)" // activate for beta versions
versionCode 111
versionName "1.5"
versionCode 112
versionName "1.5.1"
//resConfigs "en"
archivesBaseName += "-$versionName"

View file

@ -13,6 +13,6 @@
# org.gradle.parallel=true
#Sat Jan 22 19:25:52 CET 2022
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options\="-Xmx4096M"
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
android.enableJetifier=true
android.useAndroidX=true

View file

@ -180,6 +180,11 @@ public class IqGenerator extends AbstractGenerator {
info.setAttribute("type", avatar.type);
return publish("urn:xmpp:avatar:metadata", item, options);
}
public IqPacket deleteAvatar() {
final Element item = new Element("item");
item.addChild("metadata", "urn:xmpp:avatar:metadata");
return publish("urn:xmpp:avatar:metadata", item);
}
public IqPacket retrievePepAvatar(final Avatar avatar) {
final Element item = new Element("item");

View file

@ -320,6 +320,10 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else if (mXmppConnectionService.isDataSaverDisabled()) {
mXmppConnectionService.fetchAvatar(account, avatar);
}
} else {
final Contact c = account.getRoster().getContact(from);
mXmppConnectionService.getAvatarService().clear(c);
mXmppConnectionService.getFileBackend().deleteAvatar(c.getAvatarFilename());
}
} else if (Namespace.NICK.equals(node)) {
final Element i = items.findChild("item");

View file

@ -1311,6 +1311,16 @@ public class FileBackend {
final File file = getAvatarFile(avatar.getFilename());
return file.exists();
}
public boolean deleteAvatar(final String avatarFilename) {
final File file = getAvatarFile(avatarFilename);
return deleteAvatar(file);
}
public boolean deleteAvatar(final Avatar avatar) {
final File file = getAvatarFile(avatar.getFilename());
return deleteAvatar(file);
}
public boolean deleteAvatar(final File avatar) {
if (avatar.exists()) {
return avatar.delete();

View file

@ -4079,7 +4079,7 @@ public class XmppConnectionService extends Service {
public void deleteAvatar(Account account) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": deleting avatar");
IqPacket packet = this.mIqGenerator.deleteNode("urn:xmpp:avatar:data");
IqPacket packet = this.mIqGenerator.deleteAvatar();
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
@ -4088,7 +4088,9 @@ public class XmppConnectionService extends Service {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar deletion succeed");
if (account.getAvatar() != null) {
if (getFileBackend().deleteAvatar(getFileBackend().getAvatarFile(account.getAvatar()))) {
mAvatarService.clear(account);
getAvatarService().clear(account);
databaseBackend.updateAccount(account);
notifyAccountAvatarHasChanged(account);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": local avatar cache deletion succeed");
}
}

View file

@ -4,7 +4,7 @@
<item
android:id="@+id/action_delete_avatar"
app:showAsAction="always"
android:icon="?attr/icon_delete"
android:icon="@drawable/ic_delete_white_24dp"
android:orderInCategory="10"
android:title="@string/delete_avatar" />
</menu>