update libraries and migrate delete avatar from Conversations (Daniel Gultsch)

This commit is contained in:
12aw 2022-09-02 11:04:20 +02:00
parent 9180dbaf47
commit f3d201daf2
11 changed files with 128 additions and 107 deletions

View file

@ -59,11 +59,11 @@ dependencies {
implementation 'com.google.code.gson:gson:2.8.9'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'androidx.exifinterface:exifinterface:1.3.3'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "androidx.emoji2:emoji2:1.1.0"
gitImplementation "androidx.emoji2:emoji2-bundled:1.1.0"
implementation "androidx.emoji2:emoji2:1.2.0"
gitImplementation "androidx.emoji2:emoji2-bundled:1.2.0"
implementation 'androidx.recyclerview:recyclerview:1.2.1'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.cardview:cardview:1.0.0' // for compatibility
@ -77,7 +77,7 @@ dependencies {
implementation 'org.jxmpp:jxmpp-jid:1.0.3'
implementation 'org.hsluv:hsluv:0.2'
implementation 'org.conscrypt:conscrypt-android:2.5.2'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.24'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.25'
implementation 'me.drakeet.support:toastcompat:1.1.0'
implementation 'org.osmdroid:osmdroid-android:6.1.11'
implementation 'com.leinardi.android:speed-dial:3.2.0'
@ -85,7 +85,7 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:4.10.0"
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.guava:guava:31.0.1-android'
implementation 'com.google.guava:guava:31.1-android'
implementation 'com.github.AppIntro:AppIntro:6.1.0'
implementation 'androidx.browser:browser:1.4.0'
implementation 'com.otaliastudios:transcoder:0.9.1' // 0.10.4 seems to be buggy

View file

@ -708,11 +708,11 @@ public class AxolotlService implements OnAdvancedStreamFeaturesLoaded {
}
public void deleteOmemoIdentity() {
final String node = AxolotlService.PEP_BUNDLES + ":" + getOwnDeviceId();
final IqPacket deleteBundleNode = mXmppConnectionService.getIqGenerator().deleteNode(node);
mXmppConnectionService.sendIqPacket(account, deleteBundleNode, null);
mXmppConnectionService.deletePepNode(
account, AxolotlService.PEP_BUNDLES + ":" + getOwnDeviceId());
final Set<Integer> ownDeviceIds = getOwnDeviceIds();
publishDeviceIdsAndRefineAccessModel(ownDeviceIds == null ? Collections.emptySet() : ownDeviceIds);
publishDeviceIdsAndRefineAccessModel(
ownDeviceIds == null ? Collections.emptySet() : ownDeviceIds);
}
public List<Jid> getCryptoTargets(Conversation conversation) {

View file

@ -156,9 +156,9 @@ public class IqGenerator extends AbstractGenerator {
public IqPacket publishAvatar(Avatar avatar, Bundle options) {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
final Element data = item.addChild("data", "urn:xmpp:avatar:data");
final Element data = item.addChild("data", Namespace.AVATAR_DATA);
data.setContent(avatar.image);
return publish("urn:xmpp:avatar:data", item, options);
return publish(Namespace.AVATAR_DATA, item, options);
}
public IqPacket publishElement(final String namespace, final Element element, String id, final Bundle options) {
@ -172,26 +172,26 @@ public class IqGenerator extends AbstractGenerator {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
final Element metadata = item
.addChild("metadata", "urn:xmpp:avatar:metadata");
.addChild("metadata", Namespace.AVATAR_DATA);
final Element info = metadata.addChild("info");
info.setAttribute("bytes", avatar.size);
info.setAttribute("id", avatar.sha1sum);
info.setAttribute("height", avatar.height);
info.setAttribute("width", avatar.height);
info.setAttribute("type", avatar.type);
return publish("urn:xmpp:avatar:metadata", item, options);
return publish(Namespace.AVATAR_DATA, 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);
item.addChild("metadata", Namespace.AVATAR_DATA);
return publish(Namespace.AVATAR_DATA, item);
}
public IqPacket retrievePepAvatar(final Avatar avatar) {
final Element item = new Element("item");
item.setAttribute("id", avatar.sha1sum);
final IqPacket packet = retrieve("urn:xmpp:avatar:data", item);
final IqPacket packet = retrieve(Namespace.AVATAR_DATA, item);
packet.setTo(avatar.owner);
return packet;
}
@ -202,9 +202,15 @@ public class IqGenerator extends AbstractGenerator {
packet.addChild("vCard", "vcard-temp");
return packet;
}
public IqPacket retrieveVcardAvatar(final Jid to) {
final IqPacket packet = new IqPacket(IqPacket.TYPE.GET);
packet.setTo(to);
packet.addChild("vCard", "vcard-temp");
return packet;
}
public IqPacket retrieveAvatarMetaData(final Jid to) {
final IqPacket packet = retrieve("urn:xmpp:avatar:metadata", null);
final IqPacket packet = retrieve(Namespace.AVATAR_DATA, null);
if (to != null) {
packet.setTo(to);
}

View file

@ -4,12 +4,13 @@ import static eu.siacs.conversations.http.HttpConnectionManager.FileTransferExec
import android.util.Log;
import androidx.annotation.Nullable;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@ -22,6 +23,7 @@ import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.DownloadableFile;
import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.entities.Transferable;
import eu.siacs.conversations.persistance.FileBackend;
import eu.siacs.conversations.services.AbstractConnectionManager;
import eu.siacs.conversations.services.XmppConnectionService;
import eu.siacs.conversations.utils.CryptoHelper;
@ -31,7 +33,6 @@ import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import eu.siacs.conversations.persistance.FileBackend;
public class HttpUploadConnection implements Transferable, AbstractConnectionManager.ProgressListener {
@ -136,7 +137,7 @@ public class HttpUploadConnection implements Transferable, AbstractConnectionMan
this.slotFuture = new SlotRequester(mXmppConnectionService).request(method, account, file, mime);
Futures.addCallback(this.slotFuture, new FutureCallback<SlotRequester.Slot>() {
@Override
public void onSuccess(@NullableDecl SlotRequester.Slot result) {
public void onSuccess(@Nullable SlotRequester.Slot result) {
changeStatus(STATUS_WAITING);
FileTransferExecutor.execute(() -> {
changeStatus(STATUS_UPLOADING);

View file

@ -5,7 +5,7 @@ import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import eu.siacs.conversations.utils.Namespace;
import eu.siacs.conversations.entities.Account;
import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation;
@ -95,7 +95,7 @@ public abstract class AbstractParser {
if (item == null) {
return null;
}
return item.findChildContent("data", "urn:xmpp:avatar:data");
return item.findChildContent("data", Namespace.AVATAR_DATA);
}
public static MucOptions.User parseItem(Conversation conference, Element item) {

View file

@ -54,7 +54,6 @@ import eu.siacs.conversations.xmpp.OnMessagePacketReceived;
import eu.siacs.conversations.xmpp.chatstate.ChatState;
import eu.siacs.conversations.xmpp.jingle.JingleConnectionManager;
import eu.siacs.conversations.xmpp.jingle.JingleRtpConnection;
import eu.siacs.conversations.xmpp.pep.Avatar;
import eu.siacs.conversations.xmpp.stanzas.MessagePacket;
@ -297,36 +296,7 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
private void parseEvent(final Element event, final Jid from, final Account account) {
final Element items = event.findChild("items");
final String node = items == null ? null : items.getAttribute("node");
if ("urn:xmpp:avatar:metadata".equals(node)) {
Avatar avatar = Avatar.parseMetadata(items);
if (avatar != null) {
avatar.owner = from.asBareJid();
if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
if (account.getJid().asBareJid().equals(from)) {
if (account.setAvatar(avatar.getFilename())) {
mXmppConnectionService.databaseBackend.updateAccount(account);
mXmppConnectionService.notifyAccountAvatarHasChanged(account);
}
mXmppConnectionService.getAvatarService().clear(account);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateAccountUi();
} else {
final Contact contact = account.getRoster().getContact(from);
contact.setAvatar(avatar);
mXmppConnectionService.syncRoster(account);
mXmppConnectionService.getAvatarService().clear(contact);
mXmppConnectionService.updateConversationUi();
mXmppConnectionService.updateRosterUi();
}
} 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)) {
if (Namespace.NICK.equals(node)) {
final Element i = items.findChild("item");
final String nick = i == null ? null : i.findChildContent("nick", Namespace.NICK);
if (nick != null) {
@ -382,6 +352,8 @@ public class MessageParser extends AbstractParser implements OnMessagePacketRece
} else if (Namespace.BOOKMARKS2.equals(node) && account.getJid().asBareJid().equals(from)) {
account.setBookmarks(Collections.emptyMap());
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": deleted bookmarks node");
} else if (Namespace.AVATAR_METADATA.equals(node) && account.getJid().asBareJid().equals(from)) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": deleted avatar metadata node");
}
}

View file

@ -75,7 +75,7 @@ import androidx.annotation.BoolRes;
import androidx.annotation.IntegerRes;
import androidx.core.app.RemoteInput;
import androidx.core.content.ContextCompat;
import androidx.annotation.NonNull;
import com.google.common.base.Objects;
import com.google.common.base.Strings;
import com.otaliastudios.transcoder.strategy.DefaultAudioStrategy;
@ -3445,6 +3445,71 @@ public class XmppConnectionService extends Service {
}
}
public void deleteAvatar(final Account account) {
final AtomicBoolean executed = new AtomicBoolean(false);
final Runnable onDeleted =
() -> {
if (executed.compareAndSet(false, true)) {
account.setAvatar(null);
databaseBackend.updateAccount(account);
getAvatarService().clear(account);
updateAccountUi();
}
};
deleteVcardAvatar(account, onDeleted);
deletePepNode(account, Namespace.AVATAR_DATA);
deletePepNode(account, Namespace.AVATAR_METADATA, onDeleted);
}
public void deletePepNode(final Account account, final String node) {
deletePepNode(account, node, null);
}
private void deletePepNode(final Account account, final String node, final Runnable runnable) {
final IqPacket request = mIqGenerator.deleteNode(node);
sendIqPacket(account, request, (a, packet) -> {
if (packet.getType() == IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": successfully deleted pep node " + node);
if (runnable != null) {
runnable.run();
}
} else {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": failed to delete " + packet);
}
});
}
private void deleteVcardAvatar(final Account account, @NonNull final Runnable runnable) {
final IqPacket retrieveVcard = mIqGenerator.retrieveVcardAvatar(account.getJid().asBareJid());
sendIqPacket(account, retrieveVcard, (a, response) -> {
if (response.getType() != IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": no vCard set. nothing to do");
return;
}
final Element vcard = response.findChild("vCard", "vcard-temp");
if (vcard == null) {
Log.d(Config.LOGTAG, a.getJid().asBareJid() + ": no vCard set. nothing to do");
return;
}
Element photo = vcard.findChild("PHOTO");
if (photo == null) {
photo = vcard.addChild("PHOTO");
}
photo.clearChildren();
IqPacket publication = new IqPacket(IqPacket.TYPE.SET);
publication.setTo(a.getJid().asBareJid());
publication.addChild(vcard);
sendIqPacket(account, publication, (a1, publicationResponse) -> {
if (publicationResponse.getType() == IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG, a1.getJid().asBareJid() + ": successfully deleted vcard avatar");
runnable.run();
} else {
Log.d(Config.LOGTAG, "failed to publish vcard " + publicationResponse.getErrorCondition());
}
});
});
}
private boolean hasEnabledAccounts() {
if (this.accounts == null) {
return false; // set to false if accounts could not be fetched - used for notifications
@ -4101,7 +4166,7 @@ public class XmppConnectionService extends Service {
if (result.getType() == IqPacket.TYPE.RESULT) {
publishAvatarMetadata(account, avatar, options, true, callback);
} else if (retry && PublishOptions.preconditionNotMet(result)) {
pushNodeConfiguration(account, "urn:xmpp:avatar:data", options, new OnConfigurationPushed() {
pushNodeConfiguration(account, Namespace.AVATAR_DATA, options, new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": changed node configuration for avatar node");
@ -4125,33 +4190,6 @@ public class XmppConnectionService extends Service {
});
}
public void deleteAvatar(Account account) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": deleting avatar");
IqPacket packet = this.mIqGenerator.deleteAvatar();
this.sendIqPacket(account, packet, new OnIqPacketReceived() {
@Override
public void onIqPacketReceived(Account account, IqPacket result) {
if (result.getType() == IqPacket.TYPE.RESULT) {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar deletion succeed");
if (account.getAvatar() != null) {
if (getFileBackend().deleteAvatar(getFileBackend().getAvatarFile(account.getAvatar()))) {
getAvatarService().clear(account);
databaseBackend.updateAccount(account);
notifyAccountAvatarHasChanged(account);
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": local avatar cache deletion succeed");
}
}
//todo callback
} else {
Element error = result.findChild("error");
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar deletion failed " + (error != null ? error.toString() : ""));
// todo callback
}
}
});
}
public void publishAvatarMetadata(Account account, final Avatar avatar, final Bundle options, final boolean retry, final OnAvatarPublication callback) {
final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar, options);
sendIqPacket(account, packet, new OnIqPacketReceived() {
@ -4168,7 +4206,7 @@ public class XmppConnectionService extends Service {
callback.onAvatarPublicationSucceeded();
}
} else if (retry && PublishOptions.preconditionNotMet(result)) {
pushNodeConfiguration(account, "urn:xmpp:avatar:metadata", options, new OnConfigurationPushed() {
pushNodeConfiguration(account, Namespace.AVATAR_METADATA, options, new OnConfigurationPushed() {
@Override
public void onPushSucceeded() {
Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": changed node configuration for avatar meta data node");

View file

@ -14,7 +14,7 @@ import android.view.View.OnLongClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.StringRes;
import com.theartofdev.edmodo.cropper.CropImage;
@ -82,11 +82,6 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
togglePublishButton(true, R.string.publish);
});
}
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
getMenuInflater().inflate(R.menu.activity_publish_avatar, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public void onCreate(Bundle savedInstanceState) {
@ -127,7 +122,25 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
}
@Override
public void onSaveInstanceState(Bundle outState) {
public boolean onCreateOptionsMenu(@NonNull final Menu menu) {
getMenuInflater().inflate(R.menu.activity_publish_avatar, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(final MenuItem item) {
if (item.getItemId() == R.id.action_delete_avatar) {
if (xmppConnectionService != null && account != null) {
xmppConnectionService.deleteAvatar(account);
}
return true;
} else {
return super.onOptionsItemSelected(item);
}
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
if (this.avatarUri != null) {
outState.putParcelable("uri", this.avatarUri);
}
@ -283,16 +296,5 @@ public class PublishProfilePictureActivity extends XmppActivity implements XmppC
public void onAccountUpdate() {
refreshUi();
}
public boolean onOptionsItemSelected(final MenuItem item) {
switch (item.getItemId()) {
case R.id.action_delete_avatar:
if (account != null) {
xmppConnectionService.deleteAvatar(account);
finish();
}
break;
}
return super.onOptionsItemSelected(item);
}
}

View file

@ -26,6 +26,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.databinding.DataBindingUtil;
import androidx.annotation.Nullable;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
@ -35,7 +36,6 @@ import com.google.common.collect.ImmutableSet;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import org.webrtc.RendererCommon;
import org.webrtc.SurfaceViewRenderer;
import org.webrtc.VideoTrack;
@ -977,7 +977,7 @@ public class RtpSessionActivity extends XmppActivity
requireRtpConnection().switchCamera(),
new FutureCallback<Boolean>() {
@Override
public void onSuccess(@NullableDecl Boolean isFrontCamera) {
public void onSuccess(@Nullable Boolean isFrontCamera) {
binding.localVideo.setMirror(isFrontCamera);
}

View file

@ -26,6 +26,8 @@ public final class Namespace {
public static final String BOOKMARKS_CONVERSION = "urn:xmpp:bookmarks-conversion:0";
public static final String BOOKMARKS = "storage:bookmarks";
public static final String SYNCHRONIZATION = "im.quicksy.synchronization:0";
public static final String AVATAR_DATA = "urn:xmpp:avatar:data";
public static final String AVATAR_METADATA = "urn:xmpp:avatar:metadata";
public static final String AVATAR_CONVERSION = "urn:xmpp:pep-vcard-conversion:0";
public static final String JINGLE = "urn:xmpp:jingle:1";
public static final String JINGLE_ERRORS = "urn:xmpp:jingle:errors:1";

View file

@ -1,5 +1,7 @@
package eu.siacs.conversations.xmpp.jingle;
import androidx.annotation.Nullable;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
@ -11,8 +13,6 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import org.checkerframework.checker.nullness.compatqual.NullableDecl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
@ -293,9 +293,9 @@ public class RtpContentMap {
Maps.transformValues(
contents,
new Function<Content, DescriptionTransport>() {
@NullableDecl
@Nullable
@Override
public DescriptionTransport apply(@NullableDecl Content content) {
public DescriptionTransport apply(@Nullable Content content) {
return content == null ? null : of(content);
}
}));