merge: admin work visibility controls
This commit is contained in:
@@ -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 草稿,不提前拆出更多编辑态子表。
|
||||
@@ -84,34 +85,37 @@ pub struct PuzzleAgentMessageRow {
|
||||
)]
|
||||
pub struct PuzzleWorkProfileRow {
|
||||
#[primary_key]
|
||||
profile_id: String,
|
||||
work_id: String,
|
||||
owner_user_id: String,
|
||||
source_session_id: Option<String>,
|
||||
author_display_name: String,
|
||||
work_title: String,
|
||||
work_description: String,
|
||||
level_name: String,
|
||||
summary: String,
|
||||
theme_tags_json: String,
|
||||
cover_image_src: Option<String>,
|
||||
cover_asset_id: Option<String>,
|
||||
levels_json: String,
|
||||
publication_status: PuzzlePublicationStatus,
|
||||
play_count: u32,
|
||||
anchor_pack_json: String,
|
||||
publish_ready: bool,
|
||||
created_at: Timestamp,
|
||||
updated_at: Timestamp,
|
||||
published_at: Option<Timestamp>,
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) work_id: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) source_session_id: Option<String>,
|
||||
pub(crate) author_display_name: String,
|
||||
pub(crate) work_title: String,
|
||||
pub(crate) work_description: String,
|
||||
pub(crate) level_name: String,
|
||||
pub(crate) summary: String,
|
||||
pub(crate) theme_tags_json: String,
|
||||
pub(crate) cover_image_src: Option<String>,
|
||||
pub(crate) cover_asset_id: Option<String>,
|
||||
pub(crate) levels_json: String,
|
||||
pub(crate) publication_status: PuzzlePublicationStatus,
|
||||
pub(crate) play_count: u32,
|
||||
pub(crate) anchor_pack_json: String,
|
||||
pub(crate) publish_ready: bool,
|
||||
pub(crate) created_at: Timestamp,
|
||||
pub(crate) updated_at: Timestamp,
|
||||
pub(crate) published_at: Option<Timestamp>,
|
||||
#[default(0)]
|
||||
remix_count: u32,
|
||||
pub(crate) remix_count: u32,
|
||||
#[default(0)]
|
||||
like_count: u32,
|
||||
pub(crate) like_count: u32,
|
||||
#[default(PUZZLE_POINT_INCENTIVE_DEFAULT_U64)]
|
||||
point_incentive_total_half_points: u64,
|
||||
pub(crate) point_incentive_total_half_points: u64,
|
||||
#[default(PUZZLE_POINT_INCENTIVE_DEFAULT_U64)]
|
||||
point_incentive_claimed_points: u64,
|
||||
pub(crate) point_incentive_claimed_points: u64,
|
||||
// 后台可见性开关;默认显示,隐藏后不进入公开列表。
|
||||
#[default(WORK_VISIBLE_DEFAULT)]
|
||||
pub(crate) 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,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user