fix: lint code
This commit is contained in:
parent
1d877348ed
commit
9b2df05977
14 changed files with 26 additions and 27 deletions
|
|
@ -31,7 +31,7 @@ pub struct CreatePost {
|
|||
impl CreatePost {
|
||||
pub async fn send(note: Note, inbox: Url, data: &Data<DatabaseHandle>) -> Result<(), Error> {
|
||||
print!("Sending reply to {}", ¬e.attributed_to);
|
||||
let create = CreatePost {
|
||||
let create = Self {
|
||||
actor: note.attributed_to.clone(),
|
||||
to: note.to.clone(),
|
||||
object: note,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ where
|
|||
T: Into<anyhow::Error>,
|
||||
{
|
||||
fn from(t: T) -> Self {
|
||||
Error(t.into())
|
||||
Self(t.into())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -35,11 +35,11 @@ pub enum PersonAcceptedActivities {
|
|||
}
|
||||
|
||||
impl DbUser {
|
||||
pub fn new(hostname: &str, name: &str) -> Result<DbUser, Error> {
|
||||
pub fn new(hostname: &str, name: &str) -> Result<Self, Error> {
|
||||
let ap_id = Url::parse(&format!("https://{}/{}", hostname, &name))?.into();
|
||||
let inbox = Url::parse(&format!("https://{}/{}/inbox", hostname, &name))?;
|
||||
let keypair = generate_actor_keypair()?;
|
||||
Ok(DbUser {
|
||||
Ok(Self {
|
||||
name: name.to_string(),
|
||||
ap_id,
|
||||
inbox,
|
||||
|
|
@ -108,7 +108,7 @@ impl Object for DbUser {
|
|||
json: Self::Kind,
|
||||
_data: &Data<Self::DataType>,
|
||||
) -> Result<Self, Self::Error> {
|
||||
Ok(DbUser {
|
||||
Ok(Self {
|
||||
name: json.preferred_username,
|
||||
ap_id: json.id,
|
||||
inbox: json.inbox,
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ impl Object for DbPost {
|
|||
&json.content, &json.id
|
||||
);
|
||||
let creator = json.attributed_to.dereference(data).await?;
|
||||
let post = DbPost {
|
||||
let post = Self {
|
||||
text: json.content,
|
||||
ap_id: json.id.clone(),
|
||||
creator: json.attributed_to.clone(),
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
|
|||
.take(7)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
Url::parse(&format!("https://{}/objects/{}", domain, id))
|
||||
Url::parse(&format!("https://{domain}/objects/{id}"))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@ pub struct Accept {
|
|||
}
|
||||
|
||||
impl Accept {
|
||||
pub fn new(actor: ObjectId<DbUser>, object: Follow, id: Url) -> Accept {
|
||||
Accept {
|
||||
pub fn new(actor: ObjectId<DbUser>, object: Follow, id: Url) -> Self {
|
||||
Self {
|
||||
actor,
|
||||
object,
|
||||
kind: Default::default(),
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ pub struct CreatePost {
|
|||
}
|
||||
|
||||
impl CreatePost {
|
||||
pub fn new(note: Note, id: Url) -> CreatePost {
|
||||
CreatePost {
|
||||
pub fn new(note: Note, id: Url) -> Self {
|
||||
Self {
|
||||
actor: note.attributed_to.clone(),
|
||||
to: note.to.clone(),
|
||||
object: note,
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ pub struct Follow {
|
|||
}
|
||||
|
||||
impl Follow {
|
||||
pub fn new(actor: ObjectId<DbUser>, object: ObjectId<DbUser>, id: Url) -> Follow {
|
||||
Follow {
|
||||
pub fn new(actor: ObjectId<DbUser>, object: ObjectId<DbUser>, id: Url) -> Self {
|
||||
Self {
|
||||
actor,
|
||||
object,
|
||||
kind: Default::default(),
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@ where
|
|||
T: Into<anyhow::Error>,
|
||||
{
|
||||
fn from(t: T) -> Self {
|
||||
Error(t.into())
|
||||
Self(t.into())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ pub async fn new_instance(
|
|||
name: String,
|
||||
) -> Result<FederationConfig<DatabaseHandle>, Error> {
|
||||
let mut system_user = DbUser::new(hostname, "system".into())?;
|
||||
system_user.ap_id = Url::parse(&format!("http://{}/", hostname))?.into();
|
||||
system_user.ap_id = Url::parse(&format!("http://{hostname}/"))?.into();
|
||||
|
||||
let local_user = DbUser::new(hostname, name)?;
|
||||
let database = Arc::new(Database {
|
||||
|
|
@ -70,7 +70,7 @@ impl FromStr for Webserver {
|
|||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
Ok(match s {
|
||||
"axum" => Webserver::Axum,
|
||||
"axum" => Self::Axum,
|
||||
_ => panic!("Invalid webserver parameter, must be either `axum` or `actix-web`"),
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,7 @@ async fn main() -> Result<(), Error> {
|
|||
info!("Start with parameter `axum` or `actix-web` to select the webserver");
|
||||
let webserver = args()
|
||||
.nth(1)
|
||||
.map(|arg| Webserver::from_str(&arg).unwrap())
|
||||
.unwrap_or(Webserver::Axum);
|
||||
.map_or(Webserver::Axum, |arg| Webserver::from_str(&arg).unwrap());
|
||||
|
||||
let alpha = new_instance("localhost:8001", "alpha".to_string()).await?;
|
||||
let beta = new_instance("localhost:8002", "beta".to_string()).await?;
|
||||
|
|
|
|||
|
|
@ -45,11 +45,11 @@ pub enum PersonAcceptedActivities {
|
|||
}
|
||||
|
||||
impl DbUser {
|
||||
pub fn new(hostname: &str, name: String) -> Result<DbUser, Error> {
|
||||
pub fn new(hostname: &str, name: String) -> Result<Self, Error> {
|
||||
let ap_id = Url::parse(&format!("http://{}/{}", hostname, &name))?.into();
|
||||
let inbox = Url::parse(&format!("http://{}/{}/inbox", hostname, &name))?;
|
||||
let keypair = generate_actor_keypair()?;
|
||||
Ok(DbUser {
|
||||
Ok(Self {
|
||||
name,
|
||||
ap_id,
|
||||
inbox,
|
||||
|
|
@ -83,7 +83,7 @@ impl DbUser {
|
|||
}
|
||||
|
||||
pub async fn follow(&self, other: &str, data: &Data<DatabaseHandle>) -> Result<(), Error> {
|
||||
let other: DbUser = webfinger_resolve_actor(other, data).await?;
|
||||
let other: Self = webfinger_resolve_actor(other, data).await?;
|
||||
let id = generate_object_id(data.domain())?;
|
||||
let follow = Follow::new(self.ap_id.clone(), other.ap_id.clone(), id.clone());
|
||||
self.send(follow, vec![other.shared_inbox_or_inbox()], false, data)
|
||||
|
|
@ -96,7 +96,7 @@ impl DbUser {
|
|||
let create = CreatePost::new(post.into_json(data).await?, id.clone());
|
||||
let mut inboxes = vec![];
|
||||
for f in self.followers.clone() {
|
||||
let user: DbUser = ObjectId::from(f).dereference(data).await?;
|
||||
let user: Self = ObjectId::from(f).dereference(data).await?;
|
||||
inboxes.push(user.shared_inbox_or_inbox());
|
||||
}
|
||||
self.send(create, inboxes, true, data).await?;
|
||||
|
|
@ -170,7 +170,7 @@ impl Object for DbUser {
|
|||
}
|
||||
|
||||
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
||||
let user = DbUser {
|
||||
let user = Self {
|
||||
name: json.preferred_username,
|
||||
ap_id: json.id,
|
||||
inbox: json.inbox,
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ pub struct DbPost {
|
|||
}
|
||||
|
||||
impl DbPost {
|
||||
pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<DbPost, Error> {
|
||||
pub fn new(text: String, creator: ObjectId<DbUser>) -> Result<Self, Error> {
|
||||
let ap_id = generate_object_id(creator.inner().domain().unwrap())?.into();
|
||||
Ok(DbPost {
|
||||
Ok(Self {
|
||||
text,
|
||||
ap_id,
|
||||
creator,
|
||||
|
|
@ -80,7 +80,7 @@ impl Object for DbPost {
|
|||
}
|
||||
|
||||
async fn from_json(json: Self::Kind, data: &Data<Self::DataType>) -> Result<Self, Self::Error> {
|
||||
let post = DbPost {
|
||||
let post = Self {
|
||||
text: json.content,
|
||||
ap_id: json.id,
|
||||
creator: json.attributed_to,
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ pub fn generate_object_id(domain: &str) -> Result<Url, ParseError> {
|
|||
.take(7)
|
||||
.map(char::from)
|
||||
.collect();
|
||||
Url::parse(&format!("http://{}/objects/{}", domain, id))
|
||||
Url::parse(&format!("http://{domain}/objects/{id}"))
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue