Esempio n. 1
0
def activitypubpost_tags():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="# raw_content\n#foobar\n#barfoo",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
        )
Esempio n. 2
0
def activitypubpost_diaspora_guid():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="raw_content",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
            guid="totallyrandomguid",
        )
Esempio n. 3
0
def activitypubpost():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="# raw_content",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
            _media_type="text/markdown",
        )
Esempio n. 4
0
def activitypubpost_linkified_tags():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content=
            '<p>��foobar</p><p>barfoo!<br>[#fanart](https://mastodon.art/tags/fanart) '
            '[#mastoart](https://mastodon.art/tags/mastoart)</p>',
            public=True,
            provider_display_name="Mastodon",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
        )
Esempio n. 5
0
def get_outbound_entity(entity: BaseEntity, private_key):
    """Get the correct outbound entity for this protocol.

    We might have to look at entity values to decide the correct outbound entity.
    If we cannot find one, we should raise as conversion cannot be guaranteed to the given protocol.

    Private key of author is needed to be passed for signing the outbound entity.

    :arg entity: An entity instance which can be of a base or protocol entity class.
    :arg private_key: Private key of sender in str format
    :returns: Protocol specific entity class instance.
    :raises ValueError: If conversion cannot be done.
    """
    if getattr(entity, "outbound_doc", None):
        # If the entity already has an outbound doc, just return the entity as is
        return entity
    outbound = None
    cls = entity.__class__
    if cls in [
        ActivitypubAccept, ActivitypubFollow, ActivitypubProfile, ActivitypubPost, ActivitypubComment,
        ActivitypubRetraction, ActivitypubShare,
    ]:
        # Already fine
        outbound = entity
    elif cls == Accept:
        outbound = ActivitypubAccept.from_base(entity)
    elif cls == Follow:
        outbound = ActivitypubFollow.from_base(entity)
    elif cls == Post:
        outbound = ActivitypubPost.from_base(entity)
    elif cls == Profile:
        outbound = ActivitypubProfile.from_base(entity)
    elif cls == Retraction:
        outbound = ActivitypubRetraction.from_base(entity)
    elif cls == Comment:
        outbound = ActivitypubComment.from_base(entity)
    elif cls == Share:
        outbound = ActivitypubShare.from_base(entity)
    if not outbound:
        raise ValueError("Don't know how to convert this base entity to ActivityPub protocol entities.")
    # TODO LDS signing
    # if isinstance(outbound, DiasporaRelayableMixin) and not outbound.signature:
    #     # Sign by author if not signed yet. We don't want to overwrite any existing signature in the case
    #     # that this is being sent by the parent author
    #     outbound.sign(private_key)
    #     # If missing, also add same signature to `parent_author_signature`. This is required at the moment
    #     # in all situations but is apparently being removed.
    #     # TODO: remove this once Diaspora removes the extra signature
    #     outbound.parent_signature = outbound.signature
    if hasattr(outbound, "pre_send"):
        outbound.pre_send()
    return outbound
Esempio n. 6
0
def activitypubpost_mentions():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="""# raw_content\n\n@{[email protected]}""",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
            _mentions={
                "http://127.0.0.1:8000/profile/999999",
                "*****@*****.**",
            })
Esempio n. 7
0
def activitypubpost_images():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="raw_content",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"http://127.0.0.1:8000/profile/123456/",
            _children=[
                ActivitypubImage(url="foobar", media_type="image/jpeg"),
                ActivitypubImage(url="barfoo",
                                 name="spam and eggs",
                                 media_type="image/jpeg"),
            ],
        )
Esempio n. 8
0
def activitypubpost_embedded_images():
    with freeze_time("2019-04-27"):
        return ActivitypubPost(
            raw_content="""
#Cycling #lauttasaari #sea #sun


![](https://example.com/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a902541476.jpeg)![](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a902541477.png)

![foobar](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a902541478.gif)
![foobar barfoo](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a902541479.jpg)

#only a link, not embedded
[foo](https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414710.jpg)
#only a link, not embedded
https://jasonrobinson.me/media/uploads/2019/07/16/daa24d89-cedf-4fc7-bad8-74a9025414711.jpg
""",
            public=True,
            provider_display_name="Socialhome",
            id=f"http://127.0.0.1:8000/post/123456/",
            activity_id=f"http://127.0.0.1:8000/post/123456/#create",
            actor_id=f"https://jasonrobinson.me/u/jaywink/",
        )