mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-04-25 07:06:12 +00:00
two-way sync: allow changedProperties to be null to avoid array/object issues
This commit is contained in:
@@ -158,19 +158,35 @@ end
|
|||||||
function ApiContext:write(patch)
|
function ApiContext:write(patch)
|
||||||
local url = ("%s/api/write"):format(self.__baseUrl)
|
local url = ("%s/api/write"):format(self.__baseUrl)
|
||||||
|
|
||||||
local body = {
|
local updated = {}
|
||||||
sessionId = self.__sessionId,
|
for _, update in ipairs(patch.updated) do
|
||||||
removed = patch.removed,
|
local fixedUpdate = {
|
||||||
updated = patch.updated,
|
id = update.id,
|
||||||
}
|
changedName = update.changedName,
|
||||||
|
}
|
||||||
|
|
||||||
|
if next(update.changedProperties) ~= nil then
|
||||||
|
fixedUpdate.changedProperties = update.changedProperties
|
||||||
|
end
|
||||||
|
|
||||||
|
table.insert(updated, fixedUpdate)
|
||||||
|
end
|
||||||
|
|
||||||
-- Only add the 'added' field if the table is non-empty, or else Roblox's
|
-- Only add the 'added' field if the table is non-empty, or else Roblox's
|
||||||
-- JSON implementation will turn the table into an array instead of an
|
-- JSON implementation will turn the table into an array instead of an
|
||||||
-- object, causing API validation to fail.
|
-- object, causing API validation to fail.
|
||||||
|
local added
|
||||||
if next(patch.added) ~= nil then
|
if next(patch.added) ~= nil then
|
||||||
body.added = patch.added
|
added = patch.added
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local body = {
|
||||||
|
sessionId = self.__sessionId,
|
||||||
|
removed = patch.removed,
|
||||||
|
updated = updated,
|
||||||
|
added = added,
|
||||||
|
}
|
||||||
|
|
||||||
body = Http.jsonEncode(body)
|
body = Http.jsonEncode(body)
|
||||||
|
|
||||||
return Http.post(url, body)
|
return Http.post(url, body)
|
||||||
|
|||||||
@@ -34,8 +34,10 @@ pub struct InstanceUpdate {
|
|||||||
pub id: RbxId,
|
pub id: RbxId,
|
||||||
pub changed_name: Option<String>,
|
pub changed_name: Option<String>,
|
||||||
pub changed_class_name: Option<String>,
|
pub changed_class_name: Option<String>,
|
||||||
|
|
||||||
// TODO: Transform from HashMap<String, Option<_>> to something else, since
|
// TODO: Transform from HashMap<String, Option<_>> to something else, since
|
||||||
// null will get lost when decoding from JSON in some languages.
|
// null will get lost when decoding from JSON in some languages.
|
||||||
|
#[serde(default)]
|
||||||
pub changed_properties: HashMap<String, Option<RbxValue>>,
|
pub changed_properties: HashMap<String, Option<RbxValue>>,
|
||||||
pub changed_metadata: Option<InstanceMetadata>,
|
pub changed_metadata: Option<InstanceMetadata>,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user