From 4204f658d7e99fca410d2ecddb044e7aabd60ceb Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 19 Jan 2024 17:44:16 +0100 Subject: [PATCH] Fix issue #1014 - Wrong profiles when enabling remote conversations --- .../mastodon/client/entities/api/Status.java | 5 +++-- .../mastodon/helper/SpannableHelper.java | 17 ++++++++++++++++- .../mastodon/ui/drawer/ComposeAdapter.java | 2 +- .../mastodon/ui/drawer/ConversationAdapter.java | 2 +- .../mastodon/ui/drawer/StatusAdapter.java | 5 ++--- .../ui/drawer/StatusDirectMessageAdapter.java | 2 +- .../ui/drawer/StatusHistoryAdapter.java | 2 +- .../peertube/client/RetrofitPeertubeAPI.java | 1 - 8 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java index 70874d13..3c6598ec 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java +++ b/app/src/main/java/app/fedilab/android/mastodon/client/entities/api/Status.java @@ -28,6 +28,7 @@ import java.lang.ref.WeakReference; import java.util.Date; import java.util.List; +import app.fedilab.android.mastodon.helper.Helper; import app.fedilab.android.mastodon.helper.SpannableHelper; import de.timfreiheit.mathjax.android.MathJaxView; @@ -152,9 +153,9 @@ public class Status implements Serializable, Cloneable { return same; } - public synchronized Spannable getSpanContent(Context context, WeakReference viewWeakReference, Callback callback) { + public synchronized Spannable getSpanContent(Context context, boolean checkRemotely, WeakReference viewWeakReference, Callback callback) { if (contentSpan == null) { - contentSpan = SpannableHelper.convert(context, content, this, null, null, viewWeakReference, callback, true, true); + contentSpan = SpannableHelper.convert(context, content, this, null, null, checkRemotely, viewWeakReference, callback, true, true); } return contentSpan; } diff --git a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java index 87cb773f..f6228484 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java +++ b/app/src/main/java/app/fedilab/android/mastodon/helper/SpannableHelper.java @@ -111,6 +111,12 @@ public class SpannableHelper { public static Spannable convert(Context context, String text, Status status, Account account, Announcement announcement, WeakReference viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) { + return convert(context, text, status, account, announcement, false, viewWeakReference, callback, convertHtml, convertMarkdown); + } + + public static Spannable convert(Context context, String text, + Status status, Account account, Announcement announcement, boolean checkRemotely, + WeakReference viewWeakReference, Status.Callback callback, boolean convertHtml, boolean convertMarkdown) { if (text == null) { return null; } @@ -296,14 +302,23 @@ public class SpannableHelper { intent = new Intent(context, ProfileActivity.class); args = new Bundle(); Mention targetedMention = null; + String acct = null; + for (Mention mention : mentions) { if (word.compareToIgnoreCase("@" + mention.username) == 0) { - targetedMention = mention; + if(!checkRemotely) { + targetedMention = mention; + } else { + acct = mention.acct; + } break; } } + if (targetedMention != null) { args.putString(Helper.ARG_USER_ID, targetedMention.id); + } else if( acct != null){ + args.putString(Helper.ARG_MENTION, acct); } else { args.putString(Helper.ARG_MENTION, word); } diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java index 38fd8a43..08541ce9 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ComposeAdapter.java @@ -1395,7 +1395,7 @@ public class ComposeAdapter extends RecyclerView.Adapter(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(position))), TextView.BufferType.SPANNABLE); holder.binding.statusContent.setMovementMethod(LongClickLinkMovementMethod.getInstance()); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java index fb35d988..f817f6ff 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/ConversationAdapter.java @@ -209,7 +209,7 @@ public class ConversationAdapter extends RecyclerView.Adapter(holder.binding.statusContent), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))), TextView.BufferType.SPANNABLE); //--- DATE --- diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java index 2efefba8..465ebae8 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusAdapter.java @@ -514,7 +514,7 @@ public class StatusAdapter extends RecyclerView.Adapter }); holder.binding.quotedMessage.cardviewContainer.setStrokeColor(ThemeHelper.getAttColor(context, R.attr.colorPrimary)); holder.binding.quotedMessage.statusContent.setText( - statusToDeal.quote.getSpanContent(context, + statusToDeal.quote.getSpanContent(context, remote, new WeakReference<>(holder.binding.quotedMessage.statusContent), null), TextView.BufferType.SPANNABLE); MastodonHelper.loadPPMastodon(holder.binding.quotedMessage.avatar, statusToDeal.quote.account); @@ -1413,10 +1413,9 @@ public class StatusAdapter extends RecyclerView.Adapter } case "direct" -> holder.binding.actionButtonBoost.setVisibility(View.GONE); } - //--- MAIN CONTENT --- holder.binding.statusContent.setText( - statusToDeal.getSpanContent(context, + statusToDeal.getSpanContent(context, remote, new WeakReference<>(holder.binding.statusContent), () -> { recyclerView.post(() -> adapter.notifyItemChanged(holder.getBindingAdapterPosition())); }), diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusDirectMessageAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusDirectMessageAdapter.java index 4523cae7..7407e84a 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusDirectMessageAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusDirectMessageAdapter.java @@ -241,7 +241,7 @@ public class StatusDirectMessageAdapter extends RecyclerView.Adapter(holder.binding.messageContent), () -> mRecyclerView.post(() -> notifyItemChanged(holder.getBindingAdapterPosition()))), TextView.BufferType.SPANNABLE); diff --git a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusHistoryAdapter.java b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusHistoryAdapter.java index 96628a86..9eb5f25d 100644 --- a/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusHistoryAdapter.java +++ b/app/src/main/java/app/fedilab/android/mastodon/ui/drawer/StatusHistoryAdapter.java @@ -55,7 +55,7 @@ public class StatusHistoryAdapter extends RecyclerView.Adapter(holder.binding.statusContent), null), TextView.BufferType.SPANNABLE); if (status.spoiler_text != null && !status.spoiler_text.trim().isEmpty()) { diff --git a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java index ae3ed737..cef50847 100644 --- a/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java +++ b/app/src/main/java/app/fedilab/android/peertube/client/RetrofitPeertubeAPI.java @@ -28,7 +28,6 @@ import android.database.sqlite.SQLiteDatabase; import android.net.Uri; import android.os.Handler; import android.os.Looper; -import android.util.Log; import android.webkit.MimeTypeMap; import android.webkit.URLUtil;