private ViewCache ackUserWrite()

in src/main/java/com/google/firebase/database/core/view/ViewProcessor.java [541:610]


  private ViewCache ackUserWrite(
      ViewCache viewCache,
      Path ackPath,
      ImmutableTree<Boolean> affectedTree,
      WriteTreeRef writesCache,
      Node optCompleteCache,
      ChildChangeAccumulator accumulator) {
    if (writesCache.shadowingWrite(ackPath) != null) {
      return viewCache;
    }

    // Only filter server node if it is currently filtered
    boolean filterServerNode = viewCache.getServerCache().isFiltered();

    // Essentially we'll just get our existing server cache for the affected paths and
    // re-apply it
    // as a server update now that it won't be shadowed.
    CacheNode serverCache = viewCache.getServerCache();
    if (affectedTree.getValue() != null) {
      // This is an overwrite.
      if ((ackPath.isEmpty() && serverCache.isFullyInitialized())
          || serverCache.isCompleteForPath(ackPath)) {
        return applyServerOverwrite(
            viewCache,
            ackPath,
            serverCache.getNode().getChild(ackPath),
            writesCache,
            optCompleteCache,
            filterServerNode,
            accumulator);
      } else if (ackPath.isEmpty()) {
        // This is a goofy edge case where we are acking data at this location but don't
        // have full
        // data. We should just re-apply whatever we have in our cache as a merge.
        CompoundWrite changedChildren = CompoundWrite.emptyWrite();
        for (NamedNode child : serverCache.getNode()) {
          changedChildren = changedChildren.addWrite(child.getName(), child.getNode());
        }
        return applyServerMerge(
            viewCache,
            ackPath,
            changedChildren,
            writesCache,
            optCompleteCache,
            filterServerNode,
            accumulator);
      } else {
        return viewCache;
      }
    } else {
      // This is a merge.
      CompoundWrite changedChildren = CompoundWrite.emptyWrite();
      for (Map.Entry<Path, Boolean> entry : affectedTree) {
        Path mergePath = entry.getKey();
        Path serverCachePath = ackPath.child(mergePath);
        if (serverCache.isCompleteForPath(serverCachePath)) {
          changedChildren =
              changedChildren.addWrite(mergePath, serverCache.getNode().getChild(serverCachePath));
        }
      }
      return applyServerMerge(
          viewCache,
          ackPath,
          changedChildren,
          writesCache,
          optCompleteCache,
          filterServerNode,
          accumulator);
    }
  }