fix ui reader remove second skip on unfinished mobfile (#2028)
This commit is contained in:
parent
0912c4fb57
commit
f81fd1f6c0
3 changed files with 14 additions and 14 deletions
|
|
@ -42,8 +42,10 @@ export default class MessageLoader {
|
|||
? (b: Uint8Array) => decryptSessionBytes(b, this.session.fileKey!)
|
||||
: (b: Uint8Array) => Promise.resolve(b);
|
||||
const fileReader = new MFileReader(new Uint8Array(), this.session.startedAt);
|
||||
let fileNum = 0;
|
||||
return async (b: Uint8Array) => {
|
||||
try {
|
||||
fileNum += 1;
|
||||
const mobBytes = await decrypt(b);
|
||||
const data = unpack(mobBytes);
|
||||
fileReader.append(data);
|
||||
|
|
@ -115,7 +117,7 @@ export default class MessageLoader {
|
|||
console.warn('Broken timestamp messages', brokenMessages);
|
||||
}
|
||||
|
||||
onMessagesDone(sortedMsgs, file);
|
||||
onMessagesDone(sortedMsgs, `${file} ${fileNum}`);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
this.uiErrorHandler?.error('Error parsing file: ' + e.message);
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ import Logger from 'App/logger'
|
|||
|
||||
// TODO: composition instead of inheritance
|
||||
// needSkipMessage() and next() methods here use buf and p protected properties,
|
||||
// which should be probably somehow incapsulated
|
||||
export default class MFileReader extends RawMessageReader {
|
||||
private pLastMessageID: number = 0
|
||||
private currentTime: number
|
||||
|
|
@ -15,11 +14,10 @@ export default class MFileReader extends RawMessageReader {
|
|||
private noIndexes: boolean = false
|
||||
constructor(data: Uint8Array, private startTime?: number, private logger= console) {
|
||||
super(data)
|
||||
// if (noIndexes) this.noIndexes = true
|
||||
}
|
||||
|
||||
public checkForIndexes() {
|
||||
// 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff = no indexes + weird failover (don't ask)
|
||||
// 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff = no indexes + weird fail over (don't ask)
|
||||
const skipIndexes = this.readCustomIndex(this.buf.slice(0, 8)) === 72057594037927940
|
||||
|| this.readCustomIndex(this.buf.slice(0, 9)) === 72057594037927940
|
||||
|
||||
|
|
@ -28,9 +26,7 @@ export default class MFileReader extends RawMessageReader {
|
|||
this.skip(8)
|
||||
}
|
||||
this.noIndexes = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
private needSkipMessage(): boolean {
|
||||
|
|
@ -51,17 +47,19 @@ export default class MFileReader extends RawMessageReader {
|
|||
return id
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the messages from byteArray, returns null if read ended
|
||||
* will reset to last correct pointer if encountered bad read
|
||||
* (i.e mobfile was split in two parts and it encountered partial message)
|
||||
* then will proceed to read next message when next mobfile part will be added
|
||||
* via super.append
|
||||
* */
|
||||
private readRawMessage(): RawMessage | null {
|
||||
if (!this.noIndexes) this.skip(8)
|
||||
try {
|
||||
const msg = super.readMessage()
|
||||
if (!msg) {
|
||||
this.skip(-8)
|
||||
}
|
||||
return msg
|
||||
return super.readMessage()
|
||||
} catch (e) {
|
||||
this.error = true
|
||||
this.logger.error("Read message error:", e)
|
||||
this.error = true
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
|
@ -104,6 +102,7 @@ export default class MFileReader extends RawMessageReader {
|
|||
|
||||
const index = this.noIndexes ? 0 : this.getLastMessageID()
|
||||
const msg = Object.assign(rewriteMessage(rMsg), {
|
||||
// @ts-ignore
|
||||
time: this.currentTime ?? rMsg.timestamp - this.startTime!,
|
||||
tabId: this.currentTab,
|
||||
}, !this.noIndexes ? { _index: index } : {})
|
||||
|
|
|
|||
|
|
@ -913,7 +913,6 @@ export default class RawMessageReader extends PrimitiveReader {
|
|||
|
||||
default:
|
||||
throw new Error(`Unrecognizable message type: ${ tp }; Pointer at the position ${this.p} of ${this.buf.length}`)
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue