forked from forks/microblog.pub
Tweak replies management, improve tombstone support
This commit is contained in:
parent
31300e20d7
commit
786816f0a2
2 changed files with 27 additions and 7 deletions
|
@ -866,20 +866,20 @@ class Create(BaseActivity):
|
|||
'meta.count_reply': 1,
|
||||
'meta.count_direct_reply': direct_reply,
|
||||
},
|
||||
'$addToSet': {'meta.thread_children': obj.id},
|
||||
}):
|
||||
DB.outbox.update_one({'activity.object.id': reply.id}, {
|
||||
'$inc': {
|
||||
'meta.count_reply': 1,
|
||||
'meta.count_direct_reply': direct_reply,
|
||||
},
|
||||
'$addToSet': {'meta.thread_children': obj.id},
|
||||
})
|
||||
|
||||
direct_reply = 0
|
||||
reply_id = reply.id
|
||||
reply = reply.get_local_reply()
|
||||
logger.debug(f'next_reply={reply}')
|
||||
if reply:
|
||||
# Only append to threads if it's not the root
|
||||
threads.append(reply_id)
|
||||
|
||||
if reply_id:
|
||||
|
@ -1018,6 +1018,15 @@ class Note(BaseActivity):
|
|||
return Delete(object=Tombstone(id=self.id).to_dict(embed=True))
|
||||
|
||||
|
||||
def get_tombstone(self, deleted: Optional[str]) -> BaseActivity:
|
||||
return Tombstone(
|
||||
id=self.id,
|
||||
published=self.published,
|
||||
deleted=deleted,
|
||||
updated=updated,
|
||||
)
|
||||
|
||||
|
||||
_ACTIVITY_TYPE_TO_CLS = {
|
||||
ActivityType.IMAGE: Image,
|
||||
ActivityType.PERSON: Person,
|
||||
|
|
19
app.py
19
app.py
|
@ -409,9 +409,11 @@ def index():
|
|||
|
||||
@app.route('/note/<note_id>')
|
||||
def note_by_id(note_id):
|
||||
data = DB.outbox.find_one({'id': note_id, 'meta.deleted': False})
|
||||
data = DB.outbox.find_one({'id': note_id})
|
||||
if not data:
|
||||
return Response(status=404)
|
||||
abort(404)
|
||||
if data['meta'].get('deleted', False):
|
||||
abort(410)
|
||||
|
||||
replies = list(DB.inbox.find({
|
||||
'type': 'Create',
|
||||
|
@ -570,12 +572,18 @@ def outbox():
|
|||
|
||||
@app.route('/outbox/<item_id>')
|
||||
def outbox_detail(item_id):
|
||||
doc = DB.outbox.find_one({'id': item_id, 'meta.deleted': False})
|
||||
doc = DB.outbox.find_one({'id': item_id})
|
||||
if doc['meta'].get('deleted', False):
|
||||
obj = activitypub.parse_activity(doc['activity'])
|
||||
resp = jsonify(**obj.get_object().get_tombstone())
|
||||
resp.status_code = 410
|
||||
return resp
|
||||
return jsonify(**activity_from_doc(doc))
|
||||
|
||||
|
||||
@app.route('/outbox/<item_id>/activity')
|
||||
def outbox_activity(item_id):
|
||||
# TODO(tsileo): handle Tombstone
|
||||
data = DB.outbox.find_one({'id': item_id, 'meta.deleted': False})
|
||||
if not data:
|
||||
abort(404)
|
||||
|
@ -587,6 +595,7 @@ def outbox_activity(item_id):
|
|||
|
||||
@app.route('/outbox/<item_id>/replies')
|
||||
def outbox_activity_replies(item_id):
|
||||
# TODO(tsileo): handle Tombstone
|
||||
if not is_api_request():
|
||||
abort(404)
|
||||
data = DB.outbox.find_one({'id': item_id, 'meta.deleted': False})
|
||||
|
@ -614,6 +623,7 @@ def outbox_activity_replies(item_id):
|
|||
|
||||
@app.route('/outbox/<item_id>/likes')
|
||||
def outbox_activity_likes(item_id):
|
||||
# TODO(tsileo): handle Tombstone
|
||||
if not is_api_request():
|
||||
abort(404)
|
||||
data = DB.outbox.find_one({'id': item_id, 'meta.deleted': False})
|
||||
|
@ -642,6 +652,7 @@ def outbox_activity_likes(item_id):
|
|||
|
||||
@app.route('/outbox/<item_id>/shares')
|
||||
def outbox_activity_shares(item_id):
|
||||
# TODO(tsileo): handle Tombstone
|
||||
if not is_api_request():
|
||||
abort(404)
|
||||
data = DB.outbox.find_one({'id': item_id, 'meta.deleted': False})
|
||||
|
@ -755,7 +766,7 @@ def api_user_key():
|
|||
return flask_jsonify(api_key=ADMIN_API_KEY)
|
||||
|
||||
|
||||
def _user_api_arg(key: str, **kwargs: Dict[str, Any]) -> str:
|
||||
def _user_api_arg(key: str, **kwargs):
|
||||
"""Try to get the given key from the requests, try JSON body, form data and query arg."""
|
||||
if request.is_json:
|
||||
oid = request.json.get(key)
|
||||
|
|
Loading…
Reference in a new issue