@@ -22,16 +22,43 @@ class Updates{
2222 /**
2323 * Updates constructor.
2424 *
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.
2627 */
27- public function __construct (?object $ data ){
28+ public function __construct (?object $ data, bool $ enableDefaultUpdates = false ){
2829 if ($ data !== NULL ){
2930
3031 if (isset ($ data ->result [0 ]))
3132 $ this ->lastUpdateID = $ data ->result [array_key_last ($ data ->result )]->update_id ?? null ;
3233 else
3334 $ this ->lastUpdateID = null ;
3435
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+ }
3562
3663 foreach ($ data as $ key => $ value )
3764 $ this ->$ key = $ value ;
0 commit comments