Commits

Anonymous committed 764a569

Fix pseudo email-addresses to contain Facebook user-ids; fix threading to work better.

Comments (0)

Files changed (1)

packages/facescrape/lib/main.js

     window.document.querySelectorAll(".gigaboxx_thread_header_authors > a");
 
   let authors = [];
-  console.log("authorLinks.length: " + authorsLinks.length);
+  console.log("authorsLinks.length: " + authorsLinks.length);
   for (var i = 0; i < authorsLinks.length; ++i) {
-    authors.push(authorsLinks[i].textContent + " <4@facescrape.invalid>");
+    let [,authorId] = authorsLinks[i].href.match(/id=(\d+)/);
+    authors.push(authorsLinks[i].textContent + " <" + authorId + "@facescrape.invalid>");
     console.log("author link: " + authorsLinks[i].textContent);
   }
 
         return;
       }
       
-      console.log("raw facebook message: " + JSON.stringify(msg));
+      //console.log("raw facebook message: " + JSON.stringify(msg));
 
       // build message object
       let msgObj = {};
       msgObj.from = msg.author.name;
-      msgObj.subject = threadData.subject; 
+      msgObj.subject = threadData.subject;
+ 
+      // XXX breaks for threads with more than one page
+      if (index > 0) {
+        msgObj.subject = "Re: " + msgObj.subject;
+      }
+      
       msgObj.date = msg.time_rendered;
-//      msgObj.to = threadData.recipients.map(
       msgObj.to = people.join(", ");
-      msgObj.references = references;
+      if (references.length)
+        msgObj.references = references.reverse();
         
       msgObj.id = sha1.b64_sha1(msgObj.body + msgObj.date) + 
         "@facescrape.invalid";
-      references.push(msgObj.id);
       
       msgObj.contentType = "text/html";
       msgObj.body = "<html>\n" + msg.message + "</html>\n";             
       
       req.send(jsonMsg);
       console.log("message sent\n");
+
+      // make sure the next message points to this as first in the 
+      // References line so threading is right
+      references.push(msgObj.id);
     }
     
     threadData.messages.forEach(handleMessage, this);