mirror of
https://github.com/oxen-io/session-desktop.git
synced 2023-12-14 02:12:57 +01:00
Fix sync message issue
This commit is contained in:
parent
269c87a42e
commit
fd547941d6
|
@ -297,6 +297,11 @@
|
|||
const msg = conv.messageCollection.models.find(
|
||||
convMsg => convMsg.id === tmpMsg.id
|
||||
);
|
||||
|
||||
if (!msg) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return { msg };
|
||||
},
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ import { SyncMessage } from './SyncMessage';
|
|||
import { SignalService } from '../../../../../protobuf';
|
||||
import { MessageParams } from '../../Message';
|
||||
import { PubKey } from '../../../../types';
|
||||
import { ProtobufUtils } from '../../../../utils';
|
||||
|
||||
interface SentSyncMessageParams extends MessageParams {
|
||||
dataMessage: SignalService.IDataMessage;
|
||||
|
@ -21,7 +22,7 @@ export class SentSyncMessage extends SyncMessage {
|
|||
constructor(params: SentSyncMessageParams) {
|
||||
super({ timestamp: params.timestamp, identifier: params.identifier });
|
||||
|
||||
this.dataMessage = params.dataMessage;
|
||||
this.dataMessage = ProtobufUtils.convertToTS(params.dataMessage);
|
||||
this.expirationStartTimestamp = params.expirationStartTimestamp;
|
||||
this.sentTo = params.sentTo;
|
||||
this.unidentifiedDeliveries = params.unidentifiedDeliveries;
|
||||
|
|
28
ts/session/utils/Protobuf.ts
Normal file
28
ts/session/utils/Protobuf.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
import ByteBuffer from 'bytebuffer';
|
||||
|
||||
/**
|
||||
* Converts any object to a valid ts protobuf object.
|
||||
*
|
||||
* This is needed because there's a very jarring difference between `protobufjs` and `protobufts`.
|
||||
* `protobufjs` returns all `bytes` as `ByteBuffer` where as `protobufts` returns all `bytes` as `Uint8Array`.
|
||||
*/
|
||||
export function convertToTS(object: any): any {
|
||||
// No idea why js `ByteBuffer` and ts `ByteBuffer` differ ...
|
||||
if (object && object.constructor && object.constructor.name === 'ByteBuffer') {
|
||||
return new Uint8Array(object.toArrayBuffer());
|
||||
} else if (object instanceof ByteBuffer || object instanceof Buffer || object instanceof ArrayBuffer || object instanceof SharedArrayBuffer) {
|
||||
const arrayBuffer = ByteBuffer.wrap(object).toArrayBuffer();
|
||||
return new Uint8Array(arrayBuffer);
|
||||
} else if (Array.isArray(object)) {
|
||||
return object.map(convertToTS);
|
||||
} else if (object && typeof object === 'object') {
|
||||
const keys = Object.keys(object);
|
||||
const values: { [key: string]: any } = {};
|
||||
for (const key of keys) {
|
||||
values[key] = convertToTS(object[key]);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
return object;
|
||||
}
|
|
@ -3,6 +3,7 @@ import * as GroupUtils from './Groups';
|
|||
import * as SyncMessageUtils from './SyncMessage';
|
||||
import * as StringUtils from './String';
|
||||
import * as PromiseUtils from './Promise';
|
||||
import * as ProtobufUtils from './Protobuf';
|
||||
|
||||
export * from './Attachments';
|
||||
export * from './TypedEmitter';
|
||||
|
@ -14,4 +15,5 @@ export {
|
|||
GroupUtils,
|
||||
StringUtils,
|
||||
PromiseUtils,
|
||||
ProtobufUtils
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue