@@ -22,16 +22,43 @@ class Updates{
22
22
/**
23
23
* Updates constructor.
24
24
*
25
- * @param object|null $data The data object containing Telegram updates.
25
+ * @param object|null $data The data object containing Telegram updates.
26
+ * @param bool $enableDefaultUpdates Whether the default updates should be enabled or not.
26
27
*/
27
- public function __construct (?object $ data ){
28
+ public function __construct (?object $ data, bool $ enableDefaultUpdates = false ){
28
29
if ($ data !== NULL ){
29
30
30
31
if (isset ($ data ->result [0 ]))
31
32
$ this ->lastUpdateID = $ data ->result [array_key_last ($ data ->result )]->update_id ?? null ;
32
33
else
33
34
$ this ->lastUpdateID = null ;
34
35
36
+ if ($ enableDefaultUpdates ){
37
+
38
+ foreach ($ data ->result ?? [$ data ] as &$ upd ){
39
+ $ upd ->user = $ upd ->message ->from ??
40
+ $ upd ->message ->sender_chat ??
41
+ $ upd ->edited_message ->from ??
42
+ $ upd ->inline_query ->from ??
43
+ $ upd ->chosen_inline_result ->from ??
44
+ $ upd ->callback_query ->from ??
45
+ $ upd ->shipping_query ->from ??
46
+ $ upd ->poll_answer ->user ??
47
+ $ upd ->chat_member ->from ??
48
+ $ upd ->chat_join_request ->from ??
49
+ null ;
50
+
51
+ $ upd ->chat = $ upd ->message ->chat ??
52
+ $ upd ->edited_message ->chat ??
53
+ $ upd ->channel_post ->chat ??
54
+ $ upd ->edited_channel_post ->chat ??
55
+ $ upd ->callback_query ->message ->chat ??
56
+ $ upd ->my_chat_member ->chat ??
57
+ $ upd ->chat_member ->chat ??
58
+ $ upd ->chat_join_request ->chat ??
59
+ null ;
60
+ }
61
+ }
35
62
36
63
foreach ($ data as $ key => $ value )
37
64
$ this ->$ key = $ value ;
0 commit comments