do not sync profileKey on sync => only on ConfigurationMessage

pull/1528/head
Audric Ackermann 5 years ago
parent fc24df00fb
commit 43e2ca00ff
No known key found for this signature in database
GPG Key ID: 999F434D76324AD4

@ -108,23 +108,7 @@ export class ChatMessage extends DataMessage {
if (!sentTimestamp || !isNumber(sentTimestamp)) {
throw new Error('Tried to build a sync message without a sentTimestamp');
}
// the dataMessage.profileKey is of type ByteBuffer. We need to make it a Uint8Array
const lokiProfile: any = {};
if (dataMessage.profileKey?.length) {
lokiProfile.profileKey = new Uint8Array(
(dataMessage.profileKey as any).toArrayBuffer()
);
}
if (dataMessage.profile) {
if (dataMessage.profile?.displayName) {
lokiProfile.displayName = dataMessage.profile.displayName;
}
if (dataMessage.profile?.profilePicture) {
lokiProfile.avatarPointer = dataMessage.profile.profilePicture;
}
}
// don't include our profileKey on syncing message. This is to be done by a ConfigurationMessage now
const timestamp = toNumber(sentTimestamp);
const body = dataMessage.body || undefined;
@ -157,7 +141,6 @@ export class ChatMessage extends DataMessage {
attachments,
body,
quote,
lokiProfile,
preview,
syncTarget,
});

@ -36,5 +36,7 @@ export const fromHex = (d: string) => encode(d, 'hex');
export const fromHexToArray = (d: string) => new Uint8Array(encode(d, 'hex'));
export const fromBase64ToArrayBuffer = (d: string) => encode(d, 'base64');
export const fromBase64ToArray = (d: string) =>
new Uint8Array(encode(d, 'base64'));
export const fromArrayBufferToBase64 = (d: BufferType) => decode(d, 'base64');

@ -15,7 +15,12 @@ import {
ConfigurationMessageContact,
} from '../messages/outgoing/content/ConfigurationMessage';
import { ConversationModel } from '../../models/conversation';
import { fromHexToArray } from './String';
import {
fromBase64ToArray,
fromBase64ToArrayBuffer,
fromHexToArray,
} from './String';
import { fromBase64 } from 'bytebuffer';
const ITEM_ID_LAST_SYNC_TIMESTAMP = 'lastSyncedTimestamp';
@ -57,33 +62,43 @@ export const forceSyncConfigurationNowIfNeeded = async (
) =>
new Promise(resolve => {
const allConvos = ConversationController.getInstance().getConversations();
void getCurrentConfigurationMessage(allConvos).then(configMessage => {
// console.warn('forceSyncConfigurationNowIfNeeded with', configMessage);
try {
// this just adds the message to the sending queue.
// if waitForMessageSent is set, we need to effectively wait until then
// tslint:disable-next-line: no-void-expression
const callback = waitForMessageSent
? () => {
resolve(true);
}
: undefined;
void getMessageQueue().sendSyncMessage(configMessage, callback as any);
// either we resolve from the callback if we need to wait for it,
// or we don't want to wait, we resolve it here.
if (!waitForMessageSent) {
resolve(true);
void getCurrentConfigurationMessage(allConvos)
.then(configMessage => {
// console.warn('forceSyncConfigurationNowIfNeeded with', configMessage);
try {
// this just adds the message to the sending queue.
// if waitForMessageSent is set, we need to effectively wait until then
// tslint:disable-next-line: no-void-expression
const callback = waitForMessageSent
? () => {
resolve(true);
}
: undefined;
void getMessageQueue().sendSyncMessage(
configMessage,
callback as any
);
// either we resolve from the callback if we need to wait for it,
// or we don't want to wait, we resolve it here.
if (!waitForMessageSent) {
resolve(true);
}
} catch (e) {
window.log.warn(
'Caught an error while sending our ConfigurationMessage:',
e
);
resolve(false);
}
} catch (e) {
})
.catch(e => {
window.log.warn(
'Caught an error while sending our ConfigurationMessage:',
'Caught an error while building our ConfigurationMessage:',
e
);
resolve(false);
}
});
});
});
export const getCurrentConfigurationMessage = async (
@ -146,7 +161,7 @@ export const getCurrentConfigurationMessage = async (
const contacts = contactsModels.map(c => {
const profileKeyForContact = c.get('profileKey')
? fromHexToArray(c.get('profileKey') as string)
? fromBase64ToArray(c.get('profileKey') as string)
: undefined;
return new ConfigurationMessageContact({

Loading…
Cancel
Save