@@ -77,6 +77,13 @@ class Poll(Object, Update):
77
77
78
78
close_date (:py:obj:`~datetime.datetime`, *optional*):
79
79
Point in time when the poll will be automatically closed.
80
+
81
+ user (:obj:`~pyrogram.types.User`, *optional*):
82
+ The user that changed the answer to the poll, if the voter isn't anonymous.
83
+
84
+ voter_chat (:obj:`~pyrogram.types.Chat`, *optional*):
85
+ The chat that changed the answer to the poll, if the voter is anonymous.
86
+
80
87
"""
81
88
82
89
def __init__ (
@@ -97,7 +104,9 @@ def __init__(
97
104
explanation : Optional [str ] = None ,
98
105
explanation_entities : Optional [List ["types.MessageEntity" ]] = None ,
99
106
open_period : Optional [int ] = None ,
100
- close_date : Optional [datetime ] = None
107
+ close_date : Optional [datetime ] = None ,
108
+ user : Optional ["types.User" ] = None ,
109
+ voter_chat : Optional ["types.Chat" ] = None ,
101
110
):
102
111
super ().__init__ (client )
103
112
@@ -116,6 +125,9 @@ def __init__(
116
125
self .explanation_entities = explanation_entities
117
126
self .open_period = open_period
118
127
self .close_date = close_date
128
+ # TODO: spit this out
129
+ self .user = user
130
+ self .voter_chat = voter_chat
119
131
120
132
@staticmethod
121
133
def _parse (client , media_poll : Union ["raw.types.MessageMediaPoll" , "raw.types.UpdateMessagePoll" ]) -> "Poll" :
@@ -193,44 +205,81 @@ def _parse(client, media_poll: Union["raw.types.MessageMediaPoll", "raw.types.Up
193
205
)
194
206
195
207
@staticmethod
196
- def _parse_update (client , update : "raw.types.UpdateMessagePoll" ):
197
- if update .poll is not None :
198
- return Poll ._parse (client , update )
199
-
200
- # TODO: FIXME!
201
- results = update .results .results
202
- chosen_option_id = None
203
- correct_option_id = None
204
- options = []
205
- question = ""
206
-
207
- for i , result in enumerate (results ):
208
- if result .chosen :
209
- chosen_option_id = i
208
+ def _parse_update (
209
+ client ,
210
+ update : Union ["raw.types.UpdateMessagePoll" , "raw.types.UpdateMessagePollVote" ],
211
+ users : dict ,
212
+ chats : dict ,
213
+ ):
214
+ if isinstance (update , raw .types .UpdateMessagePoll ):
215
+ if update .poll is not None :
216
+ return Poll ._parse (client , update )
217
+
218
+ # TODO: FIXME!
219
+ results = update .results .results
220
+ chosen_option_id = None
221
+ correct_option_id = None
222
+ options = []
223
+ question = ""
224
+
225
+ for i , result in enumerate (results ):
226
+ if result .chosen :
227
+ chosen_option_id = i
210
228
211
- if result .correct :
212
- correct_option_id = i
229
+ if result .correct :
230
+ correct_option_id = i
213
231
214
- options .append (
215
- types .PollOption (
216
- text = "" ,
217
- text_entities = [],
218
- voter_count = result .voters ,
219
- data = result .option ,
220
- client = client
232
+ options .append (
233
+ types .PollOption (
234
+ text = "" ,
235
+ text_entities = [],
236
+ voter_count = result .voters ,
237
+ data = result .option ,
238
+ client = client
239
+ )
221
240
)
241
+
242
+ return Poll (
243
+ id = str (update .poll_id ),
244
+ question = question ,
245
+ options = options ,
246
+ total_voter_count = update .results .total_voters ,
247
+ is_closed = False ,
248
+ chosen_option_id = chosen_option_id ,
249
+ correct_option_id = correct_option_id ,
250
+ client = client
222
251
)
223
252
224
- return Poll (
225
- id = str (update .poll_id ),
226
- question = question ,
227
- options = options ,
228
- total_voter_count = update .results .total_voters ,
229
- is_closed = False ,
230
- chosen_option_id = chosen_option_id ,
231
- correct_option_id = correct_option_id ,
232
- client = client
233
- )
253
+ if isinstance (update , raw .types .UpdateMessagePollVote ):
254
+ user = None
255
+ voter_chat = None
256
+ if isinstance (update .peer , raw .types .PeerUser ):
257
+ user = types .Chat ._parse_user_chat (client , users [update .peer .user_id ])
258
+
259
+ elif isinstance (update .peer , raw .types .PeerChat ):
260
+ voter_chat = types .Chat ._parse_chat_chat (client , chats [update .peer .chat_id ])
261
+
262
+ else :
263
+ voter_chat = types .Chat ._parse_channel_chat (client , chats [update .peer .channel_id ])
264
+
265
+ return Poll (
266
+ id = str (update .poll_id ),
267
+ question = "" ,
268
+ options = [
269
+ types .PollOption (
270
+ text = "" ,
271
+ text_entities = [],
272
+ voter_count = None ,
273
+ data = option ,
274
+ client = client
275
+ ) for option in update .options
276
+ ],
277
+ total_voter_count = None ,
278
+ is_closed = False ,
279
+ user = user ,
280
+ voter_chat = voter_chat ,
281
+ client = client
282
+ )
234
283
235
284
async def stop (
236
285
self ,
0 commit comments