Add a new method to the backend

pull/9/head
Thomas Sileo 2018-06-23 01:14:05 +02:00
rodzic cf4aa1fe60
commit da9aab0124
3 zmienionych plików z 14 dodań i 5 usunięć

Wyświetl plik

@ -943,14 +943,17 @@ class Create(BaseActivity):
ACTOR_REQUIRED = True
def _outbox_set_id(self, uri: str, obj_id: str) -> None:
if BACKEND is None:
raise UninitializedBackendError
# FIXME(tsileo): add a BACKEND.note_activity_url, and pass the actor to both
self._data["object"]["id"] = uri + "/activity"
self._data["object"]["url"] = BACKEND.note_url(obj_id)
if isinstance(self.ctx(), Note):
try:
print("SETTING ID")
# FIXME(tsileo): use a weakref instead of ctx, and make it generic to every object (when
# building things (and drop the set_ctx usage)
# building things (and drop the set_ctx usage), and call _outbox_set_id on it?
self.ctx().id = self._data["object"]["id"]
print(f"CTX {self.ctx()}")
except NotImplementedError:
pass
# FIXME(tsileo): re-enable this

Wyświetl plik

@ -79,6 +79,10 @@ class Backend(abc.ABC):
def activity_url(self, obj_id: str) -> str:
pass # pragma: no cover
@abc.abstractmethod
def note_url(self, obj_id: str) -> str:
pass # pragma: no cover
@abc.abstractmethod
def outbox_create(self, as_actor: "ap.Person", activity: "ap.Create") -> None:
pass # pragma: no cover

Wyświetl plik

@ -1,6 +1,4 @@
import binascii
import json
import os
from typing import List
from typing import Optional
@ -145,6 +143,10 @@ class InMemBackend(Backend):
# from the random hex ID
return f"https://todo/{obj_id}"
def note_url(self, obj_id: str) -> str:
# from the random hex ID
return f"https://todo/note/{obj_id}"
@track_call
def outbox_new(self, as_actor: ap.Person, activity: ap.BaseActivity) -> None:
print(f"saving {activity!r} to DB")