diff --git a/app/boxes.py b/app/boxes.py index 9f4c8d2..e339301 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -786,7 +786,7 @@ async def send_vote( raise ValueError("Object has no context") context = in_reply_to_object.ap_context - # TODO: ensure the name are valid? + # ensure the name are valid # Save the answers in_reply_to_object.voted_for_answers = names @@ -819,7 +819,9 @@ async def send_vote( for rcp in recipients: await new_outgoing_activity(db_session, rcp, outbox_object.id) + # commit db session await db_session.commit() + return vote_id @@ -871,6 +873,19 @@ async def send_update( outbox_object.source = source outbox_object.revisions = revisions + if outbox_object.tags != tags: + # remove all the existing tags + for tag in outbox_object.tags or []: + db_session.delete(tag) + + for tag in tags: + if tag["type"] == "Hashtag": + tagged_object = models.TaggedOutboxObject( + tag=tag["name"][1:].lower(), + outbox_object_id=outbox_object.id, + ) + db_session.add(tagged_object) + recipients = await _compute_recipients(db_session, note) for rcp in recipients: await new_outgoing_activity(db_session, rcp, outbox_object.id) diff --git a/app/micropub.py b/app/micropub.py index 6910b2f..fe161b2 100644 --- a/app/micropub.py +++ b/app/micropub.py @@ -11,6 +11,7 @@ from app.boxes import get_outbox_object_by_ap_id from app.boxes import send_create from app.boxes import send_delete +from app.boxes import send_update from app.database import AsyncSession from app.database import get_db_session from app.indieauth import AccessTokenInfo @@ -83,6 +84,7 @@ async def post_micropub_endpoint( if "action" in form_data: if form_data["action"] in ["delete", "update"]: + url = form_data["url"] outbox_object = await get_outbox_object_by_ap_id( db_session, str(form_data["url"]) ) @@ -106,11 +108,20 @@ async def post_micropub_endpoint( if "update" not in access_token_info.scopes: return insufficient_scope_resp - # TODO(ts): support update - # "replace": {"content": ["new content"]} - - logger.info(f"Updating object {outbox_object.ap_id}: {form_data}") - return JSONResponse(content={}, status_code=200) + # TODO(1d): support update properly. Currently only supposed "replace":{"content":} + + if "replace" in form_data: + logger.info(f"Updating object {outbox_object.ap_id}: {form_data}") + await send_update(db_session,outbox_object.ap_id,form_data["replace"]["content"]) + return JSONResponse(content={}, status_code=200) + else: + return JSONResponse( + content={ + "error": "invalid_request", + "error_description": "Update only supports replace.content.", + }, + status_code=400, + ) else: raise ValueError("Should never happen") else: