feat: Chat request implementation #14
6 changed files with 137 additions and 0 deletions
|
@ -24,3 +24,4 @@ pub mod incoming_chat_requests;
|
|||
pub mod outgoing_chat_requests;
|
||||
pub mod prelude;
|
||||
pub mod users;
|
||||
pub mod whitelist;
|
||||
|
|
|
@ -57,3 +57,9 @@ pub use super::users::{
|
|||
Entity as UserEntity,
|
||||
Model as UserModel,
|
||||
};
|
||||
pub use super::whitelist::{
|
||||
ActiveModel as WhitelistActiveModel,
|
||||
Column as WhitelistColumn,
|
||||
Entity as WhitelistEntity,
|
||||
Model as WhitelistModel,
|
||||
};
|
||||
|
|
|
@ -24,6 +24,7 @@ use sea_orm::entity::prelude::*;
|
|||
use super::blacklist::Entity as BlacklistEntity;
|
||||
use super::incoming_chat_requests::Entity as InChatRequestsEntity;
|
||||
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
|
||||
use super::whitelist::Entity as WhitelistEntity;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "users")]
|
||||
|
@ -42,6 +43,8 @@ pub enum Relation {
|
|||
OutChatRequests,
|
||||
#[sea_orm(has_many = "BlacklistEntity")]
|
||||
Blacklist,
|
||||
#[sea_orm(has_many = "WhitelistEntity")]
|
||||
Whitelist,
|
||||
}
|
||||
|
||||
impl Related<InChatRequestsEntity> for Entity {
|
||||
|
@ -62,4 +65,10 @@ impl Related<BlacklistEntity> for Entity {
|
|||
}
|
||||
}
|
||||
|
||||
impl Related<WhitelistEntity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::Whitelist.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
||||
|
|
56
crates/oxidetalis_entities/src/whitelist.rs
Normal file
56
crates/oxidetalis_entities/src/whitelist.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
// OxideTalis Messaging Protocol homeserver core implementation
|
||||
// Copyright (c) 2024 OxideTalis Developers <otmp@4rs.nl>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
use chrono::Utc;
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
use super::users::Entity as UserEntity;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "whitelist")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: i32,
|
||||
pub user_id: i32,
|
||||
/// Public key of the target
|
||||
pub target: String,
|
||||
pub whitelisted_at: chrono::DateTime<Utc>,
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||
pub enum Relation {
|
||||
#[sea_orm(
|
||||
belongs_to = "UserEntity",
|
||||
from = "Column::UserId",
|
||||
to = "super::users::Column::Id"
|
||||
on_update = "NoAction",
|
||||
on_delete = "Cascade"
|
||||
)]
|
||||
UserId,
|
||||
}
|
||||
|
||||
impl Related<UserEntity> for Entity {
|
||||
fn to() -> RelationDef {
|
||||
Relation::UserId.def()
|
||||
}
|
||||
}
|
||||
|
||||
impl ActiveModelBehavior for ActiveModel {}
|
63
crates/oxidetalis_migrations/src/create_whitelist_table.rs
Normal file
63
crates/oxidetalis_migrations/src/create_whitelist_table.rs
Normal file
|
@ -0,0 +1,63 @@
|
|||
// OxideTalis Messaging Protocol homeserver core implementation
|
||||
// Copyright (c) 2024 OxideTalis Developers <otmp@4rs.nl>
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
|
||||
use sea_orm_migration::prelude::*;
|
||||
|
||||
#[derive(DeriveMigrationName)]
|
||||
pub struct Migration;
|
||||
|
||||
#[async_trait::async_trait]
|
||||
impl MigrationTrait for Migration {
|
||||
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
|
||||
manager
|
||||
.create_table(
|
||||
Table::create()
|
||||
.table(Whitelist::Table)
|
||||
.if_not_exists()
|
||||
.col(
|
||||
ColumnDef::new(Whitelist::Id)
|
||||
.integer()
|
||||
.not_null()
|
||||
.auto_increment()
|
||||
.primary_key(),
|
||||
)
|
||||
.col(ColumnDef::new(Whitelist::UserId).integer().not_null())
|
||||
.col(ColumnDef::new(Whitelist::Target).string().not_null())
|
||||
.col(
|
||||
ColumnDef::new(Whitelist::WhitelistedAt)
|
||||
.timestamp_with_time_zone()
|
||||
.not_null(),
|
||||
)
|
||||
.to_owned(),
|
||||
)
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(DeriveIden)]
|
||||
enum Whitelist {
|
||||
Table,
|
||||
Id,
|
||||
UserId,
|
||||
/// Public key of the target
|
||||
Target,
|
||||
WhitelistedAt,
|
||||
}
|
|
@ -25,6 +25,7 @@ mod create_blacklist_table;
|
|||
mod create_incoming_chat_requests_table;
|
||||
mod create_outgoing_chat_requests_table;
|
||||
mod create_users_table;
|
||||
mod create_whitelist_table;
|
||||
|
||||
pub struct Migrator;
|
||||
|
||||
|
@ -36,6 +37,7 @@ impl MigratorTrait for Migrator {
|
|||
Box::new(create_incoming_chat_requests_table::Migration),
|
||||
Box::new(create_outgoing_chat_requests_table::Migration),
|
||||
Box::new(create_blacklist_table::Migration),
|
||||
Box::new(create_whitelist_table::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue