From c6d84d628775b102dad7f079d4095e6da93f1b45 Mon Sep 17 00:00:00 2001 From: Natty Date: Mon, 8 Jan 2024 00:07:21 +0100 Subject: [PATCH] Added is_renote --- .../entity_ck/src/entities/note.rs | 1 + ext_calckey_model/migration/src/lib.rs | 2 + .../m20240107_220523_generated_is_quote.rs | 4 +- .../m20240107_224446_generated_is_renote.rs | 45 +++++++++++++++++++ .../client/src/components/MagNote.vue | 7 +-- .../client/src/components/MagNoteDetailed.vue | 3 +- fe_calckey/frontend/client/src/pages/note.vue | 8 +--- .../client/src/scripts-mag/mag-util.ts | 21 ++------- .../magnetar-common/src/types/NoteBase.ts | 2 +- magnetar_sdk/src/types/note.rs | 1 + src/model/data/note.rs | 1 + 11 files changed, 62 insertions(+), 33 deletions(-) create mode 100644 ext_calckey_model/migration/src/m20240107_224446_generated_is_renote.rs diff --git a/ext_calckey_model/entity_ck/src/entities/note.rs b/ext_calckey_model/entity_ck/src/entities/note.rs index 3248610..cc3afe4 100644 --- a/ext_calckey_model/entity_ck/src/entities/note.rs +++ b/ext_calckey_model/entity_ck/src/entities/note.rs @@ -61,6 +61,7 @@ pub struct Model { #[sea_orm(column_name = "updatedAt")] pub updated_at: Option, pub is_quote: Option, + pub is_renote: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/ext_calckey_model/migration/src/lib.rs b/ext_calckey_model/migration/src/lib.rs index f466443..2207cbc 100644 --- a/ext_calckey_model/migration/src/lib.rs +++ b/ext_calckey_model/migration/src/lib.rs @@ -6,6 +6,7 @@ mod m20230729_212237_user_unique_idx; mod m20230806_142918_drop_featured_note_option; mod m20240107_005747_remove_user_groups; mod m20240107_220523_generated_is_quote; +mod m20240107_224446_generated_is_renote; pub struct Migrator; @@ -19,6 +20,7 @@ impl MigratorTrait for Migrator { Box::new(m20230806_142918_drop_featured_note_option::Migration), Box::new(m20240107_005747_remove_user_groups::Migration), Box::new(m20240107_220523_generated_is_quote::Migration), + Box::new(m20240107_224446_generated_is_renote::Migration), ] } } diff --git a/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs b/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs index 75fca48..d7b071f 100644 --- a/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs +++ b/ext_calckey_model/migration/src/m20240107_220523_generated_is_quote.rs @@ -10,7 +10,7 @@ impl MigrationTrait for Migration { db.execute_unprepared( r#" - ALTER TABLE "note" ADD COLUMN "is_quote" BOOLEAN GENERATED ALWAYS AS ( + ALTER TABLE "note" ADD COLUMN "is_quote" BOOLEAN GENERATED ALWAYS AS ( "note"."renoteId" IS NOT NULL AND ( @@ -18,6 +18,8 @@ impl MigrationTrait for Migration { OR CARDINALITY(note."fileIds") != 0 OR + "note"."cw" IS NOT NULL AND note."cw" != '' + OR note."hasPoll" = TRUE ) ) STORED diff --git a/ext_calckey_model/migration/src/m20240107_224446_generated_is_renote.rs b/ext_calckey_model/migration/src/m20240107_224446_generated_is_renote.rs new file mode 100644 index 0000000..1317e03 --- /dev/null +++ b/ext_calckey_model/migration/src/m20240107_224446_generated_is_renote.rs @@ -0,0 +1,45 @@ +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> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + ALTER TABLE "note" ADD COLUMN "is_renote" BOOLEAN GENERATED ALWAYS AS ( + "note"."renoteId" IS NOT NULL + AND + ( + (note.text IS NULL OR note.text = '') + AND + CARDINALITY(note."fileIds") = 0 + AND + ("note"."cw" IS NULL OR note."cw" = '') + AND + note."hasPoll" = FALSE + ) + ) STORED + "#, + ) + .await?; + + Ok(()) + } + + async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { + let db = manager.get_connection(); + + db.execute_unprepared( + r#" + ALTER TABLE "note" DROP COLUMN "is_renote"; + "#, + ) + .await?; + + Ok(()) + } +} diff --git a/fe_calckey/frontend/client/src/components/MagNote.vue b/fe_calckey/frontend/client/src/components/MagNote.vue index 910bda7..1251a2d 100644 --- a/fe_calckey/frontend/client/src/components/MagNote.vue +++ b/fe_calckey/frontend/client/src/components/MagNote.vue @@ -8,7 +8,7 @@ v-size="{ max: [500, 350] }" class="tkcbzcuz note-container" :tabindex="!isDeleted ? '-1' : null" - :class="{ renote: isRenote }" + :class="{ renote: note.is_renote }" :id="appearNote.id" > {{ i18n.ts.pinnedNote }} -
+