From 8fd4e4120665d61916afc596939858557130d6ac Mon Sep 17 00:00:00 2001 From: stom79 Date: Sat, 15 Sep 2018 14:36:19 +0200 Subject: [PATCH] Some other improvements --- .../mastodon/client/Entities/Status.java | 51 +++++++++---------- .../drawers/NotificationsListAdapter.java | 1 - 2 files changed, 25 insertions(+), 27 deletions(-) diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java index bc34f8a1f..79226716b 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/client/Entities/Status.java @@ -714,6 +714,7 @@ public class Status implements Parcelable{ if( !key.startsWith("#") && !key.startsWith("@")) targetedURL.put(key, matcher.group(1)); } + String currentInstance = Helper.getLiveInstance(context); //Get url to account that are unknown Pattern aLink = Pattern.compile("(<\\s?a\\s?href=\"https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})\\/(@[\\/\\w._-]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)"); Matcher matcherALink = aLink.matcher(spannableString.toString()); @@ -721,10 +722,25 @@ public class Status implements Parcelable{ while (matcherALink.find()){ String acct = matcherALink.group(3).replace("@",""); String instance = matcherALink.group(2); - Account account = new Account(); - account.setAcct(acct); - account.setInstance(instance); - accountsMentionUnknown.add(account); + boolean addAccount = true; + for(Mention mention: mentions){ + String[] accountMentionAcct = mention.getAcct().split("@"); + //Different isntance + if( accountMentionAcct.length > 1){ + if( mention.getAcct().equals(acct+"@"+instance)) + addAccount = false; + }else { + if( (mention.getUsername()+"@"+currentInstance).equals(acct+"@"+instance)) + addAccount = false; + } + if( addAccount) { + Account account = new Account(); + account.setAcct(acct); + account.setInstance(instance); + accountsMentionUnknown.add(account); + } + } + } aLink = Pattern.compile("(<\\s?a\\s?href=\"(https?:\\/\\/[\\da-z\\.-]+\\.[a-z\\.]{2,6}[\\/]?[^\"@(\\/tags\\/)]*)\"\\s?[^.]*<\\s?\\/\\s?a\\s?>)"); matcherALink = aLink.matcher(spannableString.toString()); @@ -895,28 +911,11 @@ public class Status implements Parcelable{ spannableStringT.setSpan(new ClickableSpan() { @Override public void onClick(View textView) { - if( type == null || type != RetrieveFeedsAsyncTask.Type.REMOTE_INSTANCE) { - Intent intent = new Intent(context, ShowAccountActivity.class); - Bundle b = new Bundle(); - b.putString("accountId", mention.getId()); - intent.putExtras(b); - context.startActivity(intent); - }else { - String url = mention.getUrl(); - Pattern instanceHost = Pattern.compile("https?:\\/\\/([\\da-z\\.-]+\\.[a-z\\.]{2,6})\\/(@[\\/\\w._-]*)"); - Matcher matcherAcct = instanceHost.matcher(url); - String instance = null, acct = null; - while (matcherAcct.find()){ - instance = matcherAcct.group(1); - acct = matcherAcct.group(2); - } - if( acct != null && instance != null){ - Account account = new Account(); - account.setInstance(instance); - account.setAcct(acct.replace("@","")); - CrossActions.doCrossProfile(context, account); - } - } + Intent intent = new Intent(context, ShowAccountActivity.class); + Bundle b = new Bundle(); + b.putString("accountId", mention.getId()); + intent.putExtras(b); + context.startActivity(intent); } @Override public void updateDrawState(TextPaint ds) { diff --git a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java index d389a0482..b21a247a6 100644 --- a/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java +++ b/app/src/main/java/fr/gouv/etalab/mastodon/drawers/NotificationsListAdapter.java @@ -34,7 +34,6 @@ import android.support.v7.widget.PopupMenu; import android.support.v7.widget.RecyclerView; import android.text.Html; import android.text.method.LinkMovementMethod; -import android.util.Log; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.MenuItem;