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 139 additions and 0 deletions
Showing only changes of commit 9215d836de - Show all commits

View 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.
awiteb marked this conversation as resolved
Review

I was thinking we can have one table for blacklist and whitelist.

since at any point in time a user can either be in blacklist or whitelist (or none), instead of doing

add_to_blacklist() {
    // ...
    remove_from_whitelist()?
    // ...
}

it can be a column containing the state, either whitelist or blacklist

I was thinking we can have one table for blacklist and whitelist. since at any point in time a user can either be in blacklist or whitelist (or none), instead of doing ```rust add_to_blacklist() { // ... remove_from_whitelist()? // ... } ``` it can be a column containing the state, either whitelist or blacklist
use chrono::Utc;
use sea_orm::entity::prelude::*;
use super::users::Entity as UserEntity;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "blacklist")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub user_id: i32,
/// Public key of the target
pub target: String,
pub blacklisted_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 {}

View file

@ -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 blacklist;
pub mod incoming_chat_requests; pub mod incoming_chat_requests;
pub mod outgoing_chat_requests; pub mod outgoing_chat_requests;
pub mod prelude; pub mod prelude;

View file

@ -33,6 +33,12 @@ pub use sea_orm::{
SqlErr, SqlErr,
}; };
pub use super::blacklist::{
ActiveModel as BlacklistActiveModel,
Column as BlacklistColumn,
Entity as BlacklistEntity,
Model as BlacklistModel,
};
pub use super::incoming_chat_requests::{ pub use super::incoming_chat_requests::{
ActiveModel as InChatRequestsActiveModel, ActiveModel as InChatRequestsActiveModel,
Column as InChatRequestsColumn, Column as InChatRequestsColumn,

View file

@ -21,6 +21,7 @@
use sea_orm::entity::prelude::*; use sea_orm::entity::prelude::*;
use super::blacklist::Entity as BlacklistEntity;
use super::incoming_chat_requests::Entity as InChatRequestsEntity; use super::incoming_chat_requests::Entity as InChatRequestsEntity;
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity; use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
@ -39,6 +40,8 @@ pub enum Relation {
InChatRequests, InChatRequests,
#[sea_orm(has_many = "OutChatRequestsEntity")] #[sea_orm(has_many = "OutChatRequestsEntity")]
OutChatRequests, OutChatRequests,
#[sea_orm(has_many = "BlacklistEntity")]
Blacklist,
} }
impl Related<InChatRequestsEntity> for Entity { impl Related<InChatRequestsEntity> for Entity {
@ -53,4 +56,10 @@ impl Related<OutChatRequestsEntity> for Entity {
} }
} }
impl Related<BlacklistEntity> for Entity {
fn to() -> RelationDef {
Relation::Blacklist.def()
}
}
impl ActiveModelBehavior for ActiveModel {} impl ActiveModelBehavior for ActiveModel {}

View file

@ -0,0 +1,65 @@
// 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(Blacklist::Table)
.if_not_exists()
.col(
ColumnDef::new(Blacklist::Id)
.integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Blacklist::UserId).integer().not_null())
.col(ColumnDef::new(Blacklist::Target).string().not_null())
.col(ColumnDef::new(Blacklist::Reason).string_len(400))
awiteb marked this conversation as resolved
Review

reason is unused

reason is unused
Review

I forgot to remove it, this should be a feature soon. Is good right?

I forgot to remove it, this should be a feature soon. Is good right?
Review

yah, if you want to add it, I think we can do in this PR, just change the whitelist table (or if we are merging both, it will be a special column for blacklist)

So we can either remove it or add it as a feature

yah, if you want to add it, I think we can do in this PR, just change the whitelist table (or if we are merging both, it will be a special column for blacklist) So we can either remove it or add it as a feature
Review

Let's make it later, since we'll merge them.
I don't want to think about it right now

Let's make it later, since we'll merge them. I don't want to think about it right now
.col(
ColumnDef::new(Blacklist::BlacklistedAt)
.timestamp_with_time_zone()
.not_null(),
)
.to_owned(),
)
.await
}
}
#[derive(DeriveIden)]
enum Blacklist {
Table,
Id,
UserId,
/// Public key of the target
Target,
Reason,
BlacklistedAt,
}

View file

@ -21,6 +21,7 @@
pub use sea_orm_migration::prelude::*; pub use sea_orm_migration::prelude::*;
mod create_blacklist_table;
mod create_incoming_chat_requests_table; 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;
@ -34,6 +35,7 @@ impl MigratorTrait for Migrator {
Box::new(create_users_table::Migration), Box::new(create_users_table::Migration),
Box::new(create_incoming_chat_requests_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),
Box::new(create_blacklist_table::Migration),
] ]
} }
} }