From bd33aebc3defd9fca07de34609445322f0419bba Mon Sep 17 00:00:00 2001 From: Lucien Greathouse Date: Mon, 23 Sep 2019 10:53:11 -0700 Subject: [PATCH] Turn messages into stub SubscribeMessage struct --- src/serve_session.rs | 5 +++-- src/snapshot/patch.rs | 3 +++ src/snapshot/patch_apply.rs | 7 +++++-- src/web/api.rs | 22 +++++++++++++++------- src/web/interface.rs | 3 ++- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/serve_session.rs b/src/serve_session.rs index b7915619..327b66c7 100644 --- a/src/serve_session.rs +++ b/src/serve_session.rs @@ -8,6 +8,7 @@ use crate::{ message_queue::MessageQueue, project::Project, session_id::SessionId, + snapshot::AppliedPatchSet, snapshot::RojoTree, }; @@ -16,7 +17,7 @@ pub struct ServeSession { root_project: Option, session_id: SessionId, tree: Mutex, - message_queue: MessageQueue<()>, // TODO: Real message type + message_queue: MessageQueue, imfs: Imfs, } @@ -42,7 +43,7 @@ impl ServeSession { &self.imfs } - pub fn message_queue(&self) -> &MessageQueue<()> { + pub fn message_queue(&self) -> &MessageQueue { &self.message_queue } diff --git a/src/snapshot/patch.rs b/src/snapshot/patch.rs index c3438cca..ca77df7c 100644 --- a/src/snapshot/patch.rs +++ b/src/snapshot/patch.rs @@ -60,6 +60,7 @@ pub struct PatchUpdate { /// // TODO: Introduce machinery to detect conflicts, like keeping previous + // current values in all fields. +#[derive(Debug, Clone)] pub struct AppliedPatchSet { pub removed: Vec, pub added: Vec, @@ -76,10 +77,12 @@ impl AppliedPatchSet { } } +#[derive(Debug, Clone)] pub struct AppliedPatchAdd { pub instance_id: RbxId, } +#[derive(Debug, Clone)] pub struct AppliedPatchUpdate { pub id: RbxId, diff --git a/src/snapshot/patch_apply.rs b/src/snapshot/patch_apply.rs index 5521f997..0d7c9b78 100644 --- a/src/snapshot/patch_apply.rs +++ b/src/snapshot/patch_apply.rs @@ -5,11 +5,11 @@ use std::collections::HashMap; use rbx_dom_weak::{RbxId, RbxInstanceProperties, RbxValue}; use super::{ - patch::{PatchSet, PatchUpdate}, + patch::{AppliedPatchSet, PatchSet, PatchUpdate}, InstancePropertiesWithMeta, InstanceSnapshot, RojoTree, }; -pub fn apply_patch_set(tree: &mut RojoTree, patch_set: PatchSet) { +pub fn apply_patch_set(tree: &mut RojoTree, patch_set: PatchSet) -> AppliedPatchSet { let mut context = PatchApplyContext::default(); for removed_id in patch_set.removed_instances { @@ -25,6 +25,9 @@ pub fn apply_patch_set(tree: &mut RojoTree, patch_set: PatchSet) { } apply_deferred_properties(context, tree); + + // TODO: Actually calculate patch set + AppliedPatchSet::new() } #[derive(Default)] diff --git a/src/web/api.rs b/src/web/api.rs index 1903de90..6793e089 100644 --- a/src/web/api.rs +++ b/src/web/api.rs @@ -13,8 +13,8 @@ use crate::{ serve_session::ServeSession, web::{ interface::{ - ErrorResponse, Instance, ReadResponse, ServerInfoResponse, SubscribeResponse, - PROTOCOL_VERSION, SERVER_VERSION, + ErrorResponse, Instance, ReadResponse, ServerInfoResponse, SubscribeMessage, + SubscribeResponse, PROTOCOL_VERSION, SERVER_VERSION, }, util::{json, json_ok}, }, @@ -90,11 +90,19 @@ impl ApiService { } Box::new(receiver.then(move |result| match result { - Ok((message_cursor, messages)) => json_ok(SubscribeResponse { - session_id, - message_cursor, - messages, - }), + Ok((message_cursor, messages)) => { + // TODO: Transform applied patch sets into subscribe responses + let api_messages = messages + .into_iter() + .map(|_message| SubscribeMessage) + .collect(); + + json_ok(SubscribeResponse { + session_id, + message_cursor, + messages: api_messages, + }) + } Err(_) => json( ErrorResponse::internal_error("Message queue disconnected sender"), StatusCode::INTERNAL_SERVER_ERROR, diff --git a/src/web/interface.rs b/src/web/interface.rs index ccc7c0c3..c2fd3ca5 100644 --- a/src/web/interface.rs +++ b/src/web/interface.rs @@ -17,7 +17,8 @@ pub(crate) const SERVER_VERSION: &str = env!("CARGO_PKG_VERSION"); pub const PROTOCOL_VERSION: u64 = 3; // TODO -pub type SubscribeMessage = (); +#[derive(Debug, Serialize, Deserialize)] +pub struct SubscribeMessage; #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")]