kopia lustrzana https://github.com/snarfed/bridgy-fed
Protocol.translate_ids: minor tweaks, bug fixes, comments
rodzic
4622188aa1
commit
9358bf2fd2
|
@ -813,6 +813,7 @@ class Object(StringIdModel):
|
||||||
else bool(self.as1) != bool(other_as1))
|
else bool(self.as1) != bool(other_as1))
|
||||||
|
|
||||||
def proxy_url(self):
|
def proxy_url(self):
|
||||||
|
# TODO: replace with ids.translate_object_id?
|
||||||
"""Returns the Bridgy Fed proxy URL to render this post as HTML.
|
"""Returns the Bridgy Fed proxy URL to render this post as HTML.
|
||||||
|
|
||||||
Note that some webmention receivers are struggling with the ``%23``\s
|
Note that some webmention receivers are struggling with the ``%23``\s
|
||||||
|
@ -903,7 +904,8 @@ class Object(StringIdModel):
|
||||||
* ``object.inReplyTo``
|
* ``object.inReplyTo``
|
||||||
* ``tags.[objectType=mention].url``
|
* ``tags.[objectType=mention].url``
|
||||||
|
|
||||||
Duplicates much of :func:`common.wrap`!
|
This is the inverse of :meth:`protocol.Protocol.translate_ids`. Much of the
|
||||||
|
same logic is duplicated there!
|
||||||
"""
|
"""
|
||||||
if not self.as1:
|
if not self.as1:
|
||||||
return
|
return
|
||||||
|
|
10
protocol.py
10
protocol.py
|
@ -484,7 +484,8 @@ class Protocol:
|
||||||
* ``object.inReplyTo``
|
* ``object.inReplyTo``
|
||||||
* ``tags.[objectType=mention].url``
|
* ``tags.[objectType=mention].url``
|
||||||
|
|
||||||
Duplicates much of :meth:`models.Object.resolve_ids`!
|
This is the inverse of :meth:`models.Object.resolve_ids`. Much of the
|
||||||
|
same logic is duplicated there!
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
to_proto (Protocol subclass)
|
to_proto (Protocol subclass)
|
||||||
|
@ -501,7 +502,9 @@ class Protocol:
|
||||||
id = elem[field].get('id')
|
id = elem[field].get('id')
|
||||||
if id and util.domain_from_link(id) not in DOMAINS:
|
if id and util.domain_from_link(id) not in DOMAINS:
|
||||||
from_cls = Protocol.for_id(id)
|
from_cls = Protocol.for_id(id)
|
||||||
if from_cls != to_cls:
|
# TODO: what if from_cls is None? relax translate_object_id,
|
||||||
|
# make it a noop if we don't know enough about from/to?
|
||||||
|
if from_cls and from_cls != to_cls:
|
||||||
elem[field]['id'] = translate_object_id(
|
elem[field]['id'] = translate_object_id(
|
||||||
id=id, from_proto=from_cls, to_proto=to_cls)
|
id=id, from_proto=from_cls, to_proto=to_cls)
|
||||||
if elem[field].keys() == {'id'}:
|
if elem[field].keys() == {'id'}:
|
||||||
|
@ -517,7 +520,7 @@ class Protocol:
|
||||||
translate(tag, 'url')
|
translate(tag, 'url')
|
||||||
|
|
||||||
outer_obj = util.trim_nulls(outer_obj)
|
outer_obj = util.trim_nulls(outer_obj)
|
||||||
if outer_obj['object'].keys() == {'id'}:
|
if outer_obj.get('object', {}).keys() == {'id'}:
|
||||||
outer_obj['object'] = inner_obj['id']
|
outer_obj['object'] = inner_obj['id']
|
||||||
|
|
||||||
return outer_obj
|
return outer_obj
|
||||||
|
@ -930,6 +933,7 @@ class Protocol:
|
||||||
target_uris = set(as1.targets(obj.as1))
|
target_uris = set(as1.targets(obj.as1))
|
||||||
logger.info(f'Raw targets: {target_uris}')
|
logger.info(f'Raw targets: {target_uris}')
|
||||||
|
|
||||||
|
# TODO: remove this? seems unnecessary now that receive calls resolve_ids?
|
||||||
if target_uris:
|
if target_uris:
|
||||||
origs = {key.id() for key in get_for_copies(target_uris, keys_only=True)}
|
origs = {key.id() for key in get_for_copies(target_uris, keys_only=True)}
|
||||||
if origs:
|
if origs:
|
||||||
|
|
Ładowanie…
Reference in New Issue