1
This commit is contained in:
@@ -139,6 +139,22 @@ pub struct PublicWorkPlayDailyStat {
|
||||
pub(crate) updated_at: Timestamp,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(
|
||||
accessor = public_work_like,
|
||||
index(accessor = by_public_work_like_work, btree(columns = [source_type, profile_id])),
|
||||
index(accessor = by_public_work_like_user, btree(columns = [user_id]))
|
||||
)]
|
||||
pub struct PublicWorkLike {
|
||||
#[primary_key]
|
||||
pub(crate) like_id: String,
|
||||
// 中文注释:source_type 与 play 统计保持同一套作品类型命名,确保跨玩法 profile_id 不会互相冲突。
|
||||
pub(crate) source_type: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) user_id: String,
|
||||
pub(crate) liked_at: Timestamp,
|
||||
}
|
||||
|
||||
pub(crate) struct ProfilePlayedWorkUpsertInput {
|
||||
pub(crate) user_id: String,
|
||||
pub(crate) world_key: String,
|
||||
@@ -157,6 +173,14 @@ pub(crate) struct PublicWorkPlayRecordInput {
|
||||
pub(crate) played_at_micros: i64,
|
||||
}
|
||||
|
||||
pub(crate) struct PublicWorkLikeRecordInput {
|
||||
pub(crate) source_type: String,
|
||||
pub(crate) owner_user_id: String,
|
||||
pub(crate) profile_id: String,
|
||||
pub(crate) user_id: String,
|
||||
pub(crate) liked_at_micros: i64,
|
||||
}
|
||||
|
||||
#[spacetimedb::table(accessor = profile_membership)]
|
||||
pub struct ProfileMembership {
|
||||
#[primary_key]
|
||||
@@ -778,6 +802,39 @@ pub(crate) fn record_public_work_play(
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn record_public_work_like(
|
||||
ctx: &ReducerContext,
|
||||
input: PublicWorkLikeRecordInput,
|
||||
) -> Result<bool, String> {
|
||||
let source_type = input.source_type.trim();
|
||||
let owner_user_id = input.owner_user_id.trim();
|
||||
let profile_id = input.profile_id.trim();
|
||||
let user_id = input.user_id.trim();
|
||||
if source_type.is_empty()
|
||||
|| owner_user_id.is_empty()
|
||||
|| profile_id.is_empty()
|
||||
|| user_id.is_empty()
|
||||
{
|
||||
return Err("public_work_like 参数不能为空".to_string());
|
||||
}
|
||||
|
||||
let like_id = build_public_work_like_id(source_type, profile_id, user_id);
|
||||
if ctx.db.public_work_like().like_id().find(&like_id).is_some() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
ctx.db.public_work_like().insert(PublicWorkLike {
|
||||
like_id,
|
||||
source_type: source_type.to_string(),
|
||||
owner_user_id: owner_user_id.to_string(),
|
||||
profile_id: profile_id.to_string(),
|
||||
user_id: user_id.to_string(),
|
||||
liked_at: Timestamp::from_micros_since_unix_epoch(input.liked_at_micros),
|
||||
});
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
pub(crate) fn count_recent_public_work_plays(
|
||||
ctx: &ReducerContext,
|
||||
source_type: &str,
|
||||
@@ -817,6 +874,10 @@ fn build_public_work_play_daily_stat_id(
|
||||
format!("{source_type}:{profile_id}:{played_day}")
|
||||
}
|
||||
|
||||
fn build_public_work_like_id(source_type: &str, profile_id: &str, user_id: &str) -> String {
|
||||
format!("{source_type}:{profile_id}:{user_id}")
|
||||
}
|
||||
|
||||
fn ensure_profile_dashboard_state(ctx: &ReducerContext, user_id: &str, updated_at: Timestamp) {
|
||||
if ctx
|
||||
.db
|
||||
|
||||
Reference in New Issue
Block a user