From bfcff1e19f1bd9f7e4957802e50bfd7dc70b6b15 Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 2 Jun 2023 01:34:31 +0200 Subject: [PATCH] fix null pointer exception closes sk22#539 --- .../joinmastodon/android/model/Instance.java | 17 +++++++++++++++++ .../android/model/TimelineDefinition.java | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java index d89cc8232..12707952f 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/Instance.java @@ -11,6 +11,7 @@ import java.net.IDN; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Optional; @Parcel public class Instance extends BaseModel{ @@ -147,6 +148,22 @@ public class Instance extends BaseModel{ return pleroma != null; } + public boolean hasFeature(Feature feature) { + Optional> pleromaFeatures = Optional.ofNullable(pleroma) + .map(p -> p.metadata) + .map(m -> m.features); + + return switch (feature) { + case BUBBLE_TIMELINE -> pleromaFeatures + .map(f -> f.contains("bubble_timeline")) + .orElse(false); + }; + } + + public enum Feature { + BUBBLE_TIMELINE + } + @Parcel public static class Rule{ public String id; diff --git a/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java b/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java index 313b2d8d2..32b4d0da3 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java +++ b/mastodon/src/main/java/org/joinmastodon/android/model/TimelineDefinition.java @@ -265,7 +265,7 @@ public class TimelineDefinition { @Override public boolean wantsDefault(AccountSession session) { return session.getInstance() - .map(i -> i.isAkkoma() && i.pleroma.metadata.features.contains("bubble_timeline")) + .map(i -> i.hasFeature(Instance.Feature.BUBBLE_TIMELINE)) .orElse(false); } };