1
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::big_fish::tables::{big_fish_agent_message, big_fish_creation_session};
|
||||
use crate::runtime::{
|
||||
ProfilePlayedWorkUpsertInput, PublicWorkPlayRecordInput, add_profile_observed_play_time,
|
||||
count_recent_public_work_plays, record_public_work_play, upsert_profile_played_work,
|
||||
count_recent_public_work_plays, record_public_work_like, record_public_work_play,
|
||||
upsert_profile_played_work, PublicWorkLikeRecordInput,
|
||||
};
|
||||
use crate::*;
|
||||
|
||||
@@ -123,6 +124,32 @@ pub fn record_big_fish_play(
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn record_big_fish_like(
|
||||
ctx: &mut ProcedureContext,
|
||||
input: BigFishWorkLikeRecordInput,
|
||||
) -> BigFishWorksProcedureResult {
|
||||
match ctx.try_with_tx(|tx| record_big_fish_like_tx(tx, input.clone())) {
|
||||
Ok(items) => match serde_json::to_string(&items) {
|
||||
Ok(items_json) => BigFishWorksProcedureResult {
|
||||
ok: true,
|
||||
items_json: Some(items_json),
|
||||
error_message: None,
|
||||
},
|
||||
Err(error) => BigFishWorksProcedureResult {
|
||||
ok: false,
|
||||
items_json: None,
|
||||
error_message: Some(error.to_string()),
|
||||
},
|
||||
},
|
||||
Err(message) => BigFishWorksProcedureResult {
|
||||
ok: false,
|
||||
items_json: None,
|
||||
error_message: Some(message),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[spacetimedb::procedure]
|
||||
pub fn remix_big_fish_work(
|
||||
ctx: &mut ProcedureContext,
|
||||
@@ -712,6 +739,60 @@ pub(crate) fn record_big_fish_play_tx(
|
||||
list_big_fish_works_tx(ctx, build_public_big_fish_gallery_list_input())
|
||||
}
|
||||
|
||||
pub(crate) fn record_big_fish_like_tx(
|
||||
ctx: &ReducerContext,
|
||||
input: BigFishWorkLikeRecordInput,
|
||||
) -> Result<Vec<BigFishWorkSummarySnapshot>, String> {
|
||||
let session_id = input.session_id.trim();
|
||||
let user_id = input.user_id.trim();
|
||||
if session_id.is_empty() || user_id.is_empty() {
|
||||
return Err("big_fish like 参数不能为空".to_string());
|
||||
}
|
||||
let session = ctx
|
||||
.db
|
||||
.big_fish_creation_session()
|
||||
.session_id()
|
||||
.find(&session_id.to_string())
|
||||
.filter(|row| row.stage == BigFishCreationStage::Published)
|
||||
.ok_or_else(|| "big_fish 已发布作品不存在,无法点赞".to_string())?;
|
||||
let inserted_like = record_public_work_like(
|
||||
ctx,
|
||||
PublicWorkLikeRecordInput {
|
||||
source_type: "big-fish".to_string(),
|
||||
owner_user_id: session.owner_user_id.clone(),
|
||||
profile_id: session.session_id.clone(),
|
||||
user_id: user_id.to_string(),
|
||||
liked_at_micros: input.liked_at_micros,
|
||||
},
|
||||
)?;
|
||||
|
||||
if inserted_like {
|
||||
let liked_at = Timestamp::from_micros_since_unix_epoch(input.liked_at_micros);
|
||||
let next_session = BigFishCreationSession {
|
||||
session_id: session.session_id.clone(),
|
||||
owner_user_id: session.owner_user_id.clone(),
|
||||
seed_text: session.seed_text.clone(),
|
||||
current_turn: session.current_turn,
|
||||
progress_percent: session.progress_percent,
|
||||
stage: session.stage,
|
||||
anchor_pack_json: session.anchor_pack_json.clone(),
|
||||
draft_json: session.draft_json.clone(),
|
||||
asset_coverage_json: session.asset_coverage_json.clone(),
|
||||
last_assistant_reply: session.last_assistant_reply.clone(),
|
||||
publish_ready: session.publish_ready,
|
||||
play_count: session.play_count,
|
||||
remix_count: session.remix_count,
|
||||
like_count: session.like_count.saturating_add(1),
|
||||
published_at: session.published_at,
|
||||
created_at: session.created_at,
|
||||
updated_at: liked_at,
|
||||
};
|
||||
replace_big_fish_session(ctx, &session, next_session);
|
||||
}
|
||||
|
||||
list_big_fish_works_tx(ctx, build_public_big_fish_gallery_list_input())
|
||||
}
|
||||
|
||||
fn remix_big_fish_work_tx(
|
||||
ctx: &ReducerContext,
|
||||
input: BigFishWorkRemixInput,
|
||||
|
||||
Reference in New Issue
Block a user