feat: Chat request implementation #14

Manually merged
awiteb merged 55 commits from awiteb/chat-request-and-response into master 2024-07-18 14:21:39 +02:00 AGit
6 changed files with 152 additions and 2 deletions
Showing only changes of commit 71ae2f9145 - Show all commits

View file

@ -19,5 +19,6 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
pub mod outgoing_chat_requests;
pub mod prelude;
pub mod users;

View 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 = "out_chat_requests")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub sender_id: i32,
/// Public key of the recipient
pub recipient: String,
/// The timestamp of the request, when it was sent
pub out_on: chrono::DateTime<Utc>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "UserEntity",
from = "Column::SenderId",
to = "super::users::Column::Id"
on_update = "NoAction",
on_delete = "Cascade"
)]
SenderId,
}
impl Related<UserEntity> for Entity {
fn to() -> RelationDef {
Relation::SenderId.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -33,6 +33,12 @@ pub use sea_orm::{
SqlErr,
};
pub use super::outgoing_chat_requests::{
ActiveModel as OutChatRequestsActiveModel,
Column as OutChatRequestsColumn,
Entity as OutChatRequestsEntity,
Model as OutChatRequestsModel,
};
pub use super::users::{
ActiveModel as UserActiveModel,
Column as UserColumn,

View file

@ -21,6 +21,8 @@
use sea_orm::entity::prelude::*;
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "users")]
pub struct Model {
@ -31,6 +33,15 @@ pub struct Model {
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
pub enum Relation {
#[sea_orm(has_many = "OutChatRequestsEntity")]
OutChatRequests,
}
impl Related<OutChatRequestsEntity> for Entity {
fn to() -> RelationDef {
Relation::OutChatRequests.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,71 @@
// 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(OutChatRequests::Table)
.if_not_exists()
.col(
ColumnDef::new(OutChatRequests::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(OutChatRequests::SenderId)
.integer()
.not_null(),
)
.col(
ColumnDef::new(OutChatRequests::Recipient)
.string()
.not_null(),
)
.col(
ColumnDef::new(OutChatRequests::OutOn)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await
}
}
#[derive(DeriveIden)]
enum OutChatRequests {
Table,
Id,
SenderId,
/// Public key of the recipient
Recipient,
OutOn,
}

View file

@ -21,6 +21,7 @@
pub use sea_orm_migration::prelude::*;
mod create_outgoing_chat_requests_table;
mod create_users_table;
pub struct Migrator;
@ -28,6 +29,9 @@ pub struct Migrator;
#[async_trait::async_trait]
impl MigratorTrait for Migrator {
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
vec![Box::new(create_users_table::Migration)]
vec![
Box::new(create_users_table::Migration),
Box::new(create_outgoing_chat_requests_table::Migration),
]
}
}