Flatten threads: add UI components to messages
- A quote is added to messages to show which was the previous message in
the reply chain.
- A "reply" button is added to messages to allow users to compose a
comment which is added at the end of the reply chain.
- A bug is fixed in calculating the parent reply ID in the extra info
object. Now parent reply means the first message in a reply chain,
while previous reply means the previous message in the reply chain.
Bug: twpowertools:153
Change-Id: I699507ade52e80287dd634e61f835d53af6a904d
diff --git a/src/xhrInterceptor/responseModifiers/flattenThread.js b/src/xhrInterceptor/responseModifiers/flattenThread.js
index cece8b4..6828772 100644
--- a/src/xhrInterceptor/responseModifiers/flattenThread.js
+++ b/src/xhrInterceptor/responseModifiers/flattenThread.js
@@ -27,8 +27,14 @@
// Add some message data to the payload so the extension can show the parent
// comment/reply in the case of comments.
+ let prevReplyId;
+ let prevReplyParentId;
mogs.forEach(m => {
- const info = this.getAdditionalInformation(m, mogs);
+ const info = this.getAdditionalInformation(
+ m, mogs, prevReplyId, prevReplyParentId);
+ prevReplyId = m.getId();
+ prevReplyParentId = info.parentId;
+
const span = document.createElement('span');
span.textContent = kAdditionalInfoPrefix + JSON.stringify(info);
span.setAttribute('style', 'display: none');
@@ -52,25 +58,36 @@
response[1][8] = response[1][40].length;
return response;
},
- getAdditionalInformation(message, mogs) {
+ getAdditionalInformation(message, mogs, prevReplyId, prevReplyParentId) {
const id = message.getId();
const parentId = message.getParentMessageId();
- const parentMessage =
- parentId ? mogs.find(m => m.getId() === parentId) : null;
- if (!parentMessage) {
+ const authorName = message.getAuthor()?.[1]?.[1];
+ if (!parentId) {
return {
isComment: false,
id,
+ authorName,
};
}
+ let prevId;
+ if (parentId === prevReplyParentId && prevReplyParentId)
+ prevId = prevReplyId;
+ else
+ prevId = parentId;
+
+ const prevMessage =
+ prevId ? mogs.find(m => m.getId() === prevId) : null;
+
return {
isComment: true,
id,
- parentMessage: {
- id: parentId,
- payload: parentMessage.getPayload(),
- author: parentMessage.getAuthor(),
+ authorName,
+ parentId,
+ prevMessage: {
+ id: prevId,
+ payload: prevMessage.getPayload(),
+ author: prevMessage.getAuthor(),
},
};
}