async _setOrRemoveAssignment()

in src/js/background/assignManager.js [591:639]


  async _setOrRemoveAssignment(tabId, pageUrl, userContextId, remove) {
    let actionName;
    // https://github.com/mozilla/testpilot-containers/issues/626
    // Context menu has stored context IDs as strings, so we need to coerce
    // the value to a string for accurate checking
    userContextId = String(userContextId);

    if (!remove) {
      const tabs = await browser.tabs.query({});
      const assignmentStoreKey = this.storageArea.getSiteStoreKey(pageUrl);
      const exemptedTabIds = tabs.filter((tab) => {
        const tabStoreKey = this.storageArea.getSiteStoreKey(tab.url);
        /* Auto exempt all tabs that exist for this hostname that are not in the same container */
        if (tabStoreKey === assignmentStoreKey &&
            this.getUserContextIdFromCookieStore(tab) !== userContextId) {
          return true;
        }
        return false;
      }).map((tab) => {
        return tab.id;
      });

      await this.storageArea.set(pageUrl, {
        userContextId,
        neverAsk: false
      }, exemptedTabIds);
      actionName = "assigned site to always open in this container";
    } else {
      // Remove assignment
      await this.storageArea.remove(pageUrl);

      actionName = "removed from assigned sites list";

      // remove site isolation if now empty
      await this._maybeRemoveSiteIsolation(userContextId);
    }

    if (tabId) {
      const tab = await browser.tabs.get(tabId);
      setTimeout(function(){
        browser.tabs.sendMessage(tabId, {
          text: `Successfully ${actionName}`
        });
      }, 1000);


      this.calculateContextMenu(tab);
    }
  },