summaryrefslogtreecommitdiffstats
path: root/activities
diff options
context:
space:
mode:
authorAndrew Godwin2022-11-16 22:23:32 -0700
committerAndrew Godwin2022-11-16 22:23:32 -0700
commitb13c239213147b7acae4060aff35640d625b5169 (patch)
tree16c76dc20b3cc28403371c4b7817f636e22b13c1 /activities
parent5b34ea46c3f458a174c5443714ade43c21defdac (diff)
downloadtakahe-b13c239213147b7acae4060aff35640d625b5169.tar.gz
takahe-b13c239213147b7acae4060aff35640d625b5169.tar.bz2
takahe-b13c239213147b7acae4060aff35640d625b5169.zip
Handle post edits, follow undos
Diffstat (limited to 'activities')
-rw-r--r--activities/migrations/0007_post_edited.py18
-rw-r--r--activities/models/post.py22
2 files changed, 38 insertions, 2 deletions
diff --git a/activities/migrations/0007_post_edited.py b/activities/migrations/0007_post_edited.py
new file mode 100644
index 0000000..d4a661f
--- /dev/null
+++ b/activities/migrations/0007_post_edited.py
@@ -0,0 +1,18 @@
+# Generated by Django 4.1.3 on 2022-11-17 04:50
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("activities", "0006_alter_post_hashtags"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="post",
+ name="edited",
+ field=models.DateTimeField(blank=True, null=True),
+ ),
+ ]
diff --git a/activities/models/post.py b/activities/models/post.py
index 3847b63..473755b 100644
--- a/activities/models/post.py
+++ b/activities/models/post.py
@@ -28,7 +28,7 @@ class PostStates(StateGraph):
post = await instance.afetch_full()
# Non-local posts should not be here
if not post.local:
- raise ValueError("Trying to run handle_new on a non-local post!")
+ raise ValueError(f"Trying to run handle_new on a non-local post {post.pk}!")
# Build list of targets - mentions always included
targets = set()
async for mention in post.mentions.all():
@@ -122,6 +122,9 @@ class Post(StatorModel):
# When the post was originally created (as opposed to when we received it)
published = models.DateTimeField(default=timezone.now)
+ # If the post has been edited after initial publication
+ edited = models.DateTimeField(blank=True, null=True)
+
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
@@ -245,7 +248,7 @@ class Post(StatorModel):
post.sensitive = data.get("as:sensitive", False)
post.url = data.get("url", None)
post.published = parse_ld_date(data.get("published", None))
- # TODO: to
+ post.edited = parse_ld_date(data.get("updated", None))
# Mentions and hashtags
post.hashtags = []
for tag in get_list(data, "tag"):
@@ -254,6 +257,9 @@ class Post(StatorModel):
post.mentions.add(mention_identity)
elif tag["type"].lower() == "as:hashtag":
post.hashtags.append(tag["name"].lstrip("#"))
+ elif tag["type"].lower() == "http://joinmastodon.org/ns#emoji":
+ # TODO: Handle incoming emoji
+ pass
else:
raise ValueError(f"Unknown tag type {tag['type']}")
# Visibility and to
@@ -313,6 +319,18 @@ class Post(StatorModel):
post.transition_perform(PostStates.fanned_out)
@classmethod
+ def handle_update_ap(cls, data):
+ """
+ Handles an incoming update request
+ """
+ with transaction.atomic():
+ # Ensure the Create actor is the Post's attributedTo
+ if data["actor"] != data["object"]["attributedTo"]:
+ raise ValueError("Create actor does not match its Post object", data)
+ # Find it and update it
+ cls.by_ap(data["object"], create=False, update=True)
+
+ @classmethod
def handle_delete_ap(cls, data):
"""
Handles an incoming create request