From 486932048cd0bbb89c483b9c82bee9b30d46af17 Mon Sep 17 00:00:00 2001
From: Scott Nonnenberg <scott@signal.org>
Date: Thu, 1 Nov 2018 12:43:05 -0700
Subject: [PATCH] Add logging to help in debugging sealedSender state

---
 js/models/conversations.js | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/js/models/conversations.js b/js/models/conversations.js
index 7c16b5dba..6dd8fe4c7 100644
--- a/js/models/conversations.js
+++ b/js/models/conversations.js
@@ -831,6 +831,9 @@
             conversation &&
             conversation.get('sealedSender') !== SEALED_SENDER.DISABLED
           ) {
+            window.log.info(
+              `Setting sealedSender to DISABLED for conversation ${conversation.idForLogging()}`
+            );
             conversation.set({
               sealedSender: SEALED_SENDER.DISABLED,
             });
@@ -852,10 +855,16 @@
             conversation.get('sealedSender') === SEALED_SENDER.UNKNOWN
           ) {
             if (conversation.get('accessKey')) {
+              window.log.info(
+                `Setting sealedSender to ENABLED for conversation ${conversation.idForLogging()}`
+              );
               conversation.set({
                 sealedSender: SEALED_SENDER.ENABLED,
               });
             } else {
+              window.log.info(
+                `Setting sealedSender to UNRESTRICTED for conversation ${conversation.idForLogging()}`
+              );
               conversation.set({
                 sealedSender: SEALED_SENDER.UNRESTRICTED,
               });
@@ -1306,6 +1315,9 @@
             });
           } catch (error) {
             if (error.code === 401 || error.code === 403) {
+              window.log.info(
+                `Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
+              );
               c.set({ sealedSender: SEALED_SENDER.DISABLED });
               profile = await textsecure.messaging.getProfile(id);
             } else {
@@ -1341,6 +1353,9 @@
           profile.unrestrictedUnidentifiedAccess &&
           profile.unidentifiedAccess
         ) {
+          window.log.info(
+            `Setting sealedSender to UNRESTRICTED for conversation ${c.idForLogging()}`
+          );
           c.set({
             sealedSender: SEALED_SENDER.UNRESTRICTED,
           });
@@ -1351,15 +1366,24 @@
           );
 
           if (haveCorrectKey) {
+            window.log.info(
+              `Setting sealedSender to ENABLED for conversation ${c.idForLogging()}`
+            );
             c.set({
               sealedSender: SEALED_SENDER.ENABLED,
             });
           } else {
+            window.log.info(
+              `Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
+            );
             c.set({
               sealedSender: SEALED_SENDER.DISABLED,
             });
           }
         } else {
+          window.log.info(
+            `Setting sealedSender to DISABLED for conversation ${c.idForLogging()}`
+          );
           c.set({
             sealedSender: SEALED_SENDER.DISABLED,
           });
@@ -1442,6 +1466,9 @@
     async setProfileKey(profileKey) {
       // profileKey is a string so we can compare it directly
       if (this.get('profileKey') !== profileKey) {
+        window.log.info(
+          `Setting sealedSender to UNKNOWN for conversation ${this.idForLogging()}`
+        );
         this.set({
           profileKey,
           accessKey: null,