docs: def InitFromNotification(self, notification, is_pending=False):
      """Initializes this object from an existing notification.
  
      Args:
        notification: A rdfvalues.flows.Notification object.
        is_pending: Indicates whether the user has already seen this notification
          or not.
  
      Returns:
        The current instance.
      """
      self.timestamp = notification.timestamp
      self.message = notification.message
      self.subject = str(notification.subject)
      self.is_pending = is_pending
  
      reference_type_enum = ApiNotificationReference.Type
  
      # Please see the comments to aff4_objects.GRRUser.Notify implementation
      # for the details of notification.type format. Short summary:
      # notification.type may be one of legacy values (i.e. "ViewObject") or
      # have a format of "[legacy value]:[new-style notification type]", i.e.
      # "ViewObject:TYPE_CLIENT_INTERROGATED".
      legacy_type = None
      if ":" in notification.type:
        legacy_type, new_type = notification.type.split(":", 2)
        self.notification_type = new_type
      else:
        legacy_type = notification.type
  
      # TODO(user): refactor notifications, so that we send a meaningful
      # notification from the start, so that we don't have to do the
      # bridging/conversion/guessing here.
      components = self._GetUrnComponents(notification)
      if legacy_type == "Discovery":
        self.reference.type = reference_type_enum.CLIENT
        self.reference.client = ApiNotificationClientReference(
            client_id=components[0])
      elif legacy_type == "ViewObject":
        if len(components) >= 2 and components[0] == "hunts":
          self.reference.type = reference_type_enum.HUNT
          self.reference.hunt.hunt_id = components[1]
        elif len(components) >= 2 and components[0] == "cron":
          self.reference.type = reference_type_enum.CRON
          self.reference.cron.cron_job_id = components[1]
        elif len(components) >= 3 and components[1] == "flows":
          self.reference.type = reference_type_enum.FLOW
          self.reference.flow.flow_id = components[2]
          self.reference.flow.client_id = components[0]
        elif len(components) == 1 and rdf_client.ClientURN.Validate(
            components[0]):
          self.reference.type = reference_type_enum.CLIENT
          self.reference.client.client_id = components[0]
        else:
          if notification.subject:
            path = notification.subject.Path()
            for prefix in itervalues(rdf_paths.PathSpec.AFF4_PREFIXES):
              part = "/%s%s" % (components[0], prefix)
              if path.startswith(part):
                self.reference.type = reference_type_enum.VFS
                self.reference.vfs.client_id = components[0]
                self.reference.vfs.vfs_path = (prefix +
                                               path[len(part):]).lstrip("/")
                break
  
          if self.reference.type != reference_type_enum.VFS:
            self.reference.type = reference_type_enum.UNKNOWN
            self.reference.unknown.subject_urn = notification.subject
  
      elif legacy_type == "FlowStatus":
        if not components or not rdf_client.ClientURN.Validate(components[0]):
          self.reference.type = reference_type_enum.UNKNOWN
          self.reference.unknown.subject_urn = notification.subject
        else:
          self.reference.type = reference_type_enum.FLOW
          self.reference.flow.flow_id = notification.source.Basename()
          self.reference.flow.client_id = components[0]
  
      # TODO(user): refactor GrantAccess notification so that we don't have
      # to infer approval type from the URN.
      elif legacy_type == "GrantAccess":
        if rdf_client.ClientURN.Validate(components[1]):
          self.reference.type = reference_type_enum.CLIENT_APPROVAL
          self.reference.client_approval.client_id = components[1]
          self.reference.client_approval.approval_id = components[-1]
          self.reference.client_approval.username = components[-2]
        elif components[1] == "hunts":
          self.reference.type = reference_type_enum.HUNT_APPROVAL
          self.reference.hunt_approval.hunt_id = components[2]
          self.reference.hunt_approval.approval_id = components[-1]
          self.reference.hunt_approval.username = components[-2]
        elif components[1] == "cron":
          self.reference.type = reference_type_enum.CRON_JOB_APPROVAL
          self.reference.cron_job_approval.cron_job_id = components[2]
          self.reference.cron_job_approval.approval_id = components[-1]
          self.reference.cron_job_approval.username = components[-2]
  
      else:
        self.reference.type = reference_type_enum.UNKNOWN
        self.reference.unknown.subject_urn = notification.subject
        self.reference.unknown.source_urn = notification.source
  
      return self