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..848da50 100644 --- a/status_sdk/account.py +++ b/status_sdk/account.py @@ -928,14 +928,39 @@ def listen_messages(self) -> Generator[models.Message, None, None]: 7, # Image 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"] + 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) + 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]: """ 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: