'Fetches the user notifications.'

def Handle(self, args, token=None):

    user_record = aff4.FACTORY.Open(aff4.ROOT_URN.Add('users').Add(token.username), aff4_type=aff4_users.GRRUser, mode='rw', token=token)
    result = []
    pending_notifications = user_record.Get(user_record.Schema.PENDING_NOTIFICATIONS)
    notifications = list(user_record.ShowNotifications(reset=True))
    notifications = sorted(notifications, key=(lambda x: x.timestamp), reverse=True)
    total_count = len(notifications)
    if args.filter:
        notifications = [n for n in notifications if (args.filter.lower() in n.message.lower())]
    if (not args.count):
        args.count = 50
    start = args.offset
    end = (args.offset + args.count)
    for notification in notifications[start:end]:
        item = ApiNotification().InitFromNotification(notification, is_pending=(notification in pending_notifications))
        result.append(item)
    return ApiListAndResetUserNotificationsResult(items=result, total_count=total_count)
