From 1724d8a532bf00eb44b030d33087ab672b4b3a61 Mon Sep 17 00:00:00 2001 From: Grishka Date: Wed, 27 Sep 2023 19:50:59 +0300 Subject: [PATCH] Probably fix #703 --- .../joinmastodon/android/model/Hashtag.java | 15 +++++++++++++++ .../joinmastodon/android/model/Mention.java | 18 ++++++++++++++++++ .../android/ui/text/HtmlParser.java | 4 ++-- 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Hashtag.java b/mastodon/src/main/java/org/joinmastodon/android/model/Hashtag.java index 392a6a298..d69ac319b 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Hashtag.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Hashtag.java @@ -30,4 +30,19 @@ public class Hashtag extends BaseModel implements DisplayItemsParent{ public String getID(){ return name; } + + @Override + public boolean equals(Object o){ + if(this==o) return true; + if(o==null || getClass()!=o.getClass()) return false; + + Hashtag hashtag=(Hashtag) o; + + return name.equals(hashtag.name); + } + + @Override + public int hashCode(){ + return name.hashCode(); + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Mention.java b/mastodon/src/main/java/org/joinmastodon/android/model/Mention.java index 3b20bb714..80188c771 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Mention.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Mention.java @@ -20,4 +20,22 @@ public class Mention extends BaseModel{ ", url='"+url+'\''+ '}'; } + + @Override + public boolean equals(Object o){ + if(this==o) return true; + if(o==null || getClass()!=o.getClass()) return false; + + Mention mention=(Mention) o; + + if(!id.equals(mention.id)) return false; + return url.equals(mention.url); + } + + @Override + public int hashCode(){ + int result=id.hashCode(); + result=31*result+url.hashCode(); + return result; + } } diff --git a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java index 29db56991..cd21344f3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java +++ b/mastodon/src/main/java/org/joinmastodon/android/ui/text/HtmlParser.java @@ -81,10 +81,10 @@ public class HtmlParser{ } } - Map idsByUrl=mentions.stream().collect(Collectors.toMap(m->m.url, m->m.id)); + Map idsByUrl=mentions.stream().distinct().collect(Collectors.toMap(m->m.url, m->m.id)); // Hashtags in remote posts have remote URLs, these have local URLs so they don't match. // Map tagsByUrl=tags.stream().collect(Collectors.toMap(t->t.url, t->t.name)); - Map tagsByTag=tags.stream().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity())); + Map tagsByTag=tags.stream().distinct().collect(Collectors.toMap(t->t.name.toLowerCase(), Function.identity())); final SpannableStringBuilder ssb=new SpannableStringBuilder(); Jsoup.parseBodyFragment(source).body().traverse(new NodeVisitor(){