Flatten threads: fix for application/json+protobuf responses
When a new message is created in a thread, the thread itself is
reloaded, but via an application/json+protobuf request (array-like data)
instead of a regular text/plain request (object-like data). Since the
code didn't work well for these types of requests, the thread didn't
fully load.
This CL fixes this issue by correctly handling application/json+protobuf
responses in the response modifiers.
An issue with the read-only interceptors has also been fixed, and tests
have been added to ensure that the array-like to object-like and
viceversa transformation functions work properly.
Bug: twpowertools:153
Change-Id: If6cd5adc67d676bf36986f325e791124fa71da51
diff --git a/src/common/protojs.js b/src/common/protojs.js
index a2e2d06..c618cec 100644
--- a/src/common/protojs.js
+++ b/src/common/protojs.js
@@ -20,15 +20,22 @@
input = Array.from(input);
input.shift();
}
+
+ let object = [];
for (let i = 0; i < input.length; ++i) {
- input[i] = inverseCorrectArrayKeys(input[i]);
+ object[i] = inverseCorrectArrayKeys(input[i]);
}
- return input;
+ return object;
}
if (typeof input !== 'object' || input === null) return input;
- let array = [];
+ const keys = Object.keys(input);
+ if (keys.length === 0) return [];
+
+ const maxItem = Math.max(...keys);
+ let array = Array(maxItem).fill(undefined);
+
Object.entries(input).forEach(entry => {
array[entry[0] - 1] = inverseCorrectArrayKeys(entry[1]);
});