Skip to content

Commit

Permalink
Don't address comments to anyone's followers
Browse files Browse the repository at this point in the history
  • Loading branch information
grishka committed Jul 1, 2020
1 parent 1ead73f commit 6baa443
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
9 changes: 5 additions & 4 deletions src/main/java/smithereen/activitypub/ActivityPubWorker.java
Expand Up @@ -65,14 +65,15 @@ public void run(){
create.to=post.to;
create.cc=post.cc;
create.published=post.published;
try{
create.activityPubID=new URI(post.activityPubID.getScheme(), post.activityPubID.getSchemeSpecificPart()+"/activityCreate", null);
}catch(URISyntaxException ignore){}
create.activityPubID=Config.localURI(post.activityPubID.getPath()+"/activityCreate");
try{
boolean sendToFollowers=post.owner.id==post.user.id;
ArrayList<URI> inboxes=new ArrayList<>();
if(sendToFollowers){
inboxes.addAll(UserStorage.getFollowerInboxes(post.owner.id));
if(post.getReplyLevel()==0)
inboxes.addAll(UserStorage.getFollowerInboxes(post.owner.id));
else
inboxes.addAll(PostStorage.getInboxesForPostInteractionForwarding(post));
}else if(post.owner instanceof ForeignUser){
inboxes.add(((ForeignUser)post.owner).inbox);
}
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/smithereen/data/Post.java
Expand Up @@ -58,9 +58,17 @@ protected void fillFromResultSet(ResultSet res) throws SQLException{
summary=res.getString("content_warning");
attributedTo=user.activityPubID;

byte[] rk=res.getBytes("reply_key");
replyKey=Utils.deserializeIntArray(rk);
if(replyKey==null)
replyKey=new int[0];

if(user.id==owner.id){
to=Collections.singletonList(new LinkOrObject(ActivityPub.AS_PUBLIC));
cc=Collections.singletonList(new LinkOrObject(user.getFollowersURL()));
if(replyKey.length==0)
cc=Collections.singletonList(new LinkOrObject(user.getFollowersURL()));
else
cc=Collections.EMPTY_LIST;
}else{
to=Collections.EMPTY_LIST;
cc=Arrays.asList(new LinkOrObject(ActivityPub.AS_PUBLIC), new LinkOrObject(owner.activityPubID));
Expand All @@ -84,11 +92,6 @@ protected void fillFromResultSet(ResultSet res) throws SQLException{

userLink=user.url.toString();

byte[] rk=res.getBytes("reply_key");
replyKey=Utils.deserializeIntArray(rk);
if(replyKey==null)
replyKey=new int[0];

if(replyKey.length>0){
inReplyTo=PostStorage.getActivityPubID(replyKey[replyKey.length-1]);
}
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/smithereen/routes/ActivityPubRoutes.java
Expand Up @@ -111,6 +111,7 @@ public static void registerActivityHandlers(){
registerActivityHandler(ForeignUser.class, Delete.class, ForeignUser.class, new DeletePersonHandler());
}

@SuppressWarnings("SameParameterValue")
private static <A extends Actor, T extends Activity, O extends ActivityPubObject> void registerActivityHandler(@NotNull Class<A> actorClass,
@NotNull Class<T> activityClass,
@NotNull Class<O> objectClass,
Expand All @@ -119,6 +120,7 @@ private static <A extends Actor, T extends Activity, O extends ActivityPubObject
// System.out.println("Registered handler "+handler.getClass().getName()+" for "+actorClass.getSimpleName()+" -> "+activityClass.getSimpleName()+"{"+objectClass.getSimpleName()+"}");
}

@SuppressWarnings("SameParameterValue")
private static <A extends Actor, T extends Activity, N extends Activity, O extends ActivityPubObject> void registerActivityHandler(@NotNull Class<A> actorClass,
@NotNull Class<T> activityClass,
@NotNull Class<N> nestedActivityClass,
Expand All @@ -128,12 +130,13 @@ private static <A extends Actor, T extends Activity, N extends Activity, O exten
// System.out.println("Registered handler "+handler.getClass().getName()+" for "+actorClass.getSimpleName()+" -> "+activityClass.getSimpleName()+"{"+nestedActivityClass.getSimpleName()+"{"+objectClass.getSimpleName()+"}}");
}

@SuppressWarnings("SameParameterValue")
private static <A extends Actor, T extends Activity, N extends Activity, NN extends Activity, O extends ActivityPubObject> void registerActivityHandler(@NotNull Class<A> actorClass,
@NotNull Class<T> activityClass,
@NotNull Class<N> nestedActivityClass,
@NotNull Class<NN> doublyNestedActivityClass,
@NotNull Class<O> objectClass,
@NotNull NestedActivityTypeHandler<A, T, N, O> handler){
@NotNull Class<T> activityClass,
@NotNull Class<N> nestedActivityClass,
@NotNull Class<NN> doublyNestedActivityClass,
@NotNull Class<O> objectClass,
@NotNull NestedActivityTypeHandler<A, T, N, O> handler){
typeHandlers.add(new ActivityTypeHandlerRecord<>(actorClass, activityClass, nestedActivityClass, doublyNestedActivityClass, objectClass, handler));
// System.out.println("Registered handler "+handler.getClass().getName()+" for "+actorClass.getSimpleName()+" -> "+activityClass.getSimpleName()+"{"+nestedActivityClass.getSimpleName()+"{"+doublyNestedActivityClass.getSimpleName()+"{"+objectClass.getSimpleName()+"}}}");
}
Expand Down

0 comments on commit 6baa443

Please sign in to comment.