properly get actor and inbox urls

* get actor url from incoming message
* fall back to actor inbox if there is no shared inbox
This commit is contained in:
Izalia Mae 2025-02-11 12:28:05 -05:00
parent ff275a5ba4
commit 527afaca95
2 changed files with 30 additions and 10 deletions

View file

@ -68,7 +68,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
logging.verbose("Rejected banned actor: %s", data.actor.id)
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_response(
host = app.config.domain,
actor = data.actor.id,
@ -91,7 +91,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
logging.verbose("Non-application actor tried to follow: %s", data.actor.id)
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_response(
host = app.config.domain,
actor = data.actor.id,
@ -111,7 +111,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
with conn.transaction():
data.instance = conn.put_inbox(
domain = data.actor.domain,
inbox = data.actor.shared_inbox,
inbox = data.shared_inbox,
actor = data.actor.id,
followid = data.message.id,
software = software,
@ -125,7 +125,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
logging.verbose("Rejected actor for not being in the whitelist: %s", data.actor.id)
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_response(
host = app.config.domain,
actor = data.actor.id,
@ -140,7 +140,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
with conn.transaction():
data.instance = conn.put_inbox(
domain = data.actor.domain,
inbox = data.actor.shared_inbox,
inbox = data.shared_inbox,
actor = data.actor.id,
followid = data.message.id,
software = software,
@ -148,7 +148,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
)
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_response(
host = app.config.domain,
actor = data.actor.id,
@ -162,7 +162,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
# Ignoring only Mastodon for now
if software != "mastodon":
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_follow(
host = app.config.domain,
actor = data.actor.id
@ -193,7 +193,7 @@ async def handle_undo(app: Application, data: InboxData, conn: Connection) -> No
)
app.push_message(
data.actor.shared_inbox,
data.shared_inbox,
Message.new_unfollow(
host = app.config.domain,
actor = data.actor.id,

View file

@ -66,8 +66,16 @@ class InboxData:
logging.verbose("actor not in message")
raise HttpError(400, "no actor in message")
actor_id: str
try:
actor = await app.client.get(signature.keyid, True, Message)
actor_id = message.actor_id
except AttributeError:
actor_id = signature.keyid
try:
actor = await app.client.get(actor_id, True, Message)
except HttpError as e:
# ld signatures aren"t handled atm, so just ignore it
@ -104,6 +112,18 @@ class InboxData:
return cls(signature, message, actor, signer, None)
@property
def shared_inbox(self) -> str:
if self.actor is None:
raise AttributeError("Actor not set yet")
try:
return self.actor.shared_inbox
except KeyError:
return self.actor.inbox # type: ignore[no-any-return]
@register_route(HttpMethod.GET, "/actor", "/inbox")
async def handle_actor(app: Application, request: Request) -> Response:
with app.database.session(False) as conn:
@ -124,7 +144,7 @@ async def handle_inbox(app: Application, request: Request) -> Response:
data = await InboxData.parse(app, request)
with app.database.session() as conn:
data.instance = conn.get_inbox(data.actor.shared_inbox)
data.instance = conn.get_inbox(data.shared_inbox)
# reject if actor is banned
if conn.get_domain_ban(data.actor.domain):