@classmethod
  @gen.coroutine
  def QuerySince(cls, client, user_id, device_id, start_key, limit=None, scan_forward=True):
    """Queries all notifications intended for 'user_id' with max 'limit' notifications since
    'start_key'. Creates a special "clear_badges" notification once all notifications have been
    queried. This resets the current badge counter and results in the push of an alert to all
    *other* devices so that their badge number can be updated to 0. If 'scan_forward' is false,
    then query in reverse (descending order), and do not set clear_badges.
    """
    from viewfinder.backend.op.alert_manager import AlertManager

    # Use consistent read to ensure that no notifications are skipped.
    limit = NotificationManager._QUERY_LIMIT if limit is None else limit
    notifications = yield gen.Task(Notification.RangeQuery,
                                   client,
                                   hash_key=user_id,
                                   range_desc=None,
                                   limit=limit,
                                   col_names=None,
                                   excl_start_key=start_key,
                                   consistent_read=True,
                                   scan_forward=scan_forward)

    # If all notifications have been queried, get the last notification.
    if len(notifications) < limit and scan_forward:
      if len(notifications) == 0:
        last_notification = yield Notification.QueryLast(client, user_id, consistent_read=True)
      else:
        last_notification = notifications[-1]

      # If all notifications have been queried, add the special "clear_badges" notification.
      if last_notification is None or last_notification.badge == 0:
        raise gen.Return(notifications)

      # If TryClearBadge returns false, then new notifications showed up while the query was running, and so
      # retry creation of the notification. 
      notification_id = last_notification.notification_id + 1 if last_notification else 0
      success = yield Notification.TryClearBadge(client, user_id, device_id, notification_id)
      if not success:
        results = yield NotificationManager.QuerySince(client, user_id, device_id, start_key, scan_forward=scan_forward)
        raise gen.Return(results)

      # Push badge update to any other devices this user owns, but exclude the current device
      # because pushing badge=0 to it is redundant and annoying.
      AlertManager.SendClearBadgesAlert(client, user_id, exclude_device_id=device_id)

    raise gen.Return(notifications)
dataset/ETHPy150Open viewfinderco/viewfinder/backend/op/notification_manager.py/NotificationManager.QuerySince/original