@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414limitations under the License.
1515*/
1616
17- import { MatrixEvent , Room , Direction } from "matrix-js-sdk/src/matrix" ;
17+ import { Direction , MatrixEvent , Room } from "matrix-js-sdk/src/matrix" ;
1818import { saveAs } from "file-saver" ;
1919import { logger } from "matrix-js-sdk/src/logger" ;
2020import sanitizeFilename from "sanitize-filename" ;
@@ -135,9 +135,6 @@ export default abstract class Exporter {
135135 // when export type is LastNMessages
136136 limit = this . exportOptions . numberOfMessages ! ;
137137 break ;
138- case ExportType . Timeline :
139- limit = 40 ;
140- break ;
141138 default :
142139 limit = 10 ** 8 ;
143140 }
@@ -148,58 +145,60 @@ export default abstract class Exporter {
148145 const eventMapper = this . room . client . getEventMapper ( ) ;
149146
150147 let prevToken : string | null = null ;
151- let limit = this . getLimit ( ) ;
152- const events : MatrixEvent [ ] = [ ] ;
153-
154- while ( limit ) {
155- const eventsPerCrawl = Math . min ( limit , 1000 ) ;
156- const res = await this . room . client . createMessagesRequest (
157- this . room . roomId ,
158- prevToken ,
159- eventsPerCrawl ,
160- Direction . Backward ,
161- ) ;
162-
163- if ( this . cancelled ) {
164- this . cleanUp ( ) ;
165- return [ ] ;
166- }
167148
168- if ( res . chunk . length === 0 ) break ;
149+ let events : MatrixEvent [ ] = [ ] ;
150+ if ( this . exportType === ExportType . Timeline ) {
151+ events = this . room . getLiveTimeline ( ) . getEvents ( ) ;
152+ } else {
153+ let limit = this . getLimit ( ) ;
154+ while ( limit ) {
155+ const eventsPerCrawl = Math . min ( limit , 1000 ) ;
156+ const res = await this . room . client . createMessagesRequest (
157+ this . room . roomId ,
158+ prevToken ,
159+ eventsPerCrawl ,
160+ Direction . Backward ,
161+ ) ;
169162
170- limit -= res . chunk . length ;
163+ if ( this . cancelled ) {
164+ this . cleanUp ( ) ;
165+ return [ ] ;
166+ }
171167
172- const matrixEvents : MatrixEvent [ ] = res . chunk . map ( eventMapper ) ;
168+ if ( res . chunk . length === 0 ) break ;
173169
174- for ( const mxEv of matrixEvents ) {
175- // if (this.exportOptions.startDate && mxEv.getTs() < this.exportOptions.startDate) {
176- // // Once the last message received is older than the start date, we break out of both the loops
177- // limit = 0;
178- // break;
179- // }
180- events . push ( mxEv ) ;
181- }
170+ limit -= res . chunk . length ;
182171
183- if ( this . exportType === ExportType . LastNMessages ) {
184- this . updateProgress (
185- _t ( "Fetched %(count)s events out of %(total)s" , {
186- count : events . length ,
187- total : this . exportOptions . numberOfMessages ,
188- } ) ,
189- ) ;
190- } else {
191- this . updateProgress (
192- _t ( "Fetched %(count)s events so far" , {
193- count : events . length ,
194- } ) ,
195- ) ;
196- }
172+ const matrixEvents : MatrixEvent [ ] = res . chunk . map ( eventMapper ) ;
197173
198- prevToken = res . end ?? null ;
199- }
200- // Reverse the events so that we preserve the order
201- for ( let i = 0 ; i < Math . floor ( events . length / 2 ) ; i ++ ) {
202- [ events [ i ] , events [ events . length - i - 1 ] ] = [ events [ events . length - i - 1 ] , events [ i ] ] ;
174+ for ( const mxEv of matrixEvents ) {
175+ // if (this.exportOptions.startDate && mxEv.getTs() < this.exportOptions.startDate) {
176+ // // Once the last message received is older than the start date, we break out of both the loops
177+ // limit = 0;
178+ // break;
179+ // }
180+ events . push ( mxEv ) ;
181+ }
182+
183+ if ( this . exportType === ExportType . LastNMessages ) {
184+ this . updateProgress (
185+ _t ( "Fetched %(count)s events out of %(total)s" , {
186+ count : events . length ,
187+ total : this . exportOptions . numberOfMessages ,
188+ } ) ,
189+ ) ;
190+ } else {
191+ this . updateProgress (
192+ _t ( "Fetched %(count)s events so far" , {
193+ count : events . length ,
194+ } ) ,
195+ ) ;
196+ }
197+
198+ prevToken = res . end ?? null ;
199+ }
200+ // Reverse the events so that we preserve the order
201+ events . reverse ( ) ;
203202 }
204203
205204 const decryptionPromises = events
0 commit comments