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

follower Autocreate Hotfix #81

Merged
merged 4 commits into from
Jul 20, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package edu.sjsu.moth.server.controller;

import com.fasterxml.jackson.databind.JsonNode;
import edu.sjsu.moth.server.db.Followers;
import edu.sjsu.moth.server.db.FollowersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
Expand All @@ -9,6 +10,8 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.util.ArrayList;

@RestController
public class InboxController {
@Autowired
Expand All @@ -34,7 +37,8 @@ public Mono<String> followerHandler(String id, JsonNode inboxNode, String reques
String follower = inboxNode.get("actor").asText();
if (requestType.equals("Follow")) {
// find id, grab arraylist, append
return followersRepository.findItemById(id).flatMap(followedUser -> {
return followersRepository.findItemById(id).switchIfEmpty(Mono.just(new Followers(id, new ArrayList<>())))
Copy link
Contributor

Choose a reason for hiding this comment

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

i think this could backfire on us. if we get non-existent ids, it will create followers for them. perhaps we should write a CLI command to run that will go through the tables and make sure they are in sync.

for the contact account, we can create it on the fly since it is set by the admin, but these are random requests coming in from the internet.

Copy link
Contributor

Choose a reason for hiding this comment

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

i've been thinking about this more. perhaps it is just a matter of checking to see if the id exists in accounts in the switchIfEmpty before returning the empty array. if it doesn't exist we could return a Mono.error()

.flatMap(followedUser -> {
followedUser.getFollowers().add(follower);
return followersRepository.save(followedUser).thenReturn("done");
});
Expand Down
Loading