Skip to content
This repository was archived by the owner on Feb 11, 2026. It is now read-only.

Commit 509239e

Browse files
committed
Добавлен класс ContactPresencePayload и метод get_contact_presence для получения информации о присутствии контактов в сети
1 parent 3e33019 commit 509239e

4 files changed

Lines changed: 48 additions & 2 deletions

File tree

src/pymax/mixins/user.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
from pymax.payloads import (
55
AddContactByPhonePayload,
66
ContactActionPayload,
7+
ContactPresencePayload,
78
FetchContactsPayload,
89
SearchByPhonePayload,
910
)
1011
from pymax.protocols import ClientProtocol
1112
from pymax.static.enum import ContactAction, Opcode
12-
from pymax.types import Contact, Session, User
13+
from pymax.types import Contact, Presence, Session, User
1314
from pymax.utils import MixinsUtils
1415

1516

@@ -246,3 +247,23 @@ def get_chat_id(self, first_user_id: int, second_user_id: int) -> int:
246247
:rtype: int
247248
"""
248249
return first_user_id ^ second_user_id
250+
251+
async def get_contact_presence(self, contact_ids: list[int]) -> list[Presence]:
252+
"""
253+
Получение информации о присутствии контактов в сети.
254+
255+
:param contact_ids: Список идентификаторов контактов.
256+
:type contact_ids: list[int]
257+
"""
258+
payload = ContactPresencePayload(contact_ids=contact_ids).model_dump(by_alias=True)
259+
260+
data = await self._send_and_wait(opcode=Opcode.CONTACT_PRESENCE, payload=payload)
261+
if data.get("payload", {}).get("error"):
262+
MixinsUtils.handle_error(data)
263+
264+
presence = data["payload"].get("presence", {})
265+
266+
return [
267+
Presence(user_id=int(contact_id), last_seen=info.get("seen"))
268+
for contact_id, info in presence.items()
269+
]

src/pymax/payloads.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,3 +405,7 @@ class SendEmailCodePayload(CamelModel):
405405
class AddContactByPhonePayload(CamelModel):
406406
phone: str
407407
first_name: str
408+
409+
410+
class ContactPresencePayload(CamelModel):
411+
contact_ids: list[int]

src/pymax/static/enum.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Opcode(int, Enum):
3030
CONTACT_MUTUAL = 38
3131
CONTACT_PHOTOS = 39
3232
CONTACT_SORT = 40
33-
CONTACT_ADD_BY_PHONE = 41
33+
CONTACT_ADD_BY_PHONE = 41 # ✅
3434
CONTACT_VERIFY = 42
3535
REMOVE_CONTACT_PHOTO = 43
3636
CONTACT_INFO_BY_PHONE = 46 # ✅

src/pymax/types.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1218,3 +1218,24 @@ def __repr__(self) -> str:
12181218
@override
12191219
def __str__(self) -> str:
12201220
return f"ReadState: unread={self.unread}, mark={self.mark}"
1221+
1222+
1223+
class Presence:
1224+
def __init__(self, user_id: int, last_seen: int) -> None:
1225+
self.user_id = user_id
1226+
self.last_seen = last_seen
1227+
1228+
@classmethod
1229+
def from_dict(cls, data: dict[str, Any]) -> Self:
1230+
return cls(
1231+
user_id=data["userId"],
1232+
last_seen=data["lastSeen"],
1233+
)
1234+
1235+
@override
1236+
def __repr__(self) -> str:
1237+
return f"Presence(user_id={self.user_id!r}, last_seen={self.last_seen!r})"
1238+
1239+
@override
1240+
def __str__(self) -> str:
1241+
return f"Presence: user {self.user_id} last seen at {self.last_seen}"

0 commit comments

Comments
 (0)