Allow other Actor types

This commit is contained in:
Andrew Godwin 2022-12-20 06:52:33 +00:00
parent ee669ff568
commit 6eaaa6eac4
4 changed files with 32 additions and 2 deletions

View file

@ -82,7 +82,7 @@ class Searcher:
type = document.get("type", "unknown").lower() type = document.get("type", "unknown").lower()
# Is it an identity? # Is it an identity?
if type == "person": if type in Identity.ACTOR_TYPES:
# Try and retrieve the profile by actor URI # Try and retrieve the profile by actor URI
identity = Identity.by_actor_uri(document["id"], create=True) identity = Identity.by_actor_uri(document["id"], create=True)
if identity and identity.state == IdentityStates.outdated: if identity and identity.state == IdentityStates.outdated:

View file

@ -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),
),
]

View file

@ -66,6 +66,8 @@ class Identity(StatorModel):
limited = 1 limited = 1
blocked = 2 blocked = 2
ACTOR_TYPES = ["person", "service", "application", "group", "organization"]
# The Actor URI is essentially also a PK - we keep the default numeric # The Actor URI is essentially also a PK - we keep the default numeric
# one around as well for making nice URLs etc. # one around as well for making nice URLs etc.
actor_uri = models.CharField(max_length=500, unique=True) 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) image_uri = models.CharField(max_length=500, blank=True, null=True)
followers_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) following_uri = models.CharField(max_length=500, blank=True, null=True)
actor_type = models.CharField(max_length=100, default="person")
icon = models.ImageField( icon = models.ImageField(
upload_to=partial(upload_namer, "profile_images"), blank=True, null=True upload_to=partial(upload_namer, "profile_images"), blank=True, null=True
@ -317,7 +320,7 @@ class Identity(StatorModel):
def to_ap(self): def to_ap(self):
response = { response = {
"id": self.actor_uri, "id": self.actor_uri,
"type": "Person", "type": self.actor_type.title(),
"inbox": self.actor_uri + "inbox/", "inbox": self.actor_uri + "inbox/",
"outbox": self.actor_uri + "outbox/", "outbox": self.actor_uri + "outbox/",
"preferredUsername": self.username, "preferredUsername": self.username,
@ -475,6 +478,7 @@ class Identity(StatorModel):
self.outbox_uri = document.get("outbox") self.outbox_uri = document.get("outbox")
self.followers_uri = document.get("followers") self.followers_uri = document.get("followers")
self.following_uri = document.get("following") self.following_uri = document.get("following")
self.actor_type = document["type"].lower()
self.shared_inbox_uri = document.get("endpoints", {}).get("sharedInbox") self.shared_inbox_uri = document.get("endpoints", {}).get("sharedInbox")
self.summary = document.get("summary") self.summary = document.get("summary")
self.username = document.get("preferredUsername") self.username = document.get("preferredUsername")

View file

@ -44,6 +44,14 @@ class InboxMessageStates(StateGraph):
await sync_to_async(Post.handle_update_ap)(instance.message) await sync_to_async(Post.handle_update_ap)(instance.message)
case "person": case "person":
await sync_to_async(Identity.handle_update_ap)(instance.message) 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": case "question":
pass # Drop for now pass # Drop for now
case unknown: case unknown: