@@ -77,9 +77,9 @@ impl std::fmt::Display for RateLimitErr {
7777impl std:: error:: Error for RateLimitErr { }
7878#[ derive( Debug , Clone , Default ) ]
7979pub struct LastIds {
80- pub comments : ( String , String ) ,
81- pub posts : ( String , String ) ,
82- pub mentions : ( String , String ) ,
80+ pub comments : String ,
81+ pub posts : String ,
82+ pub mentions : String ,
8383}
8484
8585impl RedditClient {
@@ -209,7 +209,7 @@ impl RedditClient {
209209 let ( subs_response, posts_response, mentions_response) = join ! (
210210 OptionFuture :: from( SUBREDDIT_URL . clone( ) . map( |subreddit_url| {
211211 let request = self . client. get( subreddit_url) ;
212- let request = add_query( request, & last_ids. comments. 0 ) ;
212+ let request = add_query( request, & last_ids. comments) ;
213213 request. bearer_auth( & self . token. access_token) . send( )
214214 } ) ) ,
215215 OptionFuture :: from(
@@ -218,14 +218,14 @@ impl RedditClient {
218218 . flatten( )
219219 . map( |subreddit_url| {
220220 let request = self . client. get( subreddit_url) ;
221- let request = add_query( request, & last_ids. posts. 0 ) ;
221+ let request = add_query( request, & last_ids. posts) ;
222222 request. bearer_auth( & self . token. access_token) . send( )
223223 } )
224224 ) ,
225225 OptionFuture :: from( check_mentions. then_some( MENTION_URL . clone( ) ) . map(
226226 |subreddit_url| {
227227 let request = self . client. get( subreddit_url) ;
228- let request = add_query( request, & last_ids. mentions. 0 ) ;
228+ let request = add_query( request, & last_ids. mentions) ;
229229 request. bearer_auth( & self . token. access_token) . send( )
230230 }
231231 ) ) ,
@@ -265,14 +265,11 @@ impl RedditClient {
265265
266266 reset_timer = Self :: update_reset_timer ( reset_timer, t) ;
267267
268- if !a . is_empty ( )
269- && last_ids . mentions . 1 != ""
270- && !a . iter ( ) . any ( |x| x . meta . id == last_ids . mentions . 1 )
268+ if last_ids . mentions != ""
269+ && a . len ( )
270+ == * COMMENT_COUNT . get ( ) . expect ( "Comment count uninitialized" ) as usize
271271 {
272- warn ! (
273- "Failed to keep up with mentions. last_id: {}" ,
274- last_ids. mentions. 1
275- ) ;
272+ warn ! ( "Got a full response, meaning capacity is reached!" ) ;
276273 }
277274
278275 if let Some ( id) = id {
@@ -296,14 +293,11 @@ impl RedditClient {
296293
297294 reset_timer = Self :: update_reset_timer ( reset_timer, t) ;
298295
299- if !a . is_empty ( )
300- && last_ids . comments . 1 != ""
301- && !a . iter ( ) . any ( |x| x . meta . id == last_ids . comments . 1 )
296+ if last_ids . comments != ""
297+ && a . len ( )
298+ == * COMMENT_COUNT . get ( ) . expect ( "Comment count uninitialized" ) as usize
302299 {
303- warn ! (
304- "Failed to keep up with comments. last_id: {}" ,
305- last_ids. comments. 1
306- ) ;
300+ warn ! ( "Got a full response, meaning capacity is reached!" ) ;
307301 }
308302
309303 if let Some ( id) = id {
@@ -327,14 +321,11 @@ impl RedditClient {
327321
328322 reset_timer = Self :: update_reset_timer ( reset_timer, t) ;
329323
330- if !posts . is_empty ( )
331- && last_ids . posts . 1 != ""
332- && !posts . iter ( ) . any ( |x| x . meta . id == last_ids . posts . 1 )
324+ if last_ids . posts != ""
325+ && posts. len ( )
326+ == * COMMENT_COUNT . get ( ) . expect ( "Comment count uninitialized" ) as usize
333327 {
334- warn ! (
335- "Failed to keep up with posts. last_id: {}" ,
336- last_ids. posts. 1
337- ) ;
328+ warn ! ( "Got a full response, meaning capacity is reached!" ) ;
338329 }
339330
340331 if let Some ( id) = id {
@@ -603,17 +594,28 @@ impl RedditClient {
603594
604595 fn check_response_status ( response : & Response ) -> Result < ( ) , ( ) > {
605596 if !response. status ( ) . is_success ( ) {
606- if response. status ( ) . as_u16 ( ) == 500 {
607- error ! (
597+ match response. status ( ) . as_u16 ( ) {
598+ 500 => error ! (
608599 "Failed to get comments. Statuscode: {:?}. Internal server error." ,
609600 response. status( )
610- ) ;
611- } else {
612- error ! (
601+ ) ,
602+ 502 => error ! (
603+ "Failed to get comments. Statuscode: {:?}. Bad Gateway." ,
604+ response. status( )
605+ ) ,
606+ 503 => error ! (
607+ "Failed to get comments. Statuscode: {:?}. Service unavailable." ,
608+ response. status( )
609+ ) ,
610+ 504 => error ! (
611+ "Failed to get comments. Statuscode: {:?}. Gateway Timeout." ,
612+ response. status( )
613+ ) ,
614+ _ => error ! (
613615 "Failed to get comments. Statuscode: {:?}. Response: {:?}" ,
614616 response. status( ) ,
615617 response
616- ) ;
618+ ) ,
617619 }
618620 return Err ( ( ) ) ;
619621 }
@@ -637,7 +639,7 @@ impl RedditClient {
637639 Vec < CommentConstructed < Meta > > ,
638640 Vec < ( String , ( String , Commands , String ) ) > ,
639641 Option < ( f64 , f64 ) > ,
640- Option < ( String , String ) > ,
642+ Option < String > ,
641643 ) ,
642644 Box < dyn std:: error:: Error > ,
643645 > {
@@ -775,12 +777,10 @@ impl RedditClient {
775777 comments. push ( extracted_comment) ;
776778 }
777779 let id = if comments. is_empty ( ) {
778- warn ! ( "No comments. Requested comment (last_id or summon) is gone." ) ;
779- Some ( ( String :: new ( ) , String :: new ( ) ) )
780+ info ! ( "No comments. Requested comment (last_id or summon) is gone." ) ;
781+ Some ( String :: new ( ) )
780782 } else {
781- comments
782- . get ( 1 )
783- . map ( |o| ( o. meta . id . clone ( ) , comments. get ( 0 ) . unwrap ( ) . meta . id . clone ( ) ) )
783+ comments. get ( 1 ) . map ( |o| o. meta . id . clone ( ) )
784784 } ;
785785
786786 Ok ( (
@@ -1092,9 +1092,9 @@ mod tests {
10921092 let _ = COMMENT_COUNT . set ( 100 ) ;
10931093 let mut already_replied = vec ! [ ] ;
10941094 let mut last_ids = LastIds {
1095- comments : ( "t1_m86nsre" . to_owned ( ) , "" . to_owned ( ) ) ,
1096- posts : ( "t3_83us27sa" . to_owned ( ) , "" . to_owned ( ) ) ,
1097- mentions : ( "" . to_owned ( ) , "" . to_owned ( ) ) ,
1095+ comments : "t1_m86nsre" . to_owned ( ) ,
1096+ posts : "t3_83us27sa" . to_owned ( ) ,
1097+ mentions : "" . to_owned ( ) ,
10981098 } ;
10991099 let ( status, comments) = join ! (
11001100 async {
@@ -1327,10 +1327,7 @@ mod tests {
13271327 ) ;
13281328 println ! ( "{comments:?}" ) ;
13291329 assert_eq ! ( t, Some ( ( 350.0 , 10.0 ) ) ) ;
1330- assert_eq ! (
1331- id. unwrap( ) ,
1332- ( "t3_m38msug" . to_owned( ) , "t3_m38msum" . to_owned( ) )
1333- ) ;
1330+ assert_eq ! ( id. unwrap( ) , "t3_m38msug" . to_owned( ) ) ;
13341331 }
13351332
13361333 #[ test]
0 commit comments