Add support for the featured collection

This commit is contained in:
Thomas Sileo 2018-07-22 21:54:24 +02:00
parent d26d6ba70e
commit f23dbcaf05
3 changed files with 20 additions and 1 deletions

View file

@ -638,6 +638,16 @@ def embed_collection(total_items, first_page_id):
}
def simple_build_ordered_collection(col_name, data):
return {
"@context": ap.COLLECTION_CTX,
"id": BASE_URL + "/" + col_name,
"totalItems": len(data),
"type": ap.ActivityType.ORDERED_COLLECTION.value,
"orederedItems": data,
}
def build_ordered_collection(
col, q=None, cursor=None, map_func=None, limit=50, col_name=None, first_page=False
):
@ -652,6 +662,7 @@ def build_ordered_collection(
if not data:
return {
"@context": ap.COLLECTION_CTX,
"id": BASE_URL + "/" + col_name,
"totalItems": 0,
"type": ap.ActivityType.ORDERED_COLLECTION.value,

9
app.py
View file

@ -23,10 +23,10 @@ import timeago
from bson.objectid import ObjectId
from dateutil import parser
from flask import Flask
from flask import make_response
from flask import Response
from flask import abort
from flask import jsonify as flask_jsonify
from flask import make_response
from flask import redirect
from flask import render_template
from flask import request
@ -1779,6 +1779,13 @@ def tags(tag):
)
@app.route("/featured")
def featured():
if not is_api_request():
abort(404)
return jsonify(**activitypub.simple_build_ordered_collection("featured", []))
@app.route("/liked")
def liked():
if not is_api_request():

View file

@ -131,6 +131,7 @@ ME = {
"id": ID,
"following": ID + "/following",
"followers": ID + "/followers",
"featured": ID + "/featured",
"liked": ID + "/liked",
"inbox": ID + "/inbox",
"outbox": ID + "/outbox",