diff options
author | Vitaly Takmazov | 2018-10-04 12:18:42 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2018-10-04 09:35:24 +0000 |
commit | 5be22ee8963cf45190b13b41dc2dac7b7b0bfb01 (patch) | |
tree | 2ace48b2d11decb816638514157f71269c95e791 /juick-server/src/main/java/com/juick/service | |
parent | 7f9187d8a87a5cd6e2720eac0d03f1c2fcc507ed (diff) |
ActivityPub: persist followers and forward message event to them
Diffstat (limited to 'juick-server/src/main/java/com/juick/service')
-rw-r--r-- | juick-server/src/main/java/com/juick/service/ActivityPubService.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/juick-server/src/main/java/com/juick/service/ActivityPubService.java b/juick-server/src/main/java/com/juick/service/ActivityPubService.java new file mode 100644 index 00000000..6200a75e --- /dev/null +++ b/juick-server/src/main/java/com/juick/service/ActivityPubService.java @@ -0,0 +1,53 @@ +package com.juick.service; + +import com.juick.User; +import com.juick.model.AnonymousUser; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Repository; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; + +import javax.annotation.Nonnull; +import javax.inject.Inject; +import java.util.List; + +@Repository +public class ActivityPubService extends BaseJdbcService implements SocialService { + @Value("${ap_base_uri:http://localhost:8080/}") + private String baseUri; + @Inject + private UserService userService; + + @Transactional(readOnly = true) + @Override + public @Nonnull User getUserByAccountUri(String acct) { + UriComponents baseUriComponents = UriComponentsBuilder.fromUriString(baseUri).build(); + UriComponents acctComponents = UriComponentsBuilder.fromUriString(acct).build(); + if (acctComponents.getHost().equals(baseUriComponents.getHost())) { + // /u/ugnich -> ugnich + String userName = acctComponents.getPath().substring(3); + return userService.getUserByName(userName); + } + return AnonymousUser.INSTANCE; + } + + @Transactional(readOnly = true) + @Override + public @Nonnull List<String> getFollowers(User user) { + return getJdbcTemplate().queryForList("SELECT acct FROM followers WHERE user_id=?", String.class, user.getUid()); + } + + @Transactional + @Override + public void addFollower(User user, String acct) { + getJdbcTemplate().update("INSERT INTO followers(user_id, acct) " + + "VALUES(?, ?)", user.getUid(), acct); + } + + @Transactional + @Override + public void removeFollower(User user, String acct) { + getJdbcTemplate().update("DELETE FROM followers WHERE user_id=? AND acct=?", user.getUid(), acct); + } +} |