feat: Incoming chat request table
Signed-off-by: Awiteb <a@4rs.nl>
This commit is contained in:
parent
71ae2f9145
commit
844adbf699
6 changed files with 142 additions and 0 deletions
57
crates/oxidetalis_entities/src/incoming_chat_requests.rs
Normal file
57
crates/oxidetalis_entities/src/incoming_chat_requests.rs
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
// 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 = "in_chat_requests")]
|
||||||
|
pub struct Model {
|
||||||
|
#[sea_orm(primary_key)]
|
||||||
|
pub id: i32,
|
||||||
|
pub recipient_id: i32,
|
||||||
|
/// Public key of the sender
|
||||||
|
pub sender: String,
|
||||||
|
/// The timestamp of the request, when it was received
|
||||||
|
pub in_on: chrono::DateTime<Utc>,
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
|
pub enum Relation {
|
||||||
|
#[sea_orm(
|
||||||
|
belongs_to = "UserEntity",
|
||||||
|
from = "Column::RecipientId",
|
||||||
|
to = "super::users::Column::Id"
|
||||||
|
on_update = "NoAction",
|
||||||
|
on_delete = "Cascade"
|
||||||
|
)]
|
||||||
|
RecipientId,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Related<UserEntity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::RecipientId.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ActiveModelBehavior for ActiveModel {}
|
|
@ -19,6 +19,7 @@
|
||||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
// SOFTWARE.
|
// SOFTWARE.
|
||||||
|
|
||||||
|
pub mod incoming_chat_requests;
|
||||||
pub mod outgoing_chat_requests;
|
pub mod outgoing_chat_requests;
|
||||||
pub mod prelude;
|
pub mod prelude;
|
||||||
pub mod users;
|
pub mod users;
|
||||||
|
|
|
@ -33,6 +33,12 @@ pub use sea_orm::{
|
||||||
SqlErr,
|
SqlErr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
pub use super::incoming_chat_requests::{
|
||||||
|
ActiveModel as InChatRequestsActiveModel,
|
||||||
|
Column as InChatRequestsColumn,
|
||||||
|
Entity as InChatRequestsEntity,
|
||||||
|
Model as InChatRequestsModel,
|
||||||
|
};
|
||||||
pub use super::outgoing_chat_requests::{
|
pub use super::outgoing_chat_requests::{
|
||||||
ActiveModel as OutChatRequestsActiveModel,
|
ActiveModel as OutChatRequestsActiveModel,
|
||||||
Column as OutChatRequestsColumn,
|
Column as OutChatRequestsColumn,
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
use sea_orm::entity::prelude::*;
|
use sea_orm::entity::prelude::*;
|
||||||
|
|
||||||
|
use super::incoming_chat_requests::Entity as InChatRequestsEntity;
|
||||||
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
|
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||||
|
@ -34,10 +35,18 @@ pub struct Model {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
|
||||||
pub enum Relation {
|
pub enum Relation {
|
||||||
|
#[sea_orm(has_many = "InChatRequestsEntity")]
|
||||||
|
InChatRequests,
|
||||||
#[sea_orm(has_many = "OutChatRequestsEntity")]
|
#[sea_orm(has_many = "OutChatRequestsEntity")]
|
||||||
OutChatRequests,
|
OutChatRequests,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Related<InChatRequestsEntity> for Entity {
|
||||||
|
fn to() -> RelationDef {
|
||||||
|
Relation::InChatRequests.def()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Related<OutChatRequestsEntity> for Entity {
|
impl Related<OutChatRequestsEntity> for Entity {
|
||||||
fn to() -> RelationDef {
|
fn to() -> RelationDef {
|
||||||
Relation::OutChatRequests.def()
|
Relation::OutChatRequests.def()
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
// 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(InChatRequests::Table)
|
||||||
|
.if_not_exists()
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(InChatRequests::Id)
|
||||||
|
.integer()
|
||||||
|
.not_null()
|
||||||
|
.auto_increment()
|
||||||
|
.primary_key(),
|
||||||
|
)
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(InChatRequests::RecipientId)
|
||||||
|
.integer()
|
||||||
|
.not_null(),
|
||||||
|
)
|
||||||
|
.col(ColumnDef::new(InChatRequests::Sender).string().not_null())
|
||||||
|
.col(
|
||||||
|
ColumnDef::new(InChatRequests::InOn)
|
||||||
|
.timestamp_with_time_zone()
|
||||||
|
.not_null(),
|
||||||
|
)
|
||||||
|
.to_owned(),
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(DeriveIden)]
|
||||||
|
enum InChatRequests {
|
||||||
|
Table,
|
||||||
|
Id,
|
||||||
|
RecipientId,
|
||||||
|
/// Public key of the sender
|
||||||
|
Sender,
|
||||||
|
InOn,
|
||||||
|
}
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
pub use sea_orm_migration::prelude::*;
|
pub use sea_orm_migration::prelude::*;
|
||||||
|
|
||||||
|
mod create_incoming_chat_requests_table;
|
||||||
mod create_outgoing_chat_requests_table;
|
mod create_outgoing_chat_requests_table;
|
||||||
mod create_users_table;
|
mod create_users_table;
|
||||||
|
|
||||||
|
@ -31,6 +32,7 @@ impl MigratorTrait for Migrator {
|
||||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||||
vec![
|
vec![
|
||||||
Box::new(create_users_table::Migration),
|
Box::new(create_users_table::Migration),
|
||||||
|
Box::new(create_incoming_chat_requests_table::Migration),
|
||||||
Box::new(create_outgoing_chat_requests_table::Migration),
|
Box::new(create_outgoing_chat_requests_table::Migration),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue