Skip to content

Commit

Permalink
Feature: deprecate message_type in favor of message_types (#32)
Browse files Browse the repository at this point in the history
Client-side deprecation of `message_type`, see: aleph-im/pyaleph#444
  • Loading branch information
MHHukiewitz authored Sep 5, 2023
1 parent 5d66bf7 commit aea2d4d
Showing 1 changed file with 19 additions and 2 deletions.
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

0 comments on commit aea2d4d

Please sign in to comment.