Bug 1579805 - Allow browser.messages.query to find read or unread messages. r=mkmelin
authorGeoff Lankow <geoff@darktrojan.net>
Thu, 19 Sep 2019 22:02:40 +1200
changeset 36875 e30fb2f1bc3f0cec2e8bc9beedde48d4a3390dd0
parent 36874 76f68ab2dceb3d4534bd9bf4f852be43258ab359
child 36876 592b0b1a57a97f581a6e198a4cb8e1bff38ebd7b
push id395
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:38:57 +0000
reviewersmkmelin
bugs1579805
Bug 1579805 - Allow browser.messages.query to find read or unread messages. r=mkmelin
mail/components/extensions/parent/ext-messages.js
mail/components/extensions/schemas/messages.json
mail/components/extensions/test/xpcshell/test_ext_messages_query.js
--- a/mail/components/extensions/parent/ext-messages.js
+++ b/mail/components/extensions/parent/ext-messages.js
@@ -198,16 +198,22 @@ this.messages = class extends ExtensionA
               onQueryCompleted(collection) {
                 resolve(
                   collection.items.map(glodaMsg => glodaMsg.folderMessage)
                 );
               },
             });
           });
 
+          if (queryInfo.unread !== null) {
+            collectionArray = collectionArray.filter(
+              msg => msg.isRead == !queryInfo.unread
+            );
+          }
+
           return messageListTracker.startList(
             collectionArray,
             context.extension
           );
         },
         async update(messageId, newProperties) {
           let msgHdr = messageTracker.getMessage(messageId);
           if (!msgHdr) {
--- a/mail/components/extensions/schemas/messages.json
+++ b/mail/components/extensions/schemas/messages.json
@@ -110,16 +110,21 @@
                 "optional": true,
                 "description": "Returns only messages with the author matching any configured identity."
               },
               "toMe": {
                 "type": "boolean",
                 "optional": true,
                 "description": "Returns only messages with one or more recipients matching any configured identity."
               },
+              "unread": {
+                "type": "boolean",
+                "optional": true,
+                "description": "Returns only unread (or read if false) messages."
+              },
               "flagged": {
                 "type": "boolean",
                 "optional": true,
                 "description": "Returns only flagged (or unflagged if false) messages."
               },
               "folder": {
                 "$ref": "folders.MailFolder",
                 "optional": true,
--- a/mail/components/extensions/test/xpcshell/test_ext_messages_query.js
+++ b/mail/components/extensions/test/xpcshell/test_ext_messages_query.js
@@ -27,16 +27,17 @@ add_task(async function setup() {
   for (let folder of rootFolder.subFolders) {
     subFolders[folder.name] = folder;
   }
   createMessages(subFolders.test1, 9);
   createMessages(subFolders.test2, 9);
 
   let messages = [...subFolders.test1.messages];
   // NB: Here, the messages are zero-indexed. In the test they're one-indexed.
+  messages[0].markRead(true);
   messages[1].markFlagged(true);
   messages[6].markFlagged(true);
 
   addIdentity(account, messages[5].author.replace(/.*<(.*)>/, "$1"));
   addIdentity(account, messages[2].recipients.replace(/.*<(.*)>/, "$1"));
   Gloda._initMyIdentities();
 
   // Wait for Gloda to re-index the added messages.
@@ -133,16 +134,20 @@ add_task(async function() {
       await subtest({ fromDate: today });
       await subtest({ fromDate: date1 }, 1, 2, 3);
       await subtest({ fromDate: date2 }, 1, 2, 3, 4, 5, 6);
       await subtest({ toDate: date1 }, 4, 5, 6, 7, 8, 9);
       await subtest({ toDate: date2 }, 7, 8, 9);
       await subtest({ fromDate: date1, toDate: date2 });
       await subtest({ fromDate: date2, toDate: date1 }, 4, 5, 6);
 
+      // Unread query. Only message 1 has been read.
+      await subtest({ unread: false }, 1);
+      await subtest({ unread: true }, 2, 3, 4, 5, 6, 7, 8, 9);
+
       // Flagged query. Messages 2 and 7 are flagged.
       await subtest({ flagged: true }, 2, 7);
       await subtest({ flagged: false }, 1, 3, 4, 5, 6, 8, 9);
 
       // Subject query.
       let keyword = referenceMessages[1].subject.split(" ")[1];
       await subtest({ subject: keyword }, 2);
       await subtest({ fullText: keyword }, 2);