Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 3 endpoints for external public mentions to work #139

Merged
merged 4 commits into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 34 additions & 10 deletions server/src/main/java/edu/sjsu/moth/generated/Icon.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// THIS FILE WAS GENERATED BY JSON2JAVA
// IT HAS NOT BEEN CHANGED. (IF IT HAS REMOVE THIS LINE)
// CHANGES MADE:
// * NONE SO FAR
// * ADDED MORE FIELDS: PURPOSE, SIZES, SRC

package edu.sjsu.moth.generated;

Expand All @@ -12,7 +12,7 @@
import java.util.Objects;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "type", "mediaType", "url" })
@JsonPropertyOrder({ "type", "mediaType", "url", "src", "sizes", "purpose" })
public class Icon {

@JsonProperty("type")
Expand All @@ -21,18 +21,24 @@ public class Icon {
public String mediaType;
@JsonProperty("url")
public String url;
@JsonProperty("src")
public String src;
@JsonProperty("sizes")
public String sizes;
@JsonProperty("purpose")
public String purpose;

/**
* No args constructor for use in serialization
*/
public Icon() {
}

public Icon(String type, String mediaType, String url) {
public Icon(String type, String mediaType, String url, String src, String sizes, String purpose) {
super();
this.type = type;
this.mediaType = mediaType;
this.url = url;
this.src = src;
this.sizes = sizes;
this.purpose = purpose;
}

@Override
Expand All @@ -54,6 +60,18 @@ public String toString() {
sb.append('=');
sb.append(((this.url == null) ? "<null>" : this.url));
sb.append(',');
sb.append("src");
sb.append('=');
sb.append(((this.src == null) ? "<null>" : this.src));
sb.append(',');
sb.append("sizes");
sb.append('=');
sb.append(((this.sizes == null) ? "<null>" : this.sizes));
sb.append(',');
sb.append("purpose");
sb.append('=');
sb.append(((this.purpose == null) ? "<null>" : this.purpose));
sb.append(',');
if (sb.charAt((sb.length() - 1)) == ',') {
sb.setCharAt((sb.length() - 1), ']');
} else {
Expand All @@ -68,6 +86,9 @@ public int hashCode() {
result = ((result * 31) + ((this.mediaType == null) ? 0 : this.mediaType.hashCode()));
result = ((result * 31) + ((this.type == null) ? 0 : this.type.hashCode()));
result = ((result * 31) + ((this.url == null) ? 0 : this.url.hashCode()));
result = ((result * 31) + ((this.src == null) ? 0 : this.src.hashCode()));
result = ((result * 31) + ((this.sizes == null) ? 0 : this.sizes.hashCode()));
result = ((result * 31) + ((this.purpose == null) ? 0 : this.purpose.hashCode()));
return result;
}

Expand All @@ -76,11 +97,14 @@ public boolean equals(Object other) {
if (other == this) {
return true;
}
if (!(other instanceof Icon)) {
if (!(other instanceof Icon rhs)) {
return false;
}
Icon rhs = ((Icon) other);
return (((Objects.equals(this.mediaType, rhs.mediaType)) && (Objects.equals(this.type, rhs.type))) && (Objects.equals(this.url, rhs.url)));
return (((Objects.equals(this.mediaType, rhs.mediaType)) && (Objects.equals(this.type,
rhs.type))) && (Objects.equals(
this.url, rhs.url)) && (Objects.equals(this.src, rhs.src)) && (Objects.equals(this.sizes,
rhs.sizes)) && (Objects.equals(
this.purpose, rhs.purpose)));
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import edu.sjsu.moth.generated.Actor;
import edu.sjsu.moth.generated.Attachment;
import edu.sjsu.moth.generated.CustomEmoji;
import edu.sjsu.moth.generated.Icon;
import edu.sjsu.moth.server.db.Account;
import edu.sjsu.moth.server.db.AccountField;
import edu.sjsu.moth.server.db.ExternalStatus;
import edu.sjsu.moth.server.service.AccountService;
import edu.sjsu.moth.server.service.ActorService;
import edu.sjsu.moth.server.service.StatusService;
import edu.sjsu.moth.server.util.MothConfiguration;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
Expand All @@ -31,6 +33,8 @@
import java.util.ArrayList;
import java.util.List;

import static edu.sjsu.moth.server.util.Util.printJsonNode;

@RestController
public class InboxController {
@Autowired
Expand Down Expand Up @@ -110,7 +114,6 @@ public static Mono<Account> convertToAccount(Actor actor) {

@PostMapping("/inbox")
public Mono<ResponseEntity<Object>> inbox(@RequestBody JsonNode inboxNode) {
//handle here
String requestType = inboxNode.get("type").asText();
if (requestType.equals("Delete")) {
return Mono.empty();
Expand Down Expand Up @@ -185,6 +188,57 @@ public Mono<UsersFollowResponse> usersFollowers(@PathVariable String id,
return accountService.usersFollow(id, page, limit, "followers");
}

@GetMapping("/manifest.json")
public Mono<ManifestJSON> manifest() {
String name = MothConfiguration.mothConfiguration.getServerName();
String short_name = MothConfiguration.mothConfiguration.getServerName();

List<Icon> icons = new ArrayList<>();
Icon x32 = new Icon("image/png", null, null, "moth/icons/cyber-moth-32.png", "32x32", "any maskable");
Icon x48 = new Icon("image/png", null, null, "moth/icons/cyber-moth-48.png", "48x48", "any maskable");
Icon x144 = new Icon("image/png", null, null, "moth/icons/cyber-moth-144.png", "144x144", "any maskable");
Icon x256 = new Icon("image/png", null, null, "moth/icons/cyber-moth-256.png", "256x256", "any maskable");
Icon x512 = new Icon("image/png", null, null, "moth/icons/cyber-moth-512x512.png", "512x512", "any maskable");
icons.add(x32);
icons.add(x48);
icons.add(x144);
icons.add(x256);
icons.add(x512);

String theme_color = "#FFFFFF";
String background_color = "#FFFFFF";
String display = "standalone";
String start_url = "/home";
String scope = "/";

// unsure
ShareTarget share_target = new ShareTarget("share?title={title}&text={text}&url={url}", "share", "GET",
"application/x-www-form-urlencoded",
new Params("title", "text", "url"));

List<Shortcut> shortcuts = new ArrayList<>(); //may need to change to null
shortcuts.add(new Shortcut("name", "url"));

return Mono.just(
new ManifestJSON(name, short_name, icons, theme_color, background_color, display, start_url, scope,
share_target, shortcuts));
}

//TODO: add data in Usage
@GetMapping("/nodeinfo/2.0")
public Mono<NodeInfo2> nodeInfo2Mono() {
return Mono.just(new NodeInfo2("2.0", new Software("mastodon", "4.2.8"), List.of("activitypub"),
new Services(List.of(""), List.of("")), new Usage(new Users(0, 0, 0), 0), true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should add a // TODO: to grab from account DB

new Metadata()));
}

@GetMapping("/.well-known/nodeinfo")
public Mono<NodeInfo> nodeInfoMono() {
return Mono.just(new NodeInfo(
List.of(new Link("http://nodeinfo.diaspora.software/ns/schema/2.0", "https://mas.to/nodeinfo/2.0"))));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mas.to -> server name

// added placeholders, hardcoded
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "@context", "id", "type", "totalItems", "first", "next", "partOf", "orderedItems" })
public record UsersFollowResponse(String id, String type, int totalItems, String first, String next, String partOf,
Expand All @@ -194,4 +248,40 @@ public String getContext() {
return "https://www.w3.org/ns/activitystreams";
}
}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "name", "short_name", "icons", "theme_color", "background_color", "display", "start_url",
"scope", "share_target", "shortcuts" })
public record ManifestJSON(String name, String short_name, List<Icon> icons, String theme_color,
String background_color, String display, String start_url, String scope,
ShareTarget share_target, List<Shortcut> shortcuts) {}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "links" })
public record NodeInfo(List<Link> links) {}

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonPropertyOrder({ "version", "software", "protocols", "services", "usage", "openRegistrations", "metadata" })
public record NodeInfo2(String version, Software software, List<String> protocols, Services services, Usage usage,
boolean openRegistrations, Metadata metadata) {}

public record Software(String name, String version) {}

// Unsure if it is List of Strings.
public record Services(List<String> outbound, List<String> inbound) {}

public record Usage(Users user, int localPosts) {}

public record Users(int total, int activeMonth, int activeHalfyear) {}

public record Metadata() {}

public record Shortcut(String name, String url) {}

public record Params(String title, String text, String url) {}

public record ShareTarget(String url_template, String action, String method, String enctype, Params params) {}

public record Link(String rel, String href) {}

}
Loading