summaryrefslogtreecommitdiffstats
path: root/users/models
diff options
context:
space:
mode:
Diffstat (limited to 'users/models')
-rw-r--r--users/models/identity.py33
-rw-r--r--users/models/inbox_message.py8
2 files changed, 40 insertions, 1 deletions
diff --git a/users/models/identity.py b/users/models/identity.py
index 96e09c8..15caef4 100644
--- a/users/models/identity.py
+++ b/users/models/identity.py
@@ -102,8 +102,8 @@ class Identity(StatorModel):
unique_together = [("username", "domain")]
class urls(urlman.Urls):
+ view_nice = "{self._nice_view_url}"
view = "/@{self.username}@{self.domain_id}/"
- view_short = "/@{self.username}/"
action = "{view}action/"
activate = "{view}activate/"
@@ -118,6 +118,15 @@ class Identity(StatorModel):
return self.handle
return self.actor_uri
+ def _nice_view_url(self):
+ """
+ Returns the "nice" user URL if they're local, otherwise our general one
+ """
+ if self.local:
+ return f"https://{self.domain.uri_domain}/@{self.username}/"
+ else:
+ return f"/@{self.username}@{self.domain_id}/"
+
### Alternate constructors/fetchers ###
@classmethod
@@ -182,6 +191,28 @@ class Identity(StatorModel):
# TODO: Setting
return self.data_age > 60 * 24 * 24
+ ### ActivityPub (boutbound) ###
+
+ def to_ap(self):
+ response = {
+ "id": self.actor_uri,
+ "type": "Person",
+ "inbox": self.actor_uri + "inbox/",
+ "preferredUsername": self.username,
+ "publicKey": {
+ "id": self.public_key_id,
+ "owner": self.actor_uri,
+ "publicKeyPem": self.public_key,
+ },
+ "published": self.created.strftime("%Y-%m-%dT%H:%M:%SZ"),
+ "url": self.urls.view_nice,
+ }
+ if self.name:
+ response["name"] = self.name
+ if self.summary:
+ response["summary"] = self.summary
+ return response
+
### Actor/Webfinger fetching ###
@classmethod
diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py
index 6dbf5e8..b9bcfb4 100644
--- a/users/models/inbox_message.py
+++ b/users/models/inbox_message.py
@@ -46,6 +46,14 @@ class InboxMessageStates(StateGraph):
raise ValueError(
f"Cannot handle activity of type undo.{unknown}"
)
+ case "delete":
+ match instance.message_object_type:
+ case "tombstone":
+ await sync_to_async(Post.handle_delete_ap)(instance.message)
+ case unknown:
+ raise ValueError(
+ f"Cannot handle activity of type delete.{unknown}"
+ )
case unknown:
raise ValueError(f"Cannot handle activity of type {unknown}")
return cls.processed