@classmethod
  def QueryByUser(cls, client, callback, user_id, include_expired=False,
                  include_history=False):
    history_results = []
    latest = {}
    def _VisitSub(sub, callback):
      if include_history:
        history_results.append(sub)
      else:
        if sub.expiration_ts < time.time() and not include_expired:
          callback()
          return
        # Only one transaction per subscription.
        if (sub.subscription_id in latest and
            latest[sub.subscription_id].timestamp > sub.timestamp):
          callback()
          return
        latest[sub.subscription_id] = sub
      callback()

    def _OnVisitDone():
      if include_history:
        assert not latest
        callback(history_results)
      else:
        assert not history_results
        callback(latest.values())

    Subscription.VisitRange(client, user_id, None, None, _VisitSub, _OnVisitDone)
Return list of one element if ``l`` is a scalar.
dataset/ETHPy150Open viewfinderco/viewfinder/backend/db/subscription.py/Subscription.QueryByUser--crossover with--dataset/ETHPy150Open celery/kombu/kombu/utils/functional.py/maybe_list