]> Untitled Git - lemmy.git/commitdiff
Adding get_public_key_ext() to ActorType trait.
authorDessalines <tyhou13@gmx.com>
Sat, 25 Apr 2020 02:34:51 +0000 (22:34 -0400)
committerDessalines <tyhou13@gmx.com>
Sat, 25 Apr 2020 02:34:51 +0000 (22:34 -0400)
server/src/apub/community.rs
server/src/apub/community_inbox.rs
server/src/apub/mod.rs
server/src/apub/user.rs

index 05e004eee81a3bf3a7ce71f46271d9c1a1a95bf9..e74a5fd14faecf157bb45a4066673ec508369619 100644 (file)
@@ -38,13 +38,7 @@ impl ToApub for Community {
       .set_outbox(self.get_outbox_url())?
       .set_followers(self.get_followers_url())?;
 
-    let public_key = PublicKey {
-      id: format!("{}#main-key", self.actor_id),
-      owner: self.actor_id.to_owned(),
-      public_key_pem: self.public_key.to_owned().unwrap(),
-    };
-
-    Ok(group.extend(actor_props).extend(public_key.to_ext()))
+    Ok(group.extend(actor_props).extend(self.get_public_key_ext()))
   }
 }
 
@@ -52,6 +46,10 @@ impl ActorType for Community {
   fn actor_id(&self) -> String {
     self.actor_id.to_owned()
   }
+
+  fn public_key(&self) -> String {
+    self.public_key.to_owned().unwrap()
+  }
 }
 
 impl FromApub for CommunityForm {
index af6d39e12e08908eab9023af8e5ebc11fa07d0a1..6931cdf1a7fe40b9c43b9736b39dde834c66bbc3 100644 (file)
@@ -60,8 +60,8 @@ fn handle_follow(
     user_id: user.id,
   };
 
-  // This will fail if they're already a follower
-  CommunityFollower::follow(&conn, &community_follower_form)?;
+  // This will fail if they're already a follower, but ignore the error.
+  CommunityFollower::follow(&conn, &community_follower_form).ok();
 
   accept_follow(&follow, &conn)?;
   Ok(HttpResponse::Ok().finish())
index 0579296888bd411fdecc5231541ae74320b1ea10..9c02d1071fb20a2b18b05221ff02aaec989b7e8c 100644 (file)
@@ -141,6 +141,8 @@ pub trait FromApub {
 pub trait ActorType {
   fn actor_id(&self) -> String;
 
+  fn public_key(&self) -> String;
+
   fn get_inbox_url(&self) -> String {
     format!("{}/inbox", &self.actor_id())
   }
@@ -157,4 +159,13 @@ pub trait ActorType {
   fn get_liked_url(&self) -> String {
     format!("{}/liked", &self.actor_id())
   }
+
+  fn get_public_key_ext(&self) -> PublicKeyExtension {
+    PublicKey {
+      id: format!("{}#main-key", self.actor_id()),
+      owner: self.actor_id(),
+      public_key_pem: self.public_key(),
+    }
+    .to_ext()
+  }
 }
index 274c70a944eb6187a7334294e3fd976fa3f8f04f..88238b5d48fb1e022eb8811c05aa7f457a1ed01a 100644 (file)
@@ -36,13 +36,7 @@ impl ToApub for User_ {
       .set_following(self.get_following_url())?
       .set_liked(self.get_liked_url())?;
 
-    let public_key = PublicKey {
-      id: format!("{}#main-key", self.actor_id),
-      owner: self.actor_id.to_owned(),
-      public_key_pem: self.public_key.to_owned().unwrap(),
-    };
-
-    Ok(person.extend(actor_props).extend(public_key.to_ext()))
+    Ok(person.extend(actor_props).extend(self.get_public_key_ext()))
   }
 }
 
@@ -50,6 +44,10 @@ impl ActorType for User_ {
   fn actor_id(&self) -> String {
     self.actor_id.to_owned()
   }
+
+  fn public_key(&self) -> String {
+    self.public_key.to_owned().unwrap()
+  }
 }
 
 impl FromApub for UserForm {