@@ -25,6 +25,7 @@ def __init__(self, username: str, password: str) -> None:
25
25
self .auth = None
26
26
self .groups = None
27
27
self .events = None
28
+ self .messages = None
28
29
29
30
async def login_chat (self ) -> None :
30
31
api_chat_url = f"{ self .api_url } chat"
@@ -118,10 +119,20 @@ async def get_person(self, user: str) -> DictFromJSON:
118
119
raise KeyError (errmsg )
119
120
120
121
@_SpondBase .require_authentication
121
- async def get_messages (self ) -> Optional [DictFromJSON ]:
122
+ async def get_messages (
123
+ self ,
124
+ max_chats : int = 100 ,
125
+ ) -> Optional [DictFromJSON ]:
122
126
"""
123
127
Retrieve messages (chats).
124
128
129
+ Parameters
130
+ ----------
131
+ max_chats : int, optional
132
+ Set a limit on the number of chats returned.
133
+ For performance reasons, defaults to 100.
134
+ Uses `max` API parameter.
135
+
125
136
Returns
126
137
-------
127
138
list[dict] or None
@@ -130,9 +141,14 @@ async def get_messages(self) -> Optional[DictFromJSON]:
130
141
"""
131
142
if not self .auth :
132
143
await self .login_chat ()
133
- url = f"{ self .chat_url } /chats/?max=10"
134
- async with self .clientsession .get (url , headers = {"auth" : self .auth }) as r :
135
- return await r .json ()
144
+ url = f"{ self .chat_url } /chats/"
145
+ async with self .clientsession .get (
146
+ url ,
147
+ headers = {"auth" : self .auth },
148
+ params = {"max" : str (max_chats )},
149
+ ) as r :
150
+ self .messages = await r .json ()
151
+ return self .messages
136
152
137
153
@_SpondBase .require_authentication
138
154
async def _continue_chat (self , chat_id : str , text : str ):
0 commit comments