From d42486c72c687acefc60677a42f6a439e1947434 Mon Sep 17 00:00:00 2001 From: kosyak Date: Wed, 22 May 2024 21:31:23 +0200 Subject: [PATCH] fix reactions handling in case of missing reply stanza --- .../conversations/entities/Conversation.java | 6 +----- .../eu/siacs/conversations/entities/Message.java | 14 +++++++------- .../services/XmppConnectionService.java | 3 +-- .../conversations/ui/ConversationFragment.java | 16 ++++++---------- 4 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/entities/Conversation.java b/src/main/java/eu/siacs/conversations/entities/Conversation.java index 7639eaf68..1dcac5624 100644 --- a/src/main/java/eu/siacs/conversations/entities/Conversation.java +++ b/src/main/java/eu/siacs/conversations/entities/Conversation.java @@ -10,7 +10,6 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.BitmapDrawable; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.telephony.PhoneNumberUtils; @@ -24,7 +23,6 @@ import android.text.TextUtils; import android.text.TextWatcher; import android.text.util.Linkify; import android.util.DisplayMetrics; -import android.util.LruCache; import android.util.Pair; import android.util.SparseArray; import android.view.Gravity; @@ -81,7 +79,6 @@ import java.time.format.FormatStyle; import java.util.ArrayList; import java.util.Collections; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.ListIterator; import java.util.Objects; @@ -110,7 +107,6 @@ import eu.siacs.conversations.databinding.CommandTextFieldBinding; import eu.siacs.conversations.databinding.CommandUnknownBinding; import eu.siacs.conversations.databinding.CommandWebviewBinding; import eu.siacs.conversations.databinding.DialogQuickeditBinding; -import eu.siacs.conversations.http.HttpConnectionManager; import eu.siacs.conversations.persistance.DatabaseBackend; import eu.siacs.conversations.services.AvatarService; import eu.siacs.conversations.services.QuickConversationsService; @@ -1343,7 +1339,7 @@ public class Conversation extends AbstractEntity implements Blockable, Comparabl private void actualizeReplyMessages(List mainList, List messages) { for (Message m : mainList) { if (m.isReplyRestoredFromDb()) { - Element reply = m.getReply(); + Element reply = m.getReplyOrReaction(); if (reply == null) { continue; diff --git a/src/main/java/eu/siacs/conversations/entities/Message.java b/src/main/java/eu/siacs/conversations/entities/Message.java index 54adad23f..b66c5a58a 100644 --- a/src/main/java/eu/siacs/conversations/entities/Message.java +++ b/src/main/java/eu/siacs/conversations/entities/Message.java @@ -1,13 +1,9 @@ package eu.siacs.conversations.entities; import android.content.ContentValues; -import android.content.Context; import android.database.Cursor; -import android.graphics.Bitmap; import android.graphics.Color; import android.text.SpannableStringBuilder; -import android.text.TextUtils; -import android.text.style.ImageSpan; import android.util.Log; import androidx.annotation.Nullable; @@ -19,7 +15,6 @@ import com.google.common.primitives.Longs; import org.json.JSONException; -import java.io.FileNotFoundException; import java.io.IOException; import java.lang.ref.WeakReference; import java.util.ArrayList; @@ -31,7 +26,6 @@ import java.util.Set; import java.util.concurrent.CopyOnWriteArraySet; import eu.siacs.conversations.Config; -import eu.siacs.conversations.R; import eu.siacs.conversations.crypto.axolotl.AxolotlService; import eu.siacs.conversations.crypto.axolotl.FingerprintStatus; import eu.siacs.conversations.http.URL; @@ -412,7 +406,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable return null; } - public Element getReply() { + public Element getReplyOrReaction() { if (this.payloads == null) return null; for (Element el : this.payloads) { @@ -421,6 +415,12 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable } } + for (Element el : this.payloads) { + if (el.getName().equals("reactions") && el.getNamespace().equals("urn:xmpp:reactions:0")) { + return el; + } + } + return null; } diff --git a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java index 85aef0a38..0c16df6af 100644 --- a/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +++ b/src/main/java/eu/siacs/conversations/services/XmppConnectionService.java @@ -137,7 +137,6 @@ import eu.siacs.conversations.ui.interfaces.OnAvatarPublication; import eu.siacs.conversations.ui.interfaces.OnMediaLoaded; import eu.siacs.conversations.ui.interfaces.OnSearchResultsAvailable; import eu.siacs.conversations.ui.util.ShareUtil; -import eu.siacs.conversations.utils.AccountUtils; import eu.siacs.conversations.utils.Compatibility; import eu.siacs.conversations.utils.ConversationsFileObserver; import eu.siacs.conversations.utils.CryptoHelper; @@ -2324,7 +2323,7 @@ public class XmppConnectionService extends Service { Map> notFoundReplies = null; for (Message m : messages) { - Element reply = m.getReply(); + Element reply = m.getReplyOrReaction(); if (reply == null) { continue; diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 119420596..03cf922b7 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -18,8 +18,6 @@ import android.app.FragmentManager; import android.app.PendingIntent; import android.app.ProgressDialog; import android.content.ActivityNotFoundException; -import android.content.ContentResolver; -import android.content.ContentValues; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -30,7 +28,6 @@ import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Build; import android.os.Bundle; -import android.os.Environment; import android.os.Handler; import android.os.SystemClock; import android.os.VibrationEffect; @@ -38,7 +35,6 @@ import android.os.Vibrator; import android.preference.PreferenceManager; import android.provider.MediaStore; import android.text.Editable; -import android.text.Spannable; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.text.format.DateUtils; @@ -63,7 +59,6 @@ import android.widget.AbsListView.OnScrollListener; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.CheckBox; -import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupMenu; import android.widget.TextView.OnEditorActionListener; @@ -75,7 +70,6 @@ import androidx.annotation.NonNull; import androidx.annotation.StringRes; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.content.res.AppCompatResources; -import androidx.core.content.ContextCompat; import androidx.core.view.inputmethod.InputConnectionCompat; import androidx.core.view.inputmethod.InputContentInfoCompat; import androidx.databinding.DataBindingUtil; @@ -86,7 +80,6 @@ import com.google.common.collect.ImmutableList; import org.jetbrains.annotations.NotNull; -import java.net.URL; import java.util.AbstractMap; import java.util.ArrayList; import java.util.Arrays; @@ -95,7 +88,6 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashSet; import java.util.Iterator; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; @@ -129,7 +121,6 @@ import eu.siacs.conversations.services.XmppConnectionService; import eu.siacs.conversations.ui.adapter.CommandAdapter; import eu.siacs.conversations.ui.adapter.MediaPreviewAdapter; import eu.siacs.conversations.ui.adapter.MessageAdapter; -import eu.siacs.conversations.ui.text.QuoteSpan; import eu.siacs.conversations.ui.util.ActivityResult; import eu.siacs.conversations.ui.util.Attachment; import eu.siacs.conversations.ui.util.ConversationMenuConfigurator; @@ -1612,7 +1603,12 @@ public class ConversationFragment extends XmppFragment } private void scrollToReply(Message message) { - Element reply = message.getReply(); + Element reply = message.getReplyOrReaction(); + + if (reply == null) { + previousClickedReply = null; + return; + } String replyId = reply.getAttribute("id"); if (replyId != null) {