|
|
|
@ -11,9 +11,7 @@ export abstract class ContentMessage implements Message {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public plainTextBuffer(): Uint8Array {
|
|
|
|
|
const encoded = SignalService.Content.encode(this.contentProto()).finish();
|
|
|
|
|
|
|
|
|
|
return this.processPlainTextBuffer(encoded);
|
|
|
|
|
return SignalService.Content.encode(this.contentProto()).finish();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract ttl(): number;
|
|
|
|
@ -28,26 +26,4 @@ export abstract class ContentMessage implements Message {
|
|
|
|
|
return (window.getMessageTTL() || 24) * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private processPlainTextBuffer(buffer: Uint8Array): Uint8Array {
|
|
|
|
|
const paddedMessageLength = this.getPaddedMessageLength(
|
|
|
|
|
buffer.byteLength + 1
|
|
|
|
|
);
|
|
|
|
|
const plainText = new Uint8Array(paddedMessageLength - 1);
|
|
|
|
|
plainText.set(new Uint8Array(buffer));
|
|
|
|
|
plainText[buffer.byteLength] = 0x80;
|
|
|
|
|
|
|
|
|
|
return plainText;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private getPaddedMessageLength(length: number): number {
|
|
|
|
|
const messageLengthWithTerminator = length + 1;
|
|
|
|
|
let messagePartCount = Math.floor(messageLengthWithTerminator / 160);
|
|
|
|
|
|
|
|
|
|
if (messageLengthWithTerminator % 160 !== 0) {
|
|
|
|
|
messagePartCount += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return messagePartCount * 160;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|