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/xhrInterceptor/responseModifiers/loadMoreThread.js b/src/xhrInterceptor/responseModifiers/loadMoreThread.js
index f8da127..abea505 100644
--- a/src/xhrInterceptor/responseModifiers/loadMoreThread.js
+++ b/src/xhrInterceptor/responseModifiers/loadMoreThread.js
@@ -38,8 +38,9 @@
}
const messageOrGapPromises = [];
- messageOrGapPromises.push(Promise.resolve(mogs));
- for (const mog of mogs) {
+ messageOrGapPromises.push(
+ Promise.resolve(mogs.filter(mog => mog !== undefined)));
+ mogs.forEach(mog => {
if (mog instanceof GapModel) {
messageOrGapPromises.push(this.loadGap(forumId, threadId, mog));
}
@@ -50,7 +51,7 @@
}
});
}
- }
+ });
return Promise.all(messageOrGapPromises).then(res => {
// #!if !production
@@ -60,6 +61,7 @@
// #!if !production
console.timeEnd('mergeMessages');
// #!endif
+
if (mogs.some(mog => {
return mog instanceof GapModel ||
mog.getCommentsAndGaps().some(cog => cog instanceof GapModel);