From e0a9997d7901ec233c5f9b6442d7f97db99393a9 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 03:06:43 +0300
Subject: [PATCH 01/55] chore: Add `chrono` to `oxidetalis_entitys`
dependencies
Signed-off-by: Awiteb
---
Cargo.lock | 1 +
crates/oxidetalis_entities/Cargo.toml | 3 ++-
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/Cargo.lock b/Cargo.lock
index 8c8c1fc..4b1fc6a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1965,6 +1965,7 @@ dependencies = [
name = "oxidetalis_entities"
version = "0.1.0"
dependencies = [
+ "chrono",
"sea-orm",
]
diff --git a/crates/oxidetalis_entities/Cargo.toml b/crates/oxidetalis_entities/Cargo.toml
index b8f6e33..4a444f6 100644
--- a/crates/oxidetalis_entities/Cargo.toml
+++ b/crates/oxidetalis_entities/Cargo.toml
@@ -11,7 +11,8 @@ rust-version.workspace = true
[dependencies]
-sea-orm = {workspace = true }
+sea-orm = { workspace = true }
+chrono = { workspace = true }
[lints.rust]
unsafe_code = "deny"
--
2.45.2
From 71ae2f91450a0a73ee6e0aeb7099ebd05ceaac9d Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 03:15:16 +0300
Subject: [PATCH 02/55] feat: Outgoing chat request table
Signed-off-by: Awiteb
---
crates/oxidetalis_entities/src/lib.rs | 1 +
.../src/outgoing_chat_requests.rs | 57 +++++++++++++++
crates/oxidetalis_entities/src/prelude.rs | 6 ++
crates/oxidetalis_entities/src/users.rs | 13 +++-
.../create_outgoing_chat_requests_table.rs | 71 +++++++++++++++++++
crates/oxidetalis_migrations/src/lib.rs | 6 +-
6 files changed, 152 insertions(+), 2 deletions(-)
create mode 100644 crates/oxidetalis_entities/src/outgoing_chat_requests.rs
create mode 100644 crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
diff --git a/crates/oxidetalis_entities/src/lib.rs b/crates/oxidetalis_entities/src/lib.rs
index 21ae991..649ad31 100644
--- a/crates/oxidetalis_entities/src/lib.rs
+++ b/crates/oxidetalis_entities/src/lib.rs
@@ -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;
diff --git a/crates/oxidetalis_entities/src/outgoing_chat_requests.rs b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
new file mode 100644
index 0000000..35a92b7
--- /dev/null
+++ b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
@@ -0,0 +1,57 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
+
+#[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 for Entity {
+ fn to() -> RelationDef {
+ Relation::SenderId.def()
+ }
+}
+
+impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_entities/src/prelude.rs b/crates/oxidetalis_entities/src/prelude.rs
index ca81639..adcfb97 100644
--- a/crates/oxidetalis_entities/src/prelude.rs
+++ b/crates/oxidetalis_entities/src/prelude.rs
@@ -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,
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index 1bae627..0edad50 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -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 for Entity {
+ fn to() -> RelationDef {
+ Relation::OutChatRequests.def()
+ }
+}
impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
new file mode 100644
index 0000000..3db083c
--- /dev/null
+++ b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
@@ -0,0 +1,71 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
diff --git a/crates/oxidetalis_migrations/src/lib.rs b/crates/oxidetalis_migrations/src/lib.rs
index 83f94c0..b2be56c 100644
--- a/crates/oxidetalis_migrations/src/lib.rs
+++ b/crates/oxidetalis_migrations/src/lib.rs
@@ -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> {
- vec![Box::new(create_users_table::Migration)]
+ vec![
+ Box::new(create_users_table::Migration),
+ Box::new(create_outgoing_chat_requests_table::Migration),
+ ]
}
}
--
2.45.2
From 844adbf699dbc9ba87e19e863a1ee803a458a921 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 03:18:41 +0300
Subject: [PATCH 03/55] feat: Incoming chat request table
Signed-off-by: Awiteb
---
.../src/incoming_chat_requests.rs | 57 ++++++++++++++++
crates/oxidetalis_entities/src/lib.rs | 1 +
crates/oxidetalis_entities/src/prelude.rs | 6 ++
crates/oxidetalis_entities/src/users.rs | 9 +++
.../create_incoming_chat_requests_table.rs | 67 +++++++++++++++++++
crates/oxidetalis_migrations/src/lib.rs | 2 +
6 files changed, 142 insertions(+)
create mode 100644 crates/oxidetalis_entities/src/incoming_chat_requests.rs
create mode 100644 crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
diff --git a/crates/oxidetalis_entities/src/incoming_chat_requests.rs b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
new file mode 100644
index 0000000..5e34c7e
--- /dev/null
+++ b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
@@ -0,0 +1,57 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
+
+#[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 for Entity {
+ fn to() -> RelationDef {
+ Relation::RecipientId.def()
+ }
+}
+
+impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_entities/src/lib.rs b/crates/oxidetalis_entities/src/lib.rs
index 649ad31..0fe9098 100644
--- a/crates/oxidetalis_entities/src/lib.rs
+++ b/crates/oxidetalis_entities/src/lib.rs
@@ -19,6 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
+pub mod incoming_chat_requests;
pub mod outgoing_chat_requests;
pub mod prelude;
pub mod users;
diff --git a/crates/oxidetalis_entities/src/prelude.rs b/crates/oxidetalis_entities/src/prelude.rs
index adcfb97..cd34ded 100644
--- a/crates/oxidetalis_entities/src/prelude.rs
+++ b/crates/oxidetalis_entities/src/prelude.rs
@@ -33,6 +33,12 @@ pub use sea_orm::{
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::{
ActiveModel as OutChatRequestsActiveModel,
Column as OutChatRequestsColumn,
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index 0edad50..24a88cd 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -21,6 +21,7 @@
use sea_orm::entity::prelude::*;
+use super::incoming_chat_requests::Entity as InChatRequestsEntity;
use super::outgoing_chat_requests::Entity as OutChatRequestsEntity;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
@@ -34,10 +35,18 @@ pub struct Model {
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
+ #[sea_orm(has_many = "InChatRequestsEntity")]
+ InChatRequests,
#[sea_orm(has_many = "OutChatRequestsEntity")]
OutChatRequests,
}
+impl Related for Entity {
+ fn to() -> RelationDef {
+ Relation::InChatRequests.def()
+ }
+}
+
impl Related for Entity {
fn to() -> RelationDef {
Relation::OutChatRequests.def()
diff --git a/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
new file mode 100644
index 0000000..b9e1ca5
--- /dev/null
+++ b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
@@ -0,0 +1,67 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
diff --git a/crates/oxidetalis_migrations/src/lib.rs b/crates/oxidetalis_migrations/src/lib.rs
index b2be56c..8a1009f 100644
--- a/crates/oxidetalis_migrations/src/lib.rs
+++ b/crates/oxidetalis_migrations/src/lib.rs
@@ -21,6 +21,7 @@
pub use sea_orm_migration::prelude::*;
+mod create_incoming_chat_requests_table;
mod create_outgoing_chat_requests_table;
mod create_users_table;
@@ -31,6 +32,7 @@ impl MigratorTrait for Migrator {
fn migrations() -> Vec> {
vec![
Box::new(create_users_table::Migration),
+ Box::new(create_incoming_chat_requests_table::Migration),
Box::new(create_outgoing_chat_requests_table::Migration),
]
}
--
2.45.2
From 9215d836de14e904e5acc8e364756a88eb96b056 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 11:16:57 +0300
Subject: [PATCH 04/55] feat: Blacklist table
Signed-off-by: Awiteb
---
crates/oxidetalis_entities/src/blacklist.rs | 56 ++++++++++++++++
crates/oxidetalis_entities/src/lib.rs | 1 +
crates/oxidetalis_entities/src/prelude.rs | 6 ++
crates/oxidetalis_entities/src/users.rs | 9 +++
.../src/create_blacklist_table.rs | 65 +++++++++++++++++++
crates/oxidetalis_migrations/src/lib.rs | 2 +
6 files changed, 139 insertions(+)
create mode 100644 crates/oxidetalis_entities/src/blacklist.rs
create mode 100644 crates/oxidetalis_migrations/src/create_blacklist_table.rs
diff --git a/crates/oxidetalis_entities/src/blacklist.rs b/crates/oxidetalis_entities/src/blacklist.rs
new file mode 100644
index 0000000..6d955a6
--- /dev/null
+++ b/crates/oxidetalis_entities/src/blacklist.rs
@@ -0,0 +1,56 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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 = "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,
+}
+
+#[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 for Entity {
+ fn to() -> RelationDef {
+ Relation::UserId.def()
+ }
+}
+
+impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_entities/src/lib.rs b/crates/oxidetalis_entities/src/lib.rs
index 0fe9098..e758d98 100644
--- a/crates/oxidetalis_entities/src/lib.rs
+++ b/crates/oxidetalis_entities/src/lib.rs
@@ -19,6 +19,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
+pub mod blacklist;
pub mod incoming_chat_requests;
pub mod outgoing_chat_requests;
pub mod prelude;
diff --git a/crates/oxidetalis_entities/src/prelude.rs b/crates/oxidetalis_entities/src/prelude.rs
index cd34ded..8d0b50e 100644
--- a/crates/oxidetalis_entities/src/prelude.rs
+++ b/crates/oxidetalis_entities/src/prelude.rs
@@ -33,6 +33,12 @@ pub use sea_orm::{
SqlErr,
};
+pub use super::blacklist::{
+ ActiveModel as BlacklistActiveModel,
+ Column as BlacklistColumn,
+ Entity as BlacklistEntity,
+ Model as BlacklistModel,
+};
pub use super::incoming_chat_requests::{
ActiveModel as InChatRequestsActiveModel,
Column as InChatRequestsColumn,
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index 24a88cd..9842826 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -21,6 +21,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;
@@ -39,6 +40,8 @@ pub enum Relation {
InChatRequests,
#[sea_orm(has_many = "OutChatRequestsEntity")]
OutChatRequests,
+ #[sea_orm(has_many = "BlacklistEntity")]
+ Blacklist,
}
impl Related for Entity {
@@ -53,4 +56,10 @@ impl Related for Entity {
}
}
+impl Related for Entity {
+ fn to() -> RelationDef {
+ Relation::Blacklist.def()
+ }
+}
+
impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_migrations/src/create_blacklist_table.rs b/crates/oxidetalis_migrations/src/create_blacklist_table.rs
new file mode 100644
index 0000000..e459d2e
--- /dev/null
+++ b/crates/oxidetalis_migrations/src/create_blacklist_table.rs
@@ -0,0 +1,65 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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))
+ .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,
+}
diff --git a/crates/oxidetalis_migrations/src/lib.rs b/crates/oxidetalis_migrations/src/lib.rs
index 8a1009f..b50125c 100644
--- a/crates/oxidetalis_migrations/src/lib.rs
+++ b/crates/oxidetalis_migrations/src/lib.rs
@@ -21,6 +21,7 @@
pub use sea_orm_migration::prelude::*;
+mod create_blacklist_table;
mod create_incoming_chat_requests_table;
mod create_outgoing_chat_requests_table;
mod create_users_table;
@@ -34,6 +35,7 @@ impl MigratorTrait for Migrator {
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_blacklist_table::Migration),
]
}
}
--
2.45.2
From b899dd6ac5bcabd49cd8d474119b6f3d2b6d8faf Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 13:08:32 +0300
Subject: [PATCH 05/55] feat: Whitelist table
Signed-off-by: Awiteb
---
crates/oxidetalis_entities/src/lib.rs | 1 +
crates/oxidetalis_entities/src/prelude.rs | 6 ++
crates/oxidetalis_entities/src/users.rs | 9 +++
crates/oxidetalis_entities/src/whitelist.rs | 56 +++++++++++++++++
.../src/create_whitelist_table.rs | 63 +++++++++++++++++++
crates/oxidetalis_migrations/src/lib.rs | 2 +
6 files changed, 137 insertions(+)
create mode 100644 crates/oxidetalis_entities/src/whitelist.rs
create mode 100644 crates/oxidetalis_migrations/src/create_whitelist_table.rs
diff --git a/crates/oxidetalis_entities/src/lib.rs b/crates/oxidetalis_entities/src/lib.rs
index e758d98..3c72884 100644
--- a/crates/oxidetalis_entities/src/lib.rs
+++ b/crates/oxidetalis_entities/src/lib.rs
@@ -24,3 +24,4 @@ pub mod incoming_chat_requests;
pub mod outgoing_chat_requests;
pub mod prelude;
pub mod users;
+pub mod whitelist;
diff --git a/crates/oxidetalis_entities/src/prelude.rs b/crates/oxidetalis_entities/src/prelude.rs
index 8d0b50e..6d045cb 100644
--- a/crates/oxidetalis_entities/src/prelude.rs
+++ b/crates/oxidetalis_entities/src/prelude.rs
@@ -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,
+};
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index 9842826..c4bf38a 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -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 for Entity {
@@ -62,4 +65,10 @@ impl Related for Entity {
}
}
+impl Related for Entity {
+ fn to() -> RelationDef {
+ Relation::Whitelist.def()
+ }
+}
+
impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_entities/src/whitelist.rs b/crates/oxidetalis_entities/src/whitelist.rs
new file mode 100644
index 0000000..2a72197
--- /dev/null
+++ b/crates/oxidetalis_entities/src/whitelist.rs
@@ -0,0 +1,56 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
+
+#[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 for Entity {
+ fn to() -> RelationDef {
+ Relation::UserId.def()
+ }
+}
+
+impl ActiveModelBehavior for ActiveModel {}
diff --git a/crates/oxidetalis_migrations/src/create_whitelist_table.rs b/crates/oxidetalis_migrations/src/create_whitelist_table.rs
new file mode 100644
index 0000000..027c363
--- /dev/null
+++ b/crates/oxidetalis_migrations/src/create_whitelist_table.rs
@@ -0,0 +1,63 @@
+// OxideTalis Messaging Protocol homeserver core implementation
+// Copyright (c) 2024 OxideTalis Developers
+//
+// 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,
+}
diff --git a/crates/oxidetalis_migrations/src/lib.rs b/crates/oxidetalis_migrations/src/lib.rs
index b50125c..0108570 100644
--- a/crates/oxidetalis_migrations/src/lib.rs
+++ b/crates/oxidetalis_migrations/src/lib.rs
@@ -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),
]
}
}
--
2.45.2
From b712f96f59a687078e7341479bb5a0129852c653 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 14:09:03 +0300
Subject: [PATCH 06/55] change: Change the user id from `integer` to `bigint`
Signed-off-by: Awiteb
---
crates/oxidetalis_entities/src/blacklist.rs | 5 +++--
crates/oxidetalis_entities/src/incoming_chat_requests.rs | 5 +++--
crates/oxidetalis_entities/src/outgoing_chat_requests.rs | 5 +++--
crates/oxidetalis_entities/src/prelude.rs | 3 +++
crates/oxidetalis_entities/src/users.rs | 3 ++-
crates/oxidetalis_entities/src/whitelist.rs | 5 +++--
crates/oxidetalis_migrations/src/create_blacklist_table.rs | 4 ++--
.../src/create_incoming_chat_requests_table.rs | 4 ++--
.../src/create_outgoing_chat_requests_table.rs | 4 ++--
crates/oxidetalis_migrations/src/create_users_table.rs | 2 +-
crates/oxidetalis_migrations/src/create_whitelist_table.rs | 4 ++--
11 files changed, 26 insertions(+), 18 deletions(-)
diff --git a/crates/oxidetalis_entities/src/blacklist.rs b/crates/oxidetalis_entities/src/blacklist.rs
index 6d955a6..30b5ad2 100644
--- a/crates/oxidetalis_entities/src/blacklist.rs
+++ b/crates/oxidetalis_entities/src/blacklist.rs
@@ -23,13 +23,14 @@ use chrono::Utc;
use sea_orm::entity::prelude::*;
use super::users::Entity as UserEntity;
+use crate::prelude::UserId;
#[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,
+ pub id: UserId,
+ pub user_id: UserId,
/// Public key of the target
pub target: String,
pub blacklisted_at: chrono::DateTime,
diff --git a/crates/oxidetalis_entities/src/incoming_chat_requests.rs b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
index 5e34c7e..d3e16e4 100644
--- a/crates/oxidetalis_entities/src/incoming_chat_requests.rs
+++ b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
@@ -23,13 +23,14 @@ use chrono::Utc;
use sea_orm::entity::prelude::*;
use super::users::Entity as UserEntity;
+use crate::prelude::UserId;
#[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,
+ pub id: UserId,
+ pub recipient_id: UserId,
/// Public key of the sender
pub sender: String,
/// The timestamp of the request, when it was received
diff --git a/crates/oxidetalis_entities/src/outgoing_chat_requests.rs b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
index 35a92b7..6df5ed0 100644
--- a/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
+++ b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
@@ -23,13 +23,14 @@ use chrono::Utc;
use sea_orm::entity::prelude::*;
use super::users::Entity as UserEntity;
+use crate::prelude::UserId;
#[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,
+ pub id: UserId,
+ pub sender_id: UserId,
/// Public key of the recipient
pub recipient: String,
/// The timestamp of the request, when it was sent
diff --git a/crates/oxidetalis_entities/src/prelude.rs b/crates/oxidetalis_entities/src/prelude.rs
index 6d045cb..67477f1 100644
--- a/crates/oxidetalis_entities/src/prelude.rs
+++ b/crates/oxidetalis_entities/src/prelude.rs
@@ -33,6 +33,9 @@ pub use sea_orm::{
SqlErr,
};
+/// User ID type
+pub type UserId = i64;
+
pub use super::blacklist::{
ActiveModel as BlacklistActiveModel,
Column as BlacklistColumn,
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index c4bf38a..f33a285 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -25,12 +25,13 @@ 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;
+use crate::prelude::UserId;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "users")]
pub struct Model {
#[sea_orm(primary_key)]
- pub id: i32,
+ pub id: UserId,
pub public_key: String,
pub is_admin: bool,
}
diff --git a/crates/oxidetalis_entities/src/whitelist.rs b/crates/oxidetalis_entities/src/whitelist.rs
index 2a72197..1f4d944 100644
--- a/crates/oxidetalis_entities/src/whitelist.rs
+++ b/crates/oxidetalis_entities/src/whitelist.rs
@@ -23,13 +23,14 @@ use chrono::Utc;
use sea_orm::entity::prelude::*;
use super::users::Entity as UserEntity;
+use crate::prelude::UserId;
#[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,
+ pub id: UserId,
+ pub user_id: UserId,
/// Public key of the target
pub target: String,
pub whitelisted_at: chrono::DateTime,
diff --git a/crates/oxidetalis_migrations/src/create_blacklist_table.rs b/crates/oxidetalis_migrations/src/create_blacklist_table.rs
index e459d2e..2eaf805 100644
--- a/crates/oxidetalis_migrations/src/create_blacklist_table.rs
+++ b/crates/oxidetalis_migrations/src/create_blacklist_table.rs
@@ -34,12 +34,12 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(Blacklist::Id)
- .integer()
+ .big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
- .col(ColumnDef::new(Blacklist::UserId).integer().not_null())
+ .col(ColumnDef::new(Blacklist::UserId).big_integer().not_null())
.col(ColumnDef::new(Blacklist::Target).string().not_null())
.col(ColumnDef::new(Blacklist::Reason).string_len(400))
.col(
diff --git a/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
index b9e1ca5..7289225 100644
--- a/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
+++ b/crates/oxidetalis_migrations/src/create_incoming_chat_requests_table.rs
@@ -34,14 +34,14 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(InChatRequests::Id)
- .integer()
+ .big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(InChatRequests::RecipientId)
- .integer()
+ .big_integer()
.not_null(),
)
.col(ColumnDef::new(InChatRequests::Sender).string().not_null())
diff --git a/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
index 3db083c..7db4b81 100644
--- a/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
+++ b/crates/oxidetalis_migrations/src/create_outgoing_chat_requests_table.rs
@@ -34,14 +34,14 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(OutChatRequests::Id)
- .integer()
+ .big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
.col(
ColumnDef::new(OutChatRequests::SenderId)
- .integer()
+ .big_integer()
.not_null(),
)
.col(
diff --git a/crates/oxidetalis_migrations/src/create_users_table.rs b/crates/oxidetalis_migrations/src/create_users_table.rs
index 71e771e..6e1b671 100644
--- a/crates/oxidetalis_migrations/src/create_users_table.rs
+++ b/crates/oxidetalis_migrations/src/create_users_table.rs
@@ -34,7 +34,7 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(Users::Id)
- .integer()
+ .big_integer()
.not_null()
.auto_increment()
.primary_key(),
diff --git a/crates/oxidetalis_migrations/src/create_whitelist_table.rs b/crates/oxidetalis_migrations/src/create_whitelist_table.rs
index 027c363..d29f837 100644
--- a/crates/oxidetalis_migrations/src/create_whitelist_table.rs
+++ b/crates/oxidetalis_migrations/src/create_whitelist_table.rs
@@ -34,12 +34,12 @@ impl MigrationTrait for Migration {
.if_not_exists()
.col(
ColumnDef::new(Whitelist::Id)
- .integer()
+ .big_integer()
.not_null()
.auto_increment()
.primary_key(),
)
- .col(ColumnDef::new(Whitelist::UserId).integer().not_null())
+ .col(ColumnDef::new(Whitelist::UserId).big_integer().not_null())
.col(ColumnDef::new(Whitelist::Target).string().not_null())
.col(
ColumnDef::new(Whitelist::WhitelistedAt)
--
2.45.2
From 2bac5be8c84c8fbd8021ee84a6b04d1a6227efad Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 14:15:12 +0300
Subject: [PATCH 07/55] chore: Use entities prelude
Signed-off-by: Awiteb
---
crates/oxidetalis_entities/src/blacklist.rs | 3 +--
crates/oxidetalis_entities/src/incoming_chat_requests.rs | 3 +--
crates/oxidetalis_entities/src/outgoing_chat_requests.rs | 3 +--
crates/oxidetalis_entities/src/users.rs | 6 +-----
crates/oxidetalis_entities/src/whitelist.rs | 3 +--
5 files changed, 5 insertions(+), 13 deletions(-)
diff --git a/crates/oxidetalis_entities/src/blacklist.rs b/crates/oxidetalis_entities/src/blacklist.rs
index 30b5ad2..848432d 100644
--- a/crates/oxidetalis_entities/src/blacklist.rs
+++ b/crates/oxidetalis_entities/src/blacklist.rs
@@ -22,8 +22,7 @@
use chrono::Utc;
use sea_orm::entity::prelude::*;
-use super::users::Entity as UserEntity;
-use crate::prelude::UserId;
+use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "blacklist")]
diff --git a/crates/oxidetalis_entities/src/incoming_chat_requests.rs b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
index d3e16e4..2d363cd 100644
--- a/crates/oxidetalis_entities/src/incoming_chat_requests.rs
+++ b/crates/oxidetalis_entities/src/incoming_chat_requests.rs
@@ -22,8 +22,7 @@
use chrono::Utc;
use sea_orm::entity::prelude::*;
-use super::users::Entity as UserEntity;
-use crate::prelude::UserId;
+use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "in_chat_requests")]
diff --git a/crates/oxidetalis_entities/src/outgoing_chat_requests.rs b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
index 6df5ed0..d083e3e 100644
--- a/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
+++ b/crates/oxidetalis_entities/src/outgoing_chat_requests.rs
@@ -22,8 +22,7 @@
use chrono::Utc;
use sea_orm::entity::prelude::*;
-use super::users::Entity as UserEntity;
-use crate::prelude::UserId;
+use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "out_chat_requests")]
diff --git a/crates/oxidetalis_entities/src/users.rs b/crates/oxidetalis_entities/src/users.rs
index f33a285..cd6b172 100644
--- a/crates/oxidetalis_entities/src/users.rs
+++ b/crates/oxidetalis_entities/src/users.rs
@@ -21,11 +21,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;
-use crate::prelude::UserId;
+use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "users")]
diff --git a/crates/oxidetalis_entities/src/whitelist.rs b/crates/oxidetalis_entities/src/whitelist.rs
index 1f4d944..b1bee22 100644
--- a/crates/oxidetalis_entities/src/whitelist.rs
+++ b/crates/oxidetalis_entities/src/whitelist.rs
@@ -22,8 +22,7 @@
use chrono::Utc;
use sea_orm::entity::prelude::*;
-use super::users::Entity as UserEntity;
-use crate::prelude::UserId;
+use crate::prelude::*;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
#[sea_orm(table_name = "whitelist")]
--
2.45.2
From 33b44cb25602e6b78fc9ff4c3ac454c34f5c8aa4 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Tue, 9 Jul 2024 19:23:49 +0300
Subject: [PATCH 08/55] chore: Impl `AsRef` for `ServerEvent`
Signed-off-by: Awiteb
---
crates/oxidetalis/src/extensions.rs | 9 +++++----
crates/oxidetalis/src/websocket/events/server.rs | 6 ++++++
crates/oxidetalis/src/websocket/mod.rs | 16 ++++++++++------
3 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/crates/oxidetalis/src/extensions.rs b/crates/oxidetalis/src/extensions.rs
index 3f4415e..eeee250 100644
--- a/crates/oxidetalis/src/extensions.rs
+++ b/crates/oxidetalis/src/extensions.rs
@@ -19,7 +19,7 @@ use std::sync::Arc;
use chrono::Utc;
use oxidetalis_config::Config;
use rayon::iter::{IntoParallelRefMutIterator, ParallelIterator};
-use salvo::{websocket::Message, Depot};
+use salvo::Depot;
use sea_orm::DatabaseConnection;
use uuid::Uuid;
@@ -87,9 +87,10 @@ impl OnlineUsersExt for OnlineUsers {
let now = Utc::now();
self.write().await.par_iter_mut().for_each(|(_, u)| {
u.pinged_at = now;
- let _ = u.sender.unbounded_send(Ok(Message::from(
- &ServerEvent::ping().sign(&u.shared_secret),
- )));
+ let _ = u.sender.unbounded_send(Ok(ServerEvent::ping()
+ .sign(&u.shared_secret)
+ .as_ref()
+ .into()));
});
}
diff --git a/crates/oxidetalis/src/websocket/events/server.rs b/crates/oxidetalis/src/websocket/events/server.rs
index 225b129..9bd990a 100644
--- a/crates/oxidetalis/src/websocket/events/server.rs
+++ b/crates/oxidetalis/src/websocket/events/server.rs
@@ -101,6 +101,12 @@ impl ServerEvent {
}
}
+impl AsRef for ServerEvent {
+ fn as_ref(&self) -> &Self {
+ self
+ }
+}
+
impl From<&ServerEvent> for Message {
fn from(value: &ServerEvent) -> Self {
Message::text(serde_json::to_string(value).expect("This can't fail"))
diff --git a/crates/oxidetalis/src/websocket/mod.rs b/crates/oxidetalis/src/websocket/mod.rs
index c91479e..ed4a901 100644
--- a/crates/oxidetalis/src/websocket/mod.rs
+++ b/crates/oxidetalis/src/websocket/mod.rs
@@ -132,18 +132,22 @@ async fn handle_socket(
match handle_ws_msg(msg, &nonce_cache, &user_shared_secret).await {
Ok(event) => {
if let Some(server_event) = handle_events(event, &conn_id).await {
- if let Err(err) = sender.unbounded_send(Ok(Message::from(
- &server_event.sign(&user_shared_secret),
- ))) {
+ if let Err(err) = sender.unbounded_send(Ok(server_event
+ .sign(&user_shared_secret)
+ .as_ref()
+ .into()))
+ {
log::error!("Websocket Error: {err}");
break;
}
};
}
Err(err) => {
- if let Err(err) = sender.unbounded_send(Ok(Message::from(
- &ServerEvent::from(err).sign(&user_shared_secret),
- ))) {
+ if let Err(err) = sender.unbounded_send(Ok(ServerEvent::from(err)
+ .sign(&user_shared_secret)
+ .as_ref()
+ .into()))
+ {
log::error!("Websocket Error: {err}");
break;
};
--
2.45.2
From 033a21f733f0b868a6599573b85fb89c16176d71 Mon Sep 17 00:00:00 2001
From: Awiteb
Date: Wed, 10 Jul 2024 20:16:55 +0300
Subject: [PATCH 09/55] chore: Function to return user by its public key
Signed-off-by: Awiteb
---
crates/oxidetalis/src/database/user.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/crates/oxidetalis/src/database/user.rs b/crates/oxidetalis/src/database/user.rs
index 7f52764..3230aa3 100644
--- a/crates/oxidetalis/src/database/user.rs
+++ b/crates/oxidetalis/src/database/user.rs
@@ -28,6 +28,8 @@ pub trait UserTableExt {
async fn users_exists_in_database(&self) -> ApiResult;
/// Register new user
async fn register_user(&self, public_key: &PublicKey, is_admin: bool) -> ApiResult<()>;
+ /// Returns user by its public key
+ async fn get_user_by_pubk(&self, public_key: &PublicKey) -> ApiResult