diff --git a/activities/search.py b/activities/search.py index 5a43156..d1f6dc1 100644 --- a/activities/search.py +++ b/activities/search.py @@ -82,7 +82,7 @@ class Searcher: type = document.get("type", "unknown").lower() # Is it an identity? - if type == "person": + if type in Identity.ACTOR_TYPES: # Try and retrieve the profile by actor URI identity = Identity.by_actor_uri(document["id"], create=True) if identity and identity.state == IdentityStates.outdated: diff --git a/users/migrations/0006_identity_actor_type.py b/users/migrations/0006_identity_actor_type.py new file mode 100644 index 0000000..57fc058 --- /dev/null +++ b/users/migrations/0006_identity_actor_type.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.4 on 2022-12-20 06:47 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("users", "0005_report"), + ] + + operations = [ + migrations.AddField( + model_name="identity", + name="actor_type", + field=models.CharField(default="person", max_length=100), + ), + ] diff --git a/users/models/identity.py b/users/models/identity.py index 0105f75..cdacf34 100644 --- a/users/models/identity.py +++ b/users/models/identity.py @@ -66,6 +66,8 @@ class Identity(StatorModel): limited = 1 blocked = 2 + ACTOR_TYPES = ["person", "service", "application", "group", "organization"] + # The Actor URI is essentially also a PK - we keep the default numeric # one around as well for making nice URLs etc. actor_uri = models.CharField(max_length=500, unique=True) @@ -102,6 +104,7 @@ class Identity(StatorModel): image_uri = models.CharField(max_length=500, blank=True, null=True) followers_uri = models.CharField(max_length=500, blank=True, null=True) following_uri = models.CharField(max_length=500, blank=True, null=True) + actor_type = models.CharField(max_length=100, default="person") icon = models.ImageField( upload_to=partial(upload_namer, "profile_images"), blank=True, null=True @@ -317,7 +320,7 @@ class Identity(StatorModel): def to_ap(self): response = { "id": self.actor_uri, - "type": "Person", + "type": self.actor_type.title(), "inbox": self.actor_uri + "inbox/", "outbox": self.actor_uri + "outbox/", "preferredUsername": self.username, @@ -475,6 +478,7 @@ class Identity(StatorModel): self.outbox_uri = document.get("outbox") self.followers_uri = document.get("followers") self.following_uri = document.get("following") + self.actor_type = document["type"].lower() self.shared_inbox_uri = document.get("endpoints", {}).get("sharedInbox") self.summary = document.get("summary") self.username = document.get("preferredUsername") diff --git a/users/models/inbox_message.py b/users/models/inbox_message.py index dda8138..bc47728 100644 --- a/users/models/inbox_message.py +++ b/users/models/inbox_message.py @@ -44,6 +44,14 @@ class InboxMessageStates(StateGraph): await sync_to_async(Post.handle_update_ap)(instance.message) case "person": await sync_to_async(Identity.handle_update_ap)(instance.message) + case "service": + await sync_to_async(Identity.handle_update_ap)(instance.message) + case "group": + await sync_to_async(Identity.handle_update_ap)(instance.message) + case "organization": + await sync_to_async(Identity.handle_update_ap)(instance.message) + case "application": + await sync_to_async(Identity.handle_update_ap)(instance.message) case "question": pass # Drop for now case unknown: