From c8693eeb3ec11ca5fc11621b201c22e314e79b96 Mon Sep 17 00:00:00 2001 From: Awiteb Date: Sun, 28 Jul 2024 10:55:04 +0300 Subject: [PATCH] feat: Add `accepted_response` col to `incoming_chat` table Signed-off-by: Awiteb --- crates/oxidetalis/src/database/incoming_chat.rs | 10 +++++++--- crates/oxidetalis_entities/src/incoming_chat.rs | 11 +++++++---- .../src/create_incoming_chat_table.rs | 9 +++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/crates/oxidetalis/src/database/incoming_chat.rs b/crates/oxidetalis/src/database/incoming_chat.rs index 2a6dbba..e562199 100644 --- a/crates/oxidetalis/src/database/incoming_chat.rs +++ b/crates/oxidetalis/src/database/incoming_chat.rs @@ -47,9 +47,13 @@ impl IncomingChatExt for DatabaseConnection { ..Default::default() }) .on_conflict( - OnConflict::columns([IncomingChatColumn::RecipientId, IncomingChatColumn::Sender]) - .do_nothing() - .to_owned(), + OnConflict::columns([ + IncomingChatColumn::RecipientId, + IncomingChatColumn::Sender, + IncomingChatColumn::AcceptedResponse, + ]) + .do_nothing() + .to_owned(), ) .exec(self) .await?; diff --git a/crates/oxidetalis_entities/src/incoming_chat.rs b/crates/oxidetalis_entities/src/incoming_chat.rs index 709bb1a..c44393d 100644 --- a/crates/oxidetalis_entities/src/incoming_chat.rs +++ b/crates/oxidetalis_entities/src/incoming_chat.rs @@ -31,12 +31,15 @@ use crate::prelude::*; #[sea_orm(table_name = "incoming_chat")] pub struct Model { #[sea_orm(primary_key)] - pub id: IdCol, - pub recipient_id: IdCol, + pub id: IdCol, + pub recipient_id: IdCol, /// Public key of the sender - pub sender: PublicKey, + pub sender: PublicKey, + /// Whether the chat response accepted or not. + /// This will be `None` if it is chat request, otherwise `bool` + pub accepted_response: Option, /// The timestamp of the request, when it was received - pub in_on: chrono::DateTime, + pub in_on: chrono::DateTime, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/crates/oxidetalis_migrations/src/create_incoming_chat_table.rs b/crates/oxidetalis_migrations/src/create_incoming_chat_table.rs index 0dc03f5..87b7083 100644 --- a/crates/oxidetalis_migrations/src/create_incoming_chat_table.rs +++ b/crates/oxidetalis_migrations/src/create_incoming_chat_table.rs @@ -58,6 +58,12 @@ impl MigrationTrait for Migration { .on_delete(ForeignKeyAction::Cascade), ) .col(ColumnDef::new(IncomingChat::Sender).binary().not_null()) + .col( + ColumnDef::new(IncomingChat::AcceptedResponse) + .boolean() + .null() + .default(Option::::None), + ) .col( ColumnDef::new(IncomingChat::InOn) .timestamp_with_time_zone() @@ -74,6 +80,7 @@ impl MigrationTrait for Migration { .table(IncomingChat::Table) .col(IncomingChat::RecipientId) .col(IncomingChat::Sender) + .col(IncomingChat::AcceptedResponse) .unique() .to_owned(), ) @@ -88,5 +95,7 @@ enum IncomingChat { RecipientId, /// Public key of the sender Sender, + /// Whether the chat response accepted or not + AcceptedResponse, InOn, }