fix null pointer exception

closes sk22#539
This commit is contained in:
sk 2023-06-02 01:34:31 +02:00
parent f373e7df3e
commit bfcff1e19f
2 changed files with 18 additions and 1 deletions

View File

@ -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<List<String>> 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;

View File

@ -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);
}
};