From d37a5708b9a8e2000e172c7744d1cbe372d5b38e Mon Sep 17 00:00:00 2001 From: Nick Ninov Date: Wed, 9 Sep 2026 21:09:48 +0300 Subject: [PATCH 1/2] real-time: Group multiple image URLs in a single yield --- pyproject.toml | 2 +- status_sdk/account.py | 20 +++++++++++++++++++- status_sdk/models.py | 7 +++++-- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 4f530d4..c0d6e07 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "status-sdk" -version = "1.1.4" +version = "1.1.5" description = "Private chat. Communities. Multi-chain wallet. Browser. dApps all in one app, powered by SNT." readme = "README.md" requires-python = ">=3.11" diff --git a/status_sdk/account.py b/status_sdk/account.py index f4cffa8..dd85316 100644 --- a/status_sdk/account.py +++ b/status_sdk/account.py @@ -928,14 +928,32 @@ def listen_messages(self) -> Generator[models.Message, None, None]: 7, # Image 18, # Bridged Message ] - + albums: dict[str, list[dict]] = {} for message in self.signal.listen("messages.new"): event: dict = message.get("event", {}) if "chats" in event or "messages" in event: for raw in event["messages"]: if raw["contentType"] not in ALLOWED_CONTENT_TYPES: continue + + if not raw.get("albumId"): + yield models.Message.from_raw(raw) + continue + + album_id: str = raw["albumId"] + if album_id not in albums: + albums[album_id] = [] + + albums[album_id].append(raw) + if len(albums[album_id]) != raw["albumImagesCount"]: + continue + + raw["image"] = [ + point["image"] + for point in albums[album_id] + ] yield models.Message.from_raw(raw) + albums.pop(album_id) def get_messages(self, chat_id: str, start_timestamp: Optional[Union[str, datetime.datetime, datetime.date, pd.Timestamp]] = None, end_timestamp: Optional[Union[str, datetime.datetime, datetime.date, pd.Timestamp]] = None) -> list[dict]: """ diff --git a/status_sdk/models.py b/status_sdk/models.py index 7bd1af3..4fcd774 100644 --- a/status_sdk/models.py +++ b/status_sdk/models.py @@ -112,10 +112,13 @@ def from_raw(cls, raw: dict) -> Self: params["content_type"] = "sticker" # Image elif content_type == 7: - img_path = raw["image"] + if isinstance(raw["image"], str): + raw["image"] = [raw["image"]] + + img_paths: list[str] = raw["image"] text = raw["text"] caption = f"{text}\n\n" if len(text) > 0 else "" - params["content"] = f"{caption}{img_path}" + params["content"] = caption + "\n".join(img_paths) params["content_type"] = "image" # Bridged Message elif content_type == 18: From ff6b4bd27271d3c0d8a9b211051b3de162a640c6 Mon Sep 17 00:00:00 2001 From: Nick Ninov Date: Wed, 9 Sep 2026 21:11:21 +0300 Subject: [PATCH 2/2] real-time: Remove duplicate messages --- status_sdk/account.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/status_sdk/account.py b/status_sdk/account.py index dd85316..848da50 100644 --- a/status_sdk/account.py +++ b/status_sdk/account.py @@ -929,15 +929,18 @@ def listen_messages(self) -> Generator[models.Message, None, None]: 18, # Bridged Message ] albums: dict[str, list[dict]] = {} + processed: list[str] = [] + SIZE = 100 for message in self.signal.listen("messages.new"): event: dict = message.get("event", {}) if "chats" in event or "messages" in event: for raw in event["messages"]: - if raw["contentType"] not in ALLOWED_CONTENT_TYPES: + if raw["contentType"] not in ALLOWED_CONTENT_TYPES or raw["id"] in processed: continue if not raw.get("albumId"): yield models.Message.from_raw(raw) + processed.append(raw["id"]) continue album_id: str = raw["albumId"] @@ -953,8 +956,12 @@ def listen_messages(self) -> Generator[models.Message, None, None]: for point in albums[album_id] ] yield models.Message.from_raw(raw) + processed.append(raw["id"]) albums.pop(album_id) + if len(processed) == SIZE: + processed = [] + def get_messages(self, chat_id: str, start_timestamp: Optional[Union[str, datetime.datetime, datetime.date, pd.Timestamp]] = None, end_timestamp: Optional[Union[str, datetime.datetime, datetime.date, pd.Timestamp]] = None) -> list[dict]: """ Get all of the messages in the given start and end timestamps.