feat: add visible flag for works

This commit is contained in:
kdletters
2026-05-27 19:30:10 +08:00
parent a7bba70ca5
commit 8e96c8a67c
29 changed files with 198 additions and 12 deletions

View File

@@ -38,6 +38,7 @@ use spacetimedb::{
use crate::auth::user_account;
const PUZZLE_POINT_INCENTIVE_DEFAULT_U64: u64 = 0;
const WORK_VISIBLE_DEFAULT: bool = true;
/// 拼图 Agent session 真相表。
/// 当前只保存结构化字段与 JSON 草稿,不提前拆出更多编辑态子表。
@@ -112,6 +113,9 @@ pub struct PuzzleWorkProfileRow {
point_incentive_total_half_points: u64,
#[default(PUZZLE_POINT_INCENTIVE_DEFAULT_U64)]
point_incentive_claimed_points: u64,
// ???????????????????????????????
#[default(WORK_VISIBLE_DEFAULT)]
visible: bool,
}
/// 拼图广场公开详情兼容投影。
@@ -125,6 +129,7 @@ pub fn puzzle_gallery_view(ctx: &AnonymousViewContext) -> Vec<PuzzleWorkProfile>
.puzzle_work_profile()
.by_puzzle_work_publication_status()
.filter(PuzzlePublicationStatus::Published)
.filter(|row| row.visible)
.filter_map(
|row| match build_puzzle_work_profile_from_row_without_recent_count(&row) {
Ok(profile) => Some(profile),
@@ -154,6 +159,7 @@ pub fn puzzle_gallery_card_view(ctx: &AnonymousViewContext) -> Vec<PuzzleGallery
.puzzle_work_profile()
.by_puzzle_work_publication_status()
.filter(PuzzlePublicationStatus::Published)
.filter(|row| row.visible)
.filter_map(|row| match build_puzzle_gallery_card_view_row(&row) {
Ok(item) => Some(item),
Err(error) => {
@@ -1578,6 +1584,7 @@ fn update_puzzle_work_tx(
created_at: row.created_at,
updated_at: Timestamp::from_micros_since_unix_epoch(input.updated_at_micros),
published_at: row.published_at,
visible: row.visible,
};
replace_puzzle_work_profile(ctx, &row, next_row);
sync_puzzle_source_session_draft_from_work(ctx, &row, &preview_draft, input.updated_at_micros)?;
@@ -1790,6 +1797,7 @@ fn record_puzzle_work_like_tx(
created_at: row.created_at,
updated_at: liked_at,
published_at: row.published_at,
visible: row.visible,
};
replace_puzzle_work_profile(ctx, &row, next_row);
ctx.db
@@ -1878,6 +1886,7 @@ fn remix_puzzle_work_tx(
created_at: source.created_at,
updated_at: remixed_at,
published_at: source.published_at,
visible: source.visible,
},
);
@@ -1945,6 +1954,7 @@ fn remix_puzzle_work_tx(
created_at: remixed_at,
updated_at: remixed_at,
published_at: None,
visible: true,
});
get_puzzle_agent_session_tx(
@@ -2396,6 +2406,7 @@ fn claim_puzzle_work_point_incentive_tx(
created_at: row.created_at,
updated_at: claimed_at,
published_at: row.published_at,
visible: row.visible,
};
replace_puzzle_work_profile(ctx, &row, next_row);
@@ -3008,6 +3019,7 @@ fn upsert_puzzle_work_profile(ctx: &TxContext, profile: PuzzleWorkProfile) -> Re
published_at: profile
.published_at_micros
.map(Timestamp::from_micros_since_unix_epoch),
visible: existing.visible,
},
);
return Ok(());
@@ -3040,6 +3052,7 @@ fn upsert_puzzle_work_profile(ctx: &TxContext, profile: PuzzleWorkProfile) -> Re
published_at: profile
.published_at_micros
.map(Timestamp::from_micros_since_unix_epoch),
visible: true,
});
Ok(())
}
@@ -3364,6 +3377,7 @@ fn accrue_puzzle_point_incentive(
created_at: row.created_at,
updated_at: Timestamp::from_micros_since_unix_epoch(updated_at_micros),
published_at: row.published_at,
visible: row.visible,
},
);
Ok(())
@@ -3402,6 +3416,7 @@ fn increment_puzzle_profile_play_count(
created_at: row.created_at,
updated_at: Timestamp::from_micros_since_unix_epoch(updated_at_micros),
published_at: row.published_at,
visible: row.visible,
},
);
}