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

Allow multiple message types #32

Merged
merged 1 commit into from
Sep 5, 2023
Merged
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
21 changes: 19 additions & 2 deletions src/aleph/sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import queue
import threading
import time
import warnings
from datetime import datetime
from io import BytesIO
from pathlib import Path
Expand Down Expand Up @@ -721,6 +722,7 @@ async def get_messages(
pagination: int = 200,
page: int = 1,
message_type: Optional[MessageType] = None,
message_types: Optional[List[MessageType]] = None,
content_types: Optional[Iterable[str]] = None,
content_keys: Optional[Iterable[str]] = None,
refs: Optional[Iterable[str]] = None,
Expand All @@ -739,7 +741,8 @@ async def get_messages(

:param pagination: Number of items to fetch (Default: 200)
:param page: Page to fetch, begins at 1 (Default: 1)
:param message_type: Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
:param message_type: [DEPRECATED] Filter by message type, can be "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
:param message_types: Filter by message types, can be any combination of "AGGREGATE", "POST", "PROGRAM", "VM", "STORE" or "FORGET"
:param content_types: Filter by content type
:param content_keys: Filter by content key
:param refs: If set, only fetch posts that reference these hashes (in the "refs" field)
Expand All @@ -765,7 +768,13 @@ async def get_messages(
params: Dict[str, Any] = dict(pagination=pagination, page=page)

if message_type is not None:
warnings.warn(
"The message_type parameter is deprecated, please use message_types instead.",
DeprecationWarning,
)
params["msgType"] = message_type.value
if message_types is not None:
params["msgTypes"] = ",".join([t.value for t in message_types])
if content_types is not None:
params["contentTypes"] = ",".join(content_types)
if content_keys is not None:
Expand Down Expand Up @@ -863,6 +872,7 @@ async def get_message(
async def watch_messages(
self,
message_type: Optional[MessageType] = None,
message_types: Optional[Iterable[MessageType]] = None,
content_types: Optional[Iterable[str]] = None,
refs: Optional[Iterable[str]] = None,
addresses: Optional[Iterable[str]] = None,
Expand All @@ -876,7 +886,8 @@ async def watch_messages(
"""
Iterate over current and future matching messages asynchronously.

:param message_type: Type of message to watch
:param message_type: [DEPRECATED] Type of message to watch
:param message_types: Types of messages to watch
:param content_types: Content types to watch
:param refs: References to watch
:param addresses: Addresses to watch
Expand All @@ -890,7 +901,13 @@ async def watch_messages(
params: Dict[str, Any] = dict()

if message_type is not None:
warnings.warn(
"The message_type parameter is deprecated, please use message_types instead.",
DeprecationWarning,
)
params["msgType"] = message_type.value
if message_types is not None:
params["msgTypes"] = ",".join([t.value for t in message_types])
if content_types is not None:
params["contentTypes"] = ",".join(content_types)
if refs is not None:
Expand Down