Skip to content
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
29 changes: 27 additions & 2 deletions status_sdk/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand Down
7 changes: 5 additions & 2 deletions status_sdk/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading