diff options
author | Vitaly Takmazov | 2018-10-10 15:40:15 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-10 15:40:15 +0300 |
commit | 5a2b506b5ecb56793807aacb47b7615bba80a7cc (patch) | |
tree | b36e28e1fcc0058da11720b5d0c06d28a51905e1 /juick-server/src | |
parent | 07903dbec6fe386940fe373f778e69a153a28e6f (diff) |
ActivityPub: clean up 410 followers
Diffstat (limited to 'juick-server/src')
3 files changed, 25 insertions, 11 deletions
diff --git a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java index 5aecdd33..d494154c 100644 --- a/juick-server/src/main/java/com/juick/server/ActivityPubManager.java +++ b/juick-server/src/main/java/com/juick/server/ActivityPubManager.java @@ -3,6 +3,7 @@ package com.juick.server; import com.juick.Message; import com.juick.User; import com.juick.formatters.PlainTextFormatter; +import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.Image; import com.juick.server.api.activity.model.Note; import com.juick.server.api.activity.model.Person; @@ -29,6 +30,7 @@ import javax.inject.Inject; import java.io.IOException; import java.net.URI; import java.util.Collections; +import java.util.Optional; @Component public class ActivityPubManager implements ActivityListener, NotificationListener { @@ -125,17 +127,20 @@ public class ActivityPubManager implements ActivityListener, NotificationListene Note note = makeNote(msg); Person me = (Person) signatureManager.getContext(URI.create(userUri)).get(); socialService.getFollowers(user).forEach(acct -> { - Person follower = (Person) signatureManager.getContext(URI.create(acct)).get(); - Create create = new Create(); - create.setId(note.getId()); - create.setActor(me.getId()); - create.setPublished(note.getPublished()); - create.setObject(note); - try { - logger.info("Posting to follower {}", follower.getId()); - signatureManager.post(me, follower, create); - } catch (IOException e) { - logger.warn("activitypub exception", e); + Optional<Context> context = signatureManager.getContext(URI.create(acct)); + if (context.isPresent()) { + Person follower = (Person)context.get(); + Create create = new Create(); + create.setId(note.getId()); + create.setActor(me.getId()); + create.setPublished(note.getPublished()); + create.setObject(note); + try { + logger.info("Posting to follower {}", follower.getId()); + signatureManager.post(me, follower, create); + } catch (IOException e) { + logger.warn("activitypub exception", e); + } } }); } diff --git a/juick-server/src/main/java/com/juick/server/SignatureManager.java b/juick-server/src/main/java/com/juick/server/SignatureManager.java index c39cdac9..869edbfc 100644 --- a/juick-server/src/main/java/com/juick/server/SignatureManager.java +++ b/juick-server/src/main/java/com/juick/server/SignatureManager.java @@ -3,10 +3,12 @@ package com.juick.server; import com.fasterxml.jackson.databind.ObjectMapper; import com.juick.server.api.activity.model.Context; import com.juick.server.api.activity.model.Person; +import com.juick.service.activities.DeleteUserEvent; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; import org.springframework.web.client.HttpClientErrorException; @@ -83,6 +85,10 @@ public class SignatureManager { return Optional.of(new RestTemplate().getForEntity(contextUri, Context.class).getBody()); } catch (HttpClientErrorException e) { logger.warn("Cannot identify {}", contextUri); + if (e.getStatusCode().equals(HttpStatus.GONE)) { + logger.warn("Server report {} is gone, deleting", contextUri); + new DeleteUserEvent(this, contextUri.toASCIIString()); + } } return Optional.empty(); } diff --git a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java index 669a28df..357ca29c 100644 --- a/juick-server/src/main/java/com/juick/server/api/activity/Profile.java +++ b/juick-server/src/main/java/com/juick/server/api/activity/Profile.java @@ -274,9 +274,12 @@ public class Profile { if (valid) { if (activity instanceof Follow) { Follow followRequest = (Follow) activity; + String actor = followRequest.getActor(); + Person follower = (Person) signatureManager.getContext(URI.create(actor)).orElseThrow(HttpBadRequestException::new); applicationEventPublisher.publishEvent( new FollowEvent(this, followRequest)); return new ResponseEntity<>(HttpStatus.ACCEPTED); + } if (activity instanceof Undo) { String follower = (String) ((Map) activity.getObject()).get("object"); |