Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add posts langs support #96

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion atproto/xrpc_client/client/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from atproto.xrpc_client.client.async_raw import AsyncClientRaw
from atproto.xrpc_client.client.methods_mixin import SessionMethodsMixin
from atproto.xrpc_client.models import ids
from atproto.xrpc_client.models.languages import DEFAULT_LANGUAGE_CODE1

if t.TYPE_CHECKING:
from atproto.xrpc_client.client.base import InvokeType
Expand Down Expand Up @@ -88,17 +89,22 @@ async def send_post(
'models.AppBskyEmbedRecordWithMedia.Main',
]
] = None,
langs: t.Optional[t.List[str]] = None,
) -> models.ComAtprotoRepoCreateRecord.Response:
"""Send post.

Note:
If `profile_identify` is not provided will be sent to the current profile.

The async default language is ``en``.
Available languages are async defined in :py:mod:`atproto.xrpc_client.models.languages`.

Args:
text: Text of the post.
profile_identify: Handle or DID. Where to send post.
reply_to: Root and parent of the post to reply to.
embed: Embed models that should be attached to the post.
langs: List of used languages in the post.

Returns:
:obj:`models.ComAtprotoRepoCreateRecord.Response`: Reference to the created post record.
Expand All @@ -111,12 +117,15 @@ async def send_post(
if profile_identify:
repo = profile_identify

if not langs:
langs = [DEFAULT_LANGUAGE_CODE1]

return await self.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=repo,
collection=ids.AppBskyFeedPost,
record=models.AppBskyFeedPost.Main(
createdAt=datetime.now().isoformat(), text=text, reply=reply_to, embed=embed
createdAt=datetime.now().isoformat(), text=text, reply=reply_to, embed=embed, langs=langs
),
)
)
Expand Down
11 changes: 10 additions & 1 deletion atproto/xrpc_client/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from atproto.xrpc_client.client.methods_mixin import SessionMethodsMixin
from atproto.xrpc_client.client.raw import ClientRaw
from atproto.xrpc_client.models import ids
from atproto.xrpc_client.models.languages import DEFAULT_LANGUAGE_CODE1

if t.TYPE_CHECKING:
from atproto.xrpc_client.client.base import InvokeType
Expand Down Expand Up @@ -80,17 +81,22 @@ def send_post(
'models.AppBskyEmbedRecordWithMedia.Main',
]
] = None,
langs: t.Optional[t.List[str]] = None,
) -> models.ComAtprotoRepoCreateRecord.Response:
"""Send post.

Note:
If `profile_identify` is not provided will be sent to the current profile.

The default language is ``en``.
Available languages are defined in :py:mod:`atproto.xrpc_client.models.languages`.

Args:
text: Text of the post.
profile_identify: Handle or DID. Where to send post.
reply_to: Root and parent of the post to reply to.
embed: Embed models that should be attached to the post.
langs: List of used languages in the post.

Returns:
:obj:`models.ComAtprotoRepoCreateRecord.Response`: Reference to the created post record.
Expand All @@ -103,12 +109,15 @@ def send_post(
if profile_identify:
repo = profile_identify

if not langs:
langs = [DEFAULT_LANGUAGE_CODE1]

return self.com.atproto.repo.create_record(
models.ComAtprotoRepoCreateRecord.Data(
repo=repo,
collection=ids.AppBskyFeedPost,
record=models.AppBskyFeedPost.Main(
createdAt=datetime.now().isoformat(), text=text, reply=reply_to, embed=embed
createdAt=datetime.now().isoformat(), text=text, reply=reply_to, embed=embed, langs=langs
),
)
)
Expand Down
Loading