diff --git a/src/activitypub/mod.rs b/src/activitypub/mod.rs index 878b8884..2c364461 100644 --- a/src/activitypub/mod.rs +++ b/src/activitypub/mod.rs @@ -83,9 +83,8 @@ pub async fn auth(State(ctx): State, Json(login): Json) -> R .collect(); model::session::Entity::insert( model::session::ActiveModel { - id: sea_orm::ActiveValue::NotSet, + id: sea_orm::ActiveValue::Set(token.clone()), actor: sea_orm::ActiveValue::Set(x.id), - session: sea_orm::ActiveValue::Set(token.clone()), expires: sea_orm::ActiveValue::Set(chrono::Utc::now() + std::time::Duration::from_secs(3600 * 6)), } ) diff --git a/src/activitypub/user/inbox.rs b/src/activitypub/user/inbox.rs index fb640387..1dc21e32 100644 --- a/src/activitypub/user/inbox.rs +++ b/src/activitypub/user/inbox.rs @@ -102,6 +102,7 @@ pub async fn post( .map(|actor| addressing::ActiveModel{ id: sea_orm::ActiveValue::NotSet, + server: sea_orm::Set(Context::server(&actor)), actor: sea_orm::Set(actor), activity: sea_orm::Set(activity_id.clone()), object: sea_orm::Set(Some(object_id.clone())), diff --git a/src/migrations/m20240324_000001_add_addressing.rs b/src/migrations/m20240324_000001_add_addressing.rs index ea8773f9..32aac39b 100644 --- a/src/migrations/m20240324_000001_add_addressing.rs +++ b/src/migrations/m20240324_000001_add_addressing.rs @@ -18,6 +18,7 @@ impl MigrationTrait for Migration { .primary_key() ) .col(ColumnDef::new(Addressing::Actor).string().not_null()) + .col(ColumnDef::new(Addressing::Server).string().not_null()) .col(ColumnDef::new(Addressing::Activity).string().not_null()) .col(ColumnDef::new(Addressing::Object).string().null()) .col(ColumnDef::new(Addressing::Published).date_time().not_null()) @@ -39,6 +40,16 @@ impl MigrationTrait for Migration { ) .await?; + manager + .create_index( + Index::create() + .name("addressing-server-index") + .table(Addressing::Table) + .col(Addressing::Server) + .to_owned() + ) + .await?; + manager .create_index( Index::create() @@ -71,6 +82,10 @@ impl MigrationTrait for Migration { .drop_index(Index::drop().name("addressing-actor-index").to_owned()) .await?; + manager + .drop_index(Index::drop().name("addressing-server-index").to_owned()) + .await?; + manager .drop_index(Index::drop().name("addressing-activity-index").to_owned()) .await?; @@ -88,6 +103,7 @@ enum Addressing { Table, Id, Actor, + Server, Activity, Object, Published, diff --git a/src/model/addressing.rs b/src/model/addressing.rs index 37601649..478aceea 100644 --- a/src/model/addressing.rs +++ b/src/model/addressing.rs @@ -6,6 +6,7 @@ pub struct Model { #[sea_orm(primary_key)] pub id: i64, pub actor: String, + pub server: String, pub activity: String, pub object: Option, pub published: ChronoDateTimeUtc, diff --git a/src/server.rs b/src/server.rs index 0623ace6..ae9951f7 100644 --- a/src/server.rs +++ b/src/server.rs @@ -41,8 +41,6 @@ impl Context { } } - // TODO maybe redo these with enums? idk - /// get full user id uri pub fn uid(&self, id: String) -> String { self.uri("users", id) @@ -58,7 +56,7 @@ impl Context { self.uri("activities", id) } - /// get bare uri, usually an uuid but unspecified + /// get bare id, usually an uuid but unspecified pub fn id(&self, id: String) -> String { if id.starts_with(&self.0.domain) { id.split('/').last().unwrap_or("").to_string() @@ -66,4 +64,14 @@ impl Context { id } } + + pub fn server(id: &str) -> String { + id + .replace("https://", "") + .replace("http://", "") + .split('/') + .next() + .unwrap_or("") + .to_string() + } }