refactor(Instance.java): add back pleroma, akkoma, and pixelfed specific fields
This commit is contained in:
@@ -8,6 +8,7 @@ import org.parceler.Parcel;
|
|||||||
import java.net.IDN;
|
import java.net.IDN;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
public abstract class Instance extends BaseModel{
|
public abstract class Instance extends BaseModel{
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +39,14 @@ public abstract class Instance extends BaseModel{
|
|||||||
// non-standard field in some Mastodon forks
|
// non-standard field in some Mastodon forks
|
||||||
public int maxTootChars;
|
public int maxTootChars;
|
||||||
|
|
||||||
|
// MOSHIDON: we got pleroma babyyyyyy
|
||||||
|
public Pleroma pleroma;
|
||||||
|
public PleromaPollLimits pollLimits;
|
||||||
|
|
||||||
|
// MOSHIDON:
|
||||||
|
/** like uri, but always without scheme and trailing slash */
|
||||||
|
public transient String normalizedUri;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void postprocess() throws ObjectValidationException{
|
public void postprocess() throws ObjectValidationException{
|
||||||
super.postprocess();
|
super.postprocess();
|
||||||
@@ -77,6 +86,35 @@ public abstract class Instance extends BaseModel{
|
|||||||
return getApiVersion("mastodon");
|
return getApiVersion("mastodon");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MOSHIDON:
|
||||||
|
public boolean isAkkoma() {
|
||||||
|
return pleroma != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPixelfed() {
|
||||||
|
return version.contains("compatible; Pixelfed");
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum Feature {
|
||||||
|
BUBBLE_TIMELINE,
|
||||||
|
MACHINE_TRANSLATION
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
case MACHINE_TRANSLATION -> pleromaFeatures
|
||||||
|
.map(f -> f.contains("akkoma:machine_translation"))
|
||||||
|
.orElse(false);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@Parcel
|
@Parcel
|
||||||
public static class Rule{
|
public static class Rule{
|
||||||
public String id;
|
public String id;
|
||||||
@@ -116,4 +154,32 @@ public abstract class Instance extends BaseModel{
|
|||||||
public int minExpiration;
|
public int minExpiration;
|
||||||
public int maxExpiration;
|
public int maxExpiration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MOSHIDON: more pleroma :D
|
||||||
|
@Parcel
|
||||||
|
public static class Pleroma extends BaseModel {
|
||||||
|
public Pleroma.Metadata metadata;
|
||||||
|
|
||||||
|
@Parcel
|
||||||
|
public static class Metadata {
|
||||||
|
public List<String> features;
|
||||||
|
public Pleroma.Metadata.FieldsLimits fieldsLimits;
|
||||||
|
|
||||||
|
@Parcel
|
||||||
|
public static class FieldsLimits {
|
||||||
|
public long maxFields;
|
||||||
|
public long maxRemoteFields;
|
||||||
|
public long nameLength;
|
||||||
|
public long valueLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Parcel
|
||||||
|
public static class PleromaPollLimits {
|
||||||
|
public long maxExpiration;
|
||||||
|
public long maxOptionChars;
|
||||||
|
public long maxOptions;
|
||||||
|
public long minExpiration;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user