blob: 362754fdcc3353ce5a916b166d20abdff60bc7cc (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
package com.juick.server;
import com.juick.server.api.activity.model.Person;
import com.juick.server.api.activity.model.activities.Accept;
import com.juick.service.activities.FollowEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;
import javax.annotation.Nonnull;
import javax.inject.Inject;
import java.io.IOException;
import java.net.URI;
@Component
public class ActivityPubManager implements ApplicationListener<FollowEvent> {
private static final Logger logger = LoggerFactory.getLogger(ActivityPubManager.class);
@Inject
SignatureManager signatureManager;
@Override
public void onApplicationEvent(@Nonnull FollowEvent followEvent) {
logger.info("received follower request");
// automatically accept follower requests
Person me = (Person) signatureManager.getContext(URI.create((String)followEvent.getRequest().getObject()));
Person follower = (Person) signatureManager.getContext(URI.create(followEvent.getRequest().getActor()));
Accept accept = new Accept();
accept.setActor(me.getId());
accept.setObject(followEvent.getRequest());
try {
signatureManager.post(me, follower, accept);
} catch (IOException e) {
logger.info("activitypub exception", e);
}
}
}
|