Tweak webmention processing

This commit is contained in:
Thomas Sileo 2022-11-20 11:31:00 +01:00
parent 4c6eb51ae2
commit d692ec060f
2 changed files with 24 additions and 15 deletions

View file

@ -19,6 +19,8 @@ from app.boxes import get_outbox_object_by_slug_and_short_id
from app.database import AsyncSession
from app.database import get_db_session
from app.utils import microformats
from app.utils.facepile import Face
from app.utils.facepile import WebmentionReply
from app.utils.url import check_url
from app.utils.url import is_url_valid
@ -133,17 +135,6 @@ async def webmention_endpoint(
return JSONResponse(content={}, status_code=200)
webmention_type = models.WebmentionType.UNKNOWN
for item in data.get("items", []):
if target in item.get("properties", {}).get("in-reply-to", []):
webmention_type = models.WebmentionType.REPLY
break
elif target in item.get("properties", {}).get("like-of", []):
webmention_type = models.WebmentionType.LIKE
break
elif target in item.get("properties", {}).get("repost-of", []):
webmention_type = models.WebmentionType.REPOST
break
webmention: models.Webmention
if existing_webmention_in_db:
# Undelete if needed
@ -177,6 +168,28 @@ async def webmention_endpoint(
)
db_session.add(notif)
# Determine the webmention type
for item in data.get("items", []):
if target in item.get("properties", {}).get(
"in-reply-to", []
) and WebmentionReply.from_webmention(webmention):
webmention_type = models.WebmentionType.REPLY
break
elif target in item.get("properties", {}).get(
"like-of", []
) and Face.from_webmention(webmention):
webmention_type = models.WebmentionType.LIKE
break
elif target in item.get("properties", {}).get(
"repost-of", []
) and Face.from_webmention(webmention):
webmention_type = models.WebmentionType.REPOST
break
if webmention_type != models.WebmentionType.UNKNOWN:
webmention.webmention_type = webmention_type
await db_session.flush()
# Handle side effect
await _handle_webmention_side_effects(db_session, webmention, mentioned_object)
await db_session.commit()