More progess on webmention replies
This commit is contained in:
parent
066f5ec900
commit
9ee3f3b971
6 changed files with 75 additions and 17 deletions
|
@ -9,8 +9,8 @@ from app import media
|
|||
from app.models import InboxObject
|
||||
from app.models import Webmention
|
||||
from app.models import WebmentionType
|
||||
from app.utils.url import make_abs
|
||||
from app.utils.datetime import parse_isoformat
|
||||
from app.utils.url import make_abs
|
||||
|
||||
|
||||
@dataclass
|
||||
|
@ -40,7 +40,9 @@ class Face:
|
|||
return cls(
|
||||
ap_actor_id=None,
|
||||
url=(
|
||||
item["properties"]["url"][0] if item["properties"].get("url") else webmention.source
|
||||
item["properties"]["url"][0]
|
||||
if item["properties"].get("url")
|
||||
else webmention.source
|
||||
),
|
||||
name=item["properties"]["name"][0],
|
||||
picture_url=media.resized_media_url(
|
||||
|
@ -95,7 +97,9 @@ def _parse_face(webmention: Webmention, items: list[dict[str, Any]]) -> Face | N
|
|||
return Face(
|
||||
ap_actor_id=None,
|
||||
url=(
|
||||
items["properties"]["url"][0] if item["properties"].get("url") else webmention.source
|
||||
item["properties"]["url"][0]
|
||||
if item["properties"].get("url")
|
||||
else webmention.source
|
||||
),
|
||||
name=item["properties"]["name"][0],
|
||||
picture_url=media.resized_media_url(
|
||||
|
@ -112,6 +116,8 @@ def _parse_face(webmention: Webmention, items: list[dict[str, Any]]) -> Face | N
|
|||
)
|
||||
break
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@dataclass
|
||||
class WebmentionReply:
|
||||
|
@ -119,9 +125,10 @@ class WebmentionReply:
|
|||
content: str
|
||||
url: str
|
||||
published_at: datetime.datetime
|
||||
in_reply_to: str
|
||||
|
||||
@classmethod
|
||||
def from_webmention(cls, webmention: Webmention) -> "WebmentionReply":
|
||||
def from_webmention(cls, webmention: Webmention) -> Optional["WebmentionReply"]:
|
||||
if webmention.webmention_type != WebmentionType.REPLY:
|
||||
raise ValueError(f"Unexpected webmention {webmention.id}")
|
||||
|
||||
|
@ -143,9 +150,12 @@ class WebmentionReply:
|
|||
published_at=parse_isoformat(
|
||||
item["properties"]["published"][0]
|
||||
).replace(tzinfo=None),
|
||||
in_reply_to=webmention.target, # type: ignore
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
f"Failed to build Face for webmention id={webmention.id}"
|
||||
)
|
||||
break
|
||||
|
||||
return None
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue