@@ -291,8 +291,7 @@ impl NCRequest {
291
291
token : & str ,
292
292
) -> Result < NCReqDataMessage , Box < dyn Error > > {
293
293
let url_string = self . base_url . clone ( ) + "/ocs/v2.php/apps/spreed/api/v1/chat/" + token;
294
- let mut params = HashMap :: new ( ) ;
295
- params. insert ( "message" . to_owned ( ) , message. clone ( ) ) ;
294
+ let params = HashMap :: from ( [ ( "message" , message) ] ) ;
296
295
let url = Url :: parse_with_params ( & url_string, params) ?;
297
296
let response = self . request_post ( url) . await ?;
298
297
@@ -316,13 +315,10 @@ impl NCRequest {
316
315
name : & str ,
317
316
) -> Result < Vec < NCReqDataUser > , Box < dyn Error > > {
318
317
let url_string = self . base_url . clone ( ) + "/ocs/v2.php/core/autocomplete/get" ;
319
- let mut params = HashMap :: new ( ) ;
320
- params. insert ( "limit" . to_owned ( ) , "200" . to_string ( ) ) ;
321
- params. insert ( "search" . to_owned ( ) , name. to_string ( ) ) ;
322
-
318
+ let params = HashMap :: from ( [ ( "limit" , "200" ) , ( "search" , name) ] ) ;
323
319
let url = Url :: parse_with_params ( & url_string, params) ?;
324
-
325
320
let response = self . request ( url) . await ?;
321
+
326
322
match response. status ( ) {
327
323
reqwest:: StatusCode :: OK => {
328
324
let text = response. text ( ) . await ?;
@@ -352,8 +348,7 @@ impl NCRequest {
352
348
+ "/ocs/v2.php/apps/spreed/api/v4/room/"
353
349
+ token
354
350
+ "/participants" ;
355
- let mut params = HashMap :: new ( ) ;
356
- params. insert ( "includeStatus" . to_owned ( ) , "true" . to_string ( ) ) ;
351
+ let params = HashMap :: from ( [ ( "includeStatus" , "true" ) ] ) ;
357
352
let url = Url :: parse_with_params ( & url_string, params) ?;
358
353
359
354
let response = self . request ( url) . await ?;
@@ -394,10 +389,11 @@ impl NCRequest {
394
389
last_timestamp : Option < i64 > ,
395
390
) -> Result < ( Vec < NCReqDataRoom > , i64 ) , Box < dyn Error > > {
396
391
let url_string = self . base_url . clone ( ) + "/ocs/v2.php/apps/spreed/api/v4/room" ;
397
- let mut params = HashMap :: new ( ) ;
398
- if let Some ( timestamp) = last_timestamp {
399
- params. insert ( "modifiedSince" . to_owned ( ) , timestamp. to_string ( ) ) ;
400
- }
392
+ let params = if let Some ( timestamp) = last_timestamp {
393
+ HashMap :: from ( [ ( "modifiedSince" , timestamp. to_string ( ) ) ] )
394
+ } else {
395
+ HashMap :: new ( )
396
+ } ;
401
397
let url = Url :: parse_with_params ( & url_string, & params) ?;
402
398
let response = self . request ( url) . await ?;
403
399
match response. status ( ) {
@@ -466,18 +462,23 @@ impl NCRequest {
466
462
last_message : Option < i32 > ,
467
463
) -> Result < Option < Vec < NCReqDataMessage > > , Box < dyn Error > > {
468
464
let url_string = self . base_url . clone ( ) + "/ocs/v2.php/apps/spreed/api/v1/chat/" + token;
469
- let mut params = HashMap :: new ( ) ;
470
- params. insert ( "limit" . to_owned ( ) , maxMessage. to_string ( ) ) ;
471
- params. insert ( "setReadMarker" . to_owned ( ) , "0" . to_owned ( ) ) ;
472
- if let Some ( lastId) = last_message {
465
+ let params = if let Some ( lastId) = last_message {
473
466
log:: debug!( "Last MessageID {}" , lastId) ;
474
- params. insert ( "lastKnownMessageId" . to_owned ( ) , lastId. to_string ( ) ) ;
475
- params. insert ( "lookIntoFuture" . to_owned ( ) , "1" . to_owned ( ) ) ;
476
- params. insert ( "timeout" . to_owned ( ) , "0" . to_owned ( ) ) ;
477
- params. insert ( "includeLastKnown" . to_owned ( ) , "0" . to_owned ( ) ) ;
467
+ HashMap :: from ( [
468
+ ( "limit" , maxMessage. to_string ( ) ) ,
469
+ ( "setReadMarker" , "0" . into ( ) ) ,
470
+ ( "lookIntoFuture" , "1" . to_owned ( ) ) ,
471
+ ( "lastKnownMessageId" , lastId. to_string ( ) ) ,
472
+ ( "timeout" , "0" . to_owned ( ) ) ,
473
+ ( "includeLastKnown" , "0" . to_owned ( ) ) ,
474
+ ] )
478
475
} else {
479
- params. insert ( "lookIntoFuture" . to_owned ( ) , "0" . to_owned ( ) ) ;
480
- }
476
+ HashMap :: from ( [
477
+ ( "limit" , maxMessage. to_string ( ) ) ,
478
+ ( "setReadMarker" , "0" . into ( ) ) ,
479
+ ( "lookIntoFuture" , "0" . into ( ) ) ,
480
+ ] )
481
+ } ;
481
482
let url = Url :: parse_with_params ( & url_string, & params) ?;
482
483
let response = self . request ( url) . await ?;
483
484
match response. status ( ) {
@@ -542,8 +543,10 @@ impl NCRequest {
542
543
543
544
fn dump_json_to_log ( & self , url : & str , text : & str ) -> Result < ( ) , Box < dyn Error > > {
544
545
if let Some ( path) = & self . json_dump_path {
545
- let mut name = path. clone ( ) ;
546
- name. push ( url. replace ( '/' , "_" ) ) ;
546
+ let name: String = url
547
+ . chars ( )
548
+ . map ( |ch| if ch == '/' { '_' } else { ch } )
549
+ . collect ( ) ;
547
550
let mut file = File :: create ( name) ?;
548
551
let pretty_text = jzon:: stringify_pretty ( jzon:: parse ( text) ?, 2 ) ;
549
552
file. write_all ( pretty_text. as_bytes ( ) ) ?;
0 commit comments