threadListAvatars: ignore unrelated ViewForum requests

We're only interested in ViewForum requests made to load threads into
the thread list. This change ignores other ViewForum requests (by the
chat feature and the "Mark as Duplicate" dialog) which are not needed.

Fixed: twpowertools:24

Change-Id: I9b684ddf9ade1a81eec97918a4fbd67bf8f490a7
diff --git a/src/contentScripts/communityConsole/utils/AvatarsDB.js b/src/contentScripts/communityConsole/utils/AvatarsDB.js
index 05149b5..f1b09e9 100644
--- a/src/contentScripts/communityConsole/utils/AvatarsDB.js
+++ b/src/contentScripts/communityConsole/utils/AvatarsDB.js
@@ -75,8 +75,19 @@
   }
 
   setUpInvalidationsHandlers() {
-    window.addEventListener(
-        threadListLoadEvent, e => this.handleInvalidationsByListLoad(e));
+    window.addEventListener(threadListLoadEvent, e => {
+      // Ignore ViewForum requests made by the chat feature and the "Mark as
+      // duplicate" dialog.
+      //
+      // All those requests have |maxNum| set to 10 and 20 respectively, while
+      // the requests that we want to handle are the ones to initially load the
+      // thread list (which currently requests 100 threads) and the ones to load
+      // more threads (which request 50 threads).
+      var maxNum = e.detail.body?.['2']?.['1']?.['2'];
+      if (maxNum == 10 || maxNum == 20) return;
+
+      this.handleInvalidationsByListLoad(e);
+    });
     window.addEventListener(
         createMessageLoadEvent, e => this.handleInvalidationByNewMessage(e));
   }