diff --git a/bluesky/input.py b/bluesky/input.py index 164eae7..4264ef8 100644 --- a/bluesky/input.py +++ b/bluesky/input.py @@ -20,6 +20,7 @@ from cross.attachments import ( MediaAttachment, QuoteAttachment, RemoteUrlAttachment, + TagsAttachment, ) from cross.media import Blob, cleanup_blobs, download_blob from cross.post import Post, PostRef @@ -187,6 +188,8 @@ class BlueskyBaseInputService(BlueskyService, InputService, ABC): ] ), ) + if "tags" in record: + post.attachments.put(TagsAttachment(tags=record["tags"])) if parent: self._insert_post( diff --git a/cross/attachments.py b/cross/attachments.py index 902ef1a..c2358fd 100644 --- a/cross/attachments.py +++ b/cross/attachments.py @@ -8,39 +8,52 @@ class Attachment: pass +# self labels, like CWs, or adult content labels @dataclass(kw_only=True) class LabelsAttachment(Attachment): labels: list[str] +# languages used in the post @dataclass(kw_only=True) class LanguagesAttachment(Attachment): langs: list[str] +# if media on this post is considered sensitive @dataclass(kw_only=True) class SensitiveAttachment(Attachment): sensitive: bool +# link to the post on the current service @dataclass(kw_only=True) class RemoteUrlAttachment(Attachment): url: str +# any media attachment. image, video, audio, flash games, etc. @dataclass(kw_only=True) class MediaAttachment(Attachment): blobs: list[Blob] +# quote of some post on the same service @dataclass(kw_only=True) class QuoteAttachment(Attachment): quoted_id: str quoted_user: str +# embed to an external website @dataclass(kw_only=True) class ExternalEmbedAttachment(Attachment): uri: str title: str | None desc: str | None + + +# out-of-band tags (the correct kind of tags) +@dataclass(kw_only=True) +class TagsAttachment(Attachment): + tags: list[str] diff --git a/mastodon/output.py b/mastodon/output.py index 15593a3..8f65174 100644 --- a/mastodon/output.py +++ b/mastodon/output.py @@ -12,6 +12,7 @@ from cross.attachments import ( QuoteAttachment, RemoteUrlAttachment, SensitiveAttachment, + TagsAttachment, ) from cross.media import Blob from cross.post import Post, PostRef @@ -299,7 +300,19 @@ class MastodonOutputService(MastodonService, OutputService): quoted_status_id = quoted_mappings[0]["identifier"] - post_tokens = post.tokens + post_tokens = post.tokens.copy() + + # mastodon doesn't have out-of-band tag posting + # so append them at the end of the post + oob_tags = post.attachments.get(TagsAttachment) + if oob_tags and oob_tags.tags: + if post_tokens: + post_tokens.append(TextToken(text="\n\n")) + + for tag in oob_tags.tags: + post_tokens.append(TagToken(tag=tag)) + post_tokens.append(TextToken(text=" ")) + if ( post.text_type == "text/x.misskeymarkdown" and self.instance_info.text_format != "text/x.misskeymarkdown"