8
8
9
9
//! Context module.
10
10
11
- use std:: { io, path:: Path , pin:: pin, sync:: Arc , time:: Duration } ;
11
+ use std:: { io, ops :: Deref , path:: Path , pin:: pin, sync:: Arc , time:: Duration } ;
12
12
13
13
use futures_util:: future:: { Either , select} ;
14
14
use grammers_client:: {
15
15
InvocationError , Update ,
16
16
types:: {
17
- ActionSender , CallbackQuery , Chat , InlineQuery , InlineSend , InputMessage , Media , Message ,
18
- PackedChat , Photo , User , media:: Uploaded ,
17
+ self , ActionSender , Chat , InputMessage , Media , PackedChat , Photo , User ,
18
+ media:: Uploaded ,
19
+ update:: { CallbackQuery , InlineQuery , InlineSend , Message } ,
19
20
} ,
20
21
} ;
21
22
use tokio:: {
@@ -221,9 +222,11 @@ impl Context {
221
222
/// let message = ctx.message().await;
222
223
/// # }
223
224
/// ```
224
- pub async fn message ( & self ) -> Option < Message > {
225
+ pub async fn message ( & self ) -> Option < types :: Message > {
225
226
match self . update . as_ref ( ) . expect ( "No update" ) {
226
- Update :: NewMessage ( message) | Update :: MessageEdited ( message) => Some ( message. clone ( ) ) ,
227
+ Update :: NewMessage ( message) | Update :: MessageEdited ( message) => {
228
+ Some ( message. deref ( ) . clone ( ) )
229
+ }
227
230
Update :: CallbackQuery ( query) => {
228
231
let message = query. load_message ( ) . await . expect ( "Failed to load message" ) ;
229
232
@@ -339,7 +342,7 @@ impl Context {
339
342
pub async fn send < M : Into < InputMessage > > (
340
343
& self ,
341
344
message : M ,
342
- ) -> Result < Message , InvocationError > {
345
+ ) -> Result < types :: Message , InvocationError > {
343
346
if let Some ( msg) = self . message ( ) . await {
344
347
msg. respond ( message) . await
345
348
} else {
@@ -375,7 +378,7 @@ impl Context {
375
378
pub async fn reply < M : Into < InputMessage > > (
376
379
& self ,
377
380
message : M ,
378
- ) -> Result < Message , InvocationError > {
381
+ ) -> Result < types :: Message , InvocationError > {
379
382
if let Some ( msg) = self . message ( ) . await {
380
383
msg. reply ( message) . await
381
384
} else {
@@ -449,7 +452,7 @@ impl Context {
449
452
/// # Errors
450
453
///
451
454
/// Returns an error if the reply message could not be retrieved.
452
- pub async fn get_reply ( & self ) -> Result < Option < Message > , InvocationError > {
455
+ pub async fn get_reply ( & self ) -> Result < Option < types :: Message > , InvocationError > {
453
456
if let Some ( msg) = self . message ( ) . await {
454
457
msg. get_reply ( ) . await
455
458
} else {
@@ -477,7 +480,7 @@ impl Context {
477
480
pub async fn forward_to < C : Into < PackedChat > > (
478
481
& self ,
479
482
chat : C ,
480
- ) -> Result < Message , InvocationError > {
483
+ ) -> Result < types :: Message , InvocationError > {
481
484
if let Some ( msg) = self . message ( ) . await {
482
485
msg. forward_to ( chat) . await
483
486
} else {
@@ -547,7 +550,7 @@ impl Context {
547
550
/// # Errors
548
551
///
549
552
/// Returns an error if the message could not be forwarded.
550
- pub async fn forward_to_self ( & self ) -> Result < Message , InvocationError > {
553
+ pub async fn forward_to_self ( & self ) -> Result < types :: Message , InvocationError > {
551
554
if let Some ( msg) = self . message ( ) . await {
552
555
let chat = self . client ( ) . get_me ( ) . await ?;
553
556
@@ -578,7 +581,7 @@ impl Context {
578
581
pub async fn edit_or_reply < M : Into < InputMessage > > (
579
582
& self ,
580
583
message : M ,
581
- ) -> Result < Message , InvocationError > {
584
+ ) -> Result < types :: Message , InvocationError > {
582
585
if let Some ( msg) = self . message ( ) . await {
583
586
if let Some ( query) = self . callback_query ( ) {
584
587
query. answer ( ) . edit ( message) . await ?;
@@ -660,7 +663,10 @@ impl Context {
660
663
/// # Errors
661
664
///
662
665
/// Returns an error if the message could not be retrieved.
663
- pub async fn get_message ( & self , message_id : i32 ) -> Result < Option < Message > , InvocationError > {
666
+ pub async fn get_message (
667
+ & self ,
668
+ message_id : i32 ,
669
+ ) -> Result < Option < types:: Message > , InvocationError > {
664
670
self . get_messages ( vec ! [ message_id] )
665
671
. await
666
672
. map ( |mut v| v. pop ( ) . unwrap_or_default ( ) )
@@ -687,7 +693,7 @@ impl Context {
687
693
pub async fn get_messages (
688
694
& self ,
689
695
message_ids : Vec < i32 > ,
690
- ) -> Result < Vec < Option < Message > > , InvocationError > {
696
+ ) -> Result < Vec < Option < types :: Message > > , InvocationError > {
691
697
self . client
692
698
. get_messages_by_id ( self . chat ( ) . expect ( "No chat" ) , & message_ids)
693
699
. await
@@ -741,7 +747,7 @@ impl Context {
741
747
& self ,
742
748
user : & User ,
743
749
limit : Option < usize > ,
744
- ) -> Result < Vec < Message > , InvocationError > {
750
+ ) -> Result < Vec < types :: Message > , InvocationError > {
745
751
let mut iter = self
746
752
. client
747
753
. iter_messages ( self . chat ( ) . expect ( "No chat" ) )
@@ -780,7 +786,7 @@ impl Context {
780
786
pub async fn get_messages_from_self (
781
787
& self ,
782
788
limit : Option < usize > ,
783
- ) -> Result < Vec < Message > , InvocationError > {
789
+ ) -> Result < Vec < types :: Message > , InvocationError > {
784
790
let mut iter = self
785
791
. client
786
792
. iter_messages ( self . chat ( ) . expect ( "No chat" ) )
0 commit comments