def block(request, feed, item):    
    next = db.query(ContentItem).filter(ContentItem.type.in_(get_content_feeds()[feed]["types"]), ContentItem.permissions_for(request.user), ContentItem.created_at > item["created_at"]).order_by(ContentItem.created_at).first()
    prev = db.query(ContentItem).filter(ContentItem.type.in_(get_content_feeds()[feed]["types"]), ContentItem.permissions_for(request.user), ContentItem.created_at < item["created_at"]).order_by(ContentItem.created_at.desc()).first()
    if next or prev:
        return {
            "next"  : process_content_item(next) if next else None,
            "prev"  : process_content_item(prev) if prev else None,
        }
    else:
        return None
def block(request, limit=10):
    return {
        "last_comments" : [
            {
                "comment"       : db.query(Comment).options(joinedload("content_item")).filter(Comment.content_item_id == content_item_id).order_by(Comment.created_at.desc()).first(),
                "content_item"  : process_content_item(db.query(ContentItem).get(content_item_id)),

                "count_new"     : db.query(func.count(Comment)).filter(Comment.content_item_id == content_item_id, Comment.created_at > request.user.last_visit).scalar() if request.user else 0,
                "new_index"     : (db.query(func.count(Comment)).filter(Comment.content_item_id == content_item_id, Comment.created_at <= request.user.last_visit).scalar() if request.user else 0) + 1,
            }
            for content_item_id, in db.query(Comment.content_item_id).group_by(Comment.content_item_id).order_by(-func.max(Comment.created_at))[:limit]
        ],
    }