mirror of
https://git.sr.ht/~tsileo/microblog.pub
synced 2024-12-22 21:24:28 +00:00
Drop more OStatus stuff
This commit is contained in:
parent
a165e36303
commit
deea5be452
4 changed files with 33 additions and 12 deletions
|
@ -16,8 +16,8 @@ from little_boxes import strtobool
|
|||
from little_boxes.activitypub import _to_list
|
||||
from little_boxes.backend import Backend
|
||||
from little_boxes.errors import ActivityGoneError
|
||||
from little_boxes.errors import NotAnActivityError
|
||||
from little_boxes.errors import Error
|
||||
from little_boxes.errors import NotAnActivityError
|
||||
|
||||
from config import BASE_URL
|
||||
from config import DB
|
||||
|
|
30
tasks.py
30
tasks.py
|
@ -6,9 +6,9 @@ import random
|
|||
import requests
|
||||
from celery import Celery
|
||||
from little_boxes import activitypub as ap
|
||||
from little_boxes.errors import NotAnActivityError
|
||||
from little_boxes.errors import ActivityGoneError
|
||||
from little_boxes.errors import ActivityNotFoundError
|
||||
from little_boxes.errors import NotAnActivityError
|
||||
from little_boxes.httpsig import HTTPSigAuth
|
||||
from little_boxes.linked_data_sig import generate_signature
|
||||
from requests.exceptions import HTTPError
|
||||
|
@ -44,10 +44,17 @@ def process_new_activity(self, iri: str) -> None:
|
|||
# Is the activity expected?
|
||||
# following = ap.get_backend().following()
|
||||
should_forward = False
|
||||
should_delete = False
|
||||
|
||||
tag_stream = False
|
||||
if activity.has_type(ap.ActivityType.ANNOUNCE):
|
||||
tag_stream = True
|
||||
try:
|
||||
activity.get_object()
|
||||
except NotAnActivityError:
|
||||
# Most likely on OStatus notice
|
||||
tag_stream = False
|
||||
should_delete = True
|
||||
|
||||
elif activity.has_type(ap.ActivityType.CREATE):
|
||||
note = activity.get_object()
|
||||
|
@ -56,13 +63,17 @@ def process_new_activity(self, iri: str) -> None:
|
|||
tag_stream = True
|
||||
|
||||
if note.inReplyTo:
|
||||
try:
|
||||
reply = ap.fetch_remote_activity(note.inReplyTo)
|
||||
if (
|
||||
reply.id.startswith(ID) or reply.has_mention(ID)
|
||||
) and activity.is_public():
|
||||
# The reply is public "local reply", forward the reply (i.e. the original activity) to the original
|
||||
# recipients
|
||||
# The reply is public "local reply", forward the reply (i.e. the original activity) to the
|
||||
# original recipients
|
||||
should_forward = True
|
||||
except NotAnActivityError:
|
||||
# Most likely a reply to an OStatus notce
|
||||
should_delete = True
|
||||
|
||||
# (partial) Ghost replies handling
|
||||
# [X] This is the first time the server has seen this Activity.
|
||||
|
@ -82,7 +93,7 @@ def process_new_activity(self, iri: str) -> None:
|
|||
note = DB.activities.find_one(
|
||||
{"activity.object.id": activity.get_object().id}
|
||||
)
|
||||
if note["meta"].get("forwarded", False):
|
||||
if note and note["meta"].get("forwarded", False):
|
||||
# If the activity was originally forwarded, forward the delete too
|
||||
should_forward = True
|
||||
|
||||
|
@ -90,10 +101,19 @@ def process_new_activity(self, iri: str) -> None:
|
|||
log.info(f"will forward {activity!r} to followers")
|
||||
activity.forward(back.followers_as_recipients())
|
||||
|
||||
if should_delete:
|
||||
log.info(f"will soft delete {activity!r}")
|
||||
|
||||
log.info(f"{iri} tag_stream={tag_stream}")
|
||||
DB.activities.update_one(
|
||||
{"remote_id": activity.id},
|
||||
{"$set": {"meta.stream": tag_stream, "meta.forwarded": should_forward}},
|
||||
{
|
||||
"$set": {
|
||||
"meta.stream": tag_stream,
|
||||
"meta.forwarded": should_forward,
|
||||
"meta.deleted": should_delete,
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
log.info(f"new activity {iri} processed")
|
||||
|
|
|
@ -3,8 +3,8 @@ import json
|
|||
import little_boxes.activitypub as ap
|
||||
import mf2py
|
||||
import requests
|
||||
from little_boxes.webfinger import get_actor_url
|
||||
from little_boxes.errors import NotAnActivityError
|
||||
from little_boxes.webfinger import get_actor_url
|
||||
|
||||
|
||||
def lookup(url: str) -> ap.BaseActivity:
|
||||
|
|
|
@ -5,6 +5,7 @@ from little_boxes import activitypub as ap
|
|||
from little_boxes.errors import NotAnActivityError
|
||||
from little_boxes.urlutils import check_url
|
||||
from little_boxes.urlutils import is_url_valid
|
||||
|
||||
from .lookup import lookup
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue