mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2025-03-04 00:33:58 +00:00
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:
parent
ff275a5ba4
commit
527afaca95
2 changed files with 30 additions and 10 deletions
|
@ -68,7 +68,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
|
||||||
logging.verbose("Rejected banned actor: %s", data.actor.id)
|
logging.verbose("Rejected banned actor: %s", data.actor.id)
|
||||||
|
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_response(
|
Message.new_response(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id,
|
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)
|
logging.verbose("Non-application actor tried to follow: %s", data.actor.id)
|
||||||
|
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_response(
|
Message.new_response(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
|
@ -111,7 +111,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
|
||||||
with conn.transaction():
|
with conn.transaction():
|
||||||
data.instance = conn.put_inbox(
|
data.instance = conn.put_inbox(
|
||||||
domain = data.actor.domain,
|
domain = data.actor.domain,
|
||||||
inbox = data.actor.shared_inbox,
|
inbox = data.shared_inbox,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
followid = data.message.id,
|
followid = data.message.id,
|
||||||
software = software,
|
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)
|
logging.verbose("Rejected actor for not being in the whitelist: %s", data.actor.id)
|
||||||
|
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_response(
|
Message.new_response(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
|
@ -140,7 +140,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
|
||||||
with conn.transaction():
|
with conn.transaction():
|
||||||
data.instance = conn.put_inbox(
|
data.instance = conn.put_inbox(
|
||||||
domain = data.actor.domain,
|
domain = data.actor.domain,
|
||||||
inbox = data.actor.shared_inbox,
|
inbox = data.shared_inbox,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
followid = data.message.id,
|
followid = data.message.id,
|
||||||
software = software,
|
software = software,
|
||||||
|
@ -148,7 +148,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
|
||||||
)
|
)
|
||||||
|
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_response(
|
Message.new_response(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
|
@ -162,7 +162,7 @@ async def handle_follow(app: Application, data: InboxData, conn: Connection) ->
|
||||||
# Ignoring only Mastodon for now
|
# Ignoring only Mastodon for now
|
||||||
if software != "mastodon":
|
if software != "mastodon":
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_follow(
|
Message.new_follow(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id
|
actor = data.actor.id
|
||||||
|
@ -193,7 +193,7 @@ async def handle_undo(app: Application, data: InboxData, conn: Connection) -> No
|
||||||
)
|
)
|
||||||
|
|
||||||
app.push_message(
|
app.push_message(
|
||||||
data.actor.shared_inbox,
|
data.shared_inbox,
|
||||||
Message.new_unfollow(
|
Message.new_unfollow(
|
||||||
host = app.config.domain,
|
host = app.config.domain,
|
||||||
actor = data.actor.id,
|
actor = data.actor.id,
|
||||||
|
|
|
@ -66,8 +66,16 @@ class InboxData:
|
||||||
logging.verbose("actor not in message")
|
logging.verbose("actor not in message")
|
||||||
raise HttpError(400, "no actor in message")
|
raise HttpError(400, "no actor in message")
|
||||||
|
|
||||||
|
actor_id: str
|
||||||
|
|
||||||
try:
|
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:
|
except HttpError as e:
|
||||||
# ld signatures aren"t handled atm, so just ignore it
|
# ld signatures aren"t handled atm, so just ignore it
|
||||||
|
@ -104,6 +112,18 @@ class InboxData:
|
||||||
return cls(signature, message, actor, signer, None)
|
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")
|
@register_route(HttpMethod.GET, "/actor", "/inbox")
|
||||||
async def handle_actor(app: Application, request: Request) -> Response:
|
async def handle_actor(app: Application, request: Request) -> Response:
|
||||||
with app.database.session(False) as conn:
|
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)
|
data = await InboxData.parse(app, request)
|
||||||
|
|
||||||
with app.database.session() as conn:
|
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
|
# reject if actor is banned
|
||||||
if conn.get_domain_ban(data.actor.domain):
|
if conn.get_domain_ban(data.actor.domain):
|
||||||
|
|
Loading…
Reference in a new issue