Add public work read model and smooth puzzle transitions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::*;
|
||||
use spacetimedb::AnonymousViewContext;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
#[spacetimedb::table(
|
||||
@@ -4988,6 +4989,28 @@ fn build_custom_world_profile_snapshot(row: &CustomWorldProfile) -> CustomWorldP
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn custom_world_public_profile_snapshots(
|
||||
ctx: &AnonymousViewContext,
|
||||
) -> Vec<CustomWorldProfileSnapshot> {
|
||||
let mut entries = ctx
|
||||
.db
|
||||
.custom_world_profile()
|
||||
.by_custom_world_profile_publication_status()
|
||||
.filter(CustomWorldPublicationStatus::Published)
|
||||
.filter(|row| row.deleted_at.is_none())
|
||||
.map(|row| build_custom_world_profile_snapshot(&row))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
entries.sort_by(|left, right| {
|
||||
right
|
||||
.published_at_micros
|
||||
.unwrap_or(right.updated_at_micros)
|
||||
.cmp(&left.published_at_micros.unwrap_or(left.updated_at_micros))
|
||||
.then_with(|| left.profile_id.cmp(&right.profile_id))
|
||||
});
|
||||
entries
|
||||
}
|
||||
|
||||
fn build_custom_world_agent_session_snapshot(
|
||||
ctx: &ReducerContext,
|
||||
row: &CustomWorldAgentSession,
|
||||
@@ -5125,6 +5148,29 @@ fn build_custom_world_gallery_entry_snapshot(
|
||||
build_custom_world_gallery_entry_snapshot_with_recent_counts(row, &recent_play_counts)
|
||||
}
|
||||
|
||||
pub(crate) fn custom_world_public_gallery_snapshots(
|
||||
ctx: &AnonymousViewContext,
|
||||
) -> Vec<CustomWorldGalleryEntrySnapshot> {
|
||||
let mut entries = ctx
|
||||
.db
|
||||
.custom_world_gallery_entry()
|
||||
.by_custom_world_gallery_owner_user_id()
|
||||
.filter(""..)
|
||||
.map(|row| {
|
||||
build_custom_world_gallery_entry_snapshot_with_recent_counts(&row, &HashMap::new())
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
entries.sort_by(|left, right| {
|
||||
right
|
||||
.published_at_micros
|
||||
.cmp(&left.published_at_micros)
|
||||
.then_with(|| right.updated_at_micros.cmp(&left.updated_at_micros))
|
||||
.then_with(|| left.profile_id.cmp(&right.profile_id))
|
||||
});
|
||||
entries
|
||||
}
|
||||
|
||||
fn build_custom_world_gallery_entry_snapshot_with_recent_counts(
|
||||
row: &CustomWorldGalleryEntry,
|
||||
recent_play_counts: &HashMap<String, u32>,
|
||||
@@ -5173,6 +5219,10 @@ fn build_public_work_code_from_profile_id(profile_id: &str) -> String {
|
||||
format!("CW-{normalized_digits}")
|
||||
}
|
||||
|
||||
pub(crate) fn build_custom_world_public_work_code(profile_id: &str) -> String {
|
||||
build_public_work_code_from_profile_id(profile_id)
|
||||
}
|
||||
|
||||
fn build_public_user_code_from_owner_user_id(owner_user_id: &str) -> String {
|
||||
owner_user_id
|
||||
.trim_start_matches("user_")
|
||||
|
||||
Reference in New Issue
Block a user