@@ -544,35 +544,23 @@ export default class EmbeddedChatApi {
544544 this . sdk . connection . close ( ) ;
545545 }
546546
547- /**
548- * @param {boolean } anonymousMode
549- * @param {Object } options This object should include query or fields.
550- * query - json object which accepts MongoDB query operators.
551- * fields - json object with properties that have either 1 or 0 to include them or exclude them
552- * @returns messages
553- */
554547 async getMessages (
555548 anonymousMode = false ,
556549 options : {
557- query ?: object | undefined ;
558- field ?: object | undefined ;
559- } = {
560- query : undefined ,
561- field : undefined ,
562- } ,
550+ oldest ?: string ;
551+ latest ?: string ;
552+ count ?: number ;
553+ } = { } ,
563554 isChannelPrivate = false
564555 ) {
565556 const roomType = isChannelPrivate ? "groups" : "channels" ;
566557 const endp = anonymousMode ? "anonymousread" : "messages" ;
567- const query = options ?. query
568- ? `&query=${ JSON . stringify ( options . query ) } `
569- : "" ;
570- const field = options ?. field
571- ? `&field=${ JSON . stringify ( options . field ) } `
572- : "" ;
558+ const oldest = options ?. oldest ? `&oldest=${ options . oldest } ` : "" ;
559+ const latest = options ?. latest ? `&latest=${ options . latest } ` : "" ;
560+ const count = options ?. count != null ? `&count=${ options . count } ` : "" ;
573561 try {
574562 return await this . _restRequest (
575- `/v1/${ roomType } .${ endp } ?roomId=${ this . rid } ${ query } ${ field } `
563+ `/v1/${ roomType } .${ endp } ?roomId=${ this . rid } ${ oldest } ${ latest } ${ count } `
576564 ) ;
577565 } catch ( err : any ) {
578566 console . error ( err instanceof Error ? err . message : err ) ;
@@ -583,28 +571,22 @@ export default class EmbeddedChatApi {
583571 async getOlderMessages (
584572 anonymousMode = false ,
585573 options : {
586- query ?: object | undefined ;
587- field ?: object | undefined ;
574+ oldest ?: string ;
575+ latest ?: string ;
576+ count ?: number ;
588577 offset ?: number ;
589- } = {
590- query : undefined ,
591- field : undefined ,
592- offset : 50 ,
593- } ,
578+ } = { } ,
594579 isChannelPrivate = false
595580 ) {
596581 const roomType = isChannelPrivate ? "groups" : "channels" ;
597582 const endp = anonymousMode ? "anonymousread" : "messages" ;
598- const query = options ?. query
599- ? `&query=${ JSON . stringify ( options . query ) } `
600- : "" ;
601- const field = options ?. field
602- ? `&field=${ JSON . stringify ( options . field ) } `
603- : "" ;
604- const offset = options ?. offset ? options . offset : 0 ;
583+ const oldest = options ?. oldest ? `&oldest=${ options . oldest } ` : "" ;
584+ const latest = options ?. latest ? `&latest=${ options . latest } ` : "" ;
585+ const count = options ?. count != null ? `&count=${ options . count } ` : "" ;
586+ const offset = options ?. offset ? `&offset=${ options . offset } ` : "&offset=0" ;
605587 try {
606588 return await this . _restRequest (
607- `/v1/${ roomType } .${ endp } ?roomId=${ this . rid } ${ query } ${ field } &offset= ${ offset } `
589+ `/v1/${ roomType } .${ endp } ?roomId=${ this . rid } ${ oldest } ${ latest } ${ count } ${ offset } `
608590 ) ;
609591 } catch ( err : any ) {
610592 console . error ( err instanceof Error ? err . message : String ( err ) ) ;
0 commit comments