|
|
@ -18,7 +18,6 @@ import { OpenGroupUtils } from '../session/apis/open_group_api/utils';
|
|
|
|
import { getOpenGroupV2ConversationId } from '../session/apis/open_group_api/utils/OpenGroupUtils';
|
|
|
|
import { getOpenGroupV2ConversationId } from '../session/apis/open_group_api/utils/OpenGroupUtils';
|
|
|
|
import { getSwarmPollingInstance } from '../session/apis/snode_api';
|
|
|
|
import { getSwarmPollingInstance } from '../session/apis/snode_api';
|
|
|
|
import { getConversationController } from '../session/conversations';
|
|
|
|
import { getConversationController } from '../session/conversations';
|
|
|
|
import { IncomingMessage } from '../session/messages/incoming/IncomingMessage';
|
|
|
|
|
|
|
|
import { Profile, ProfileManager } from '../session/profile_manager/ProfileManager';
|
|
|
|
import { Profile, ProfileManager } from '../session/profile_manager/ProfileManager';
|
|
|
|
import { PubKey } from '../session/types';
|
|
|
|
import { PubKey } from '../session/types';
|
|
|
|
import { StringUtils, UserUtils } from '../session/utils';
|
|
|
|
import { StringUtils, UserUtils } from '../session/utils';
|
|
|
@ -43,6 +42,8 @@ import {
|
|
|
|
} from '../util/storage';
|
|
|
|
} from '../util/storage';
|
|
|
|
|
|
|
|
|
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
|
|
// eslint-disable-next-line import/no-unresolved
|
|
|
|
|
|
|
|
import { SnodeNamespaces } from '../session/apis/snode_api/namespaces';
|
|
|
|
|
|
|
|
import { RetrieveMessageItemWithNamespace } from '../session/apis/snode_api/types';
|
|
|
|
import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions';
|
|
|
|
import { ConfigWrapperObjectTypes } from '../webworker/workers/browser/libsession_worker_functions';
|
|
|
|
import {
|
|
|
|
import {
|
|
|
|
ContactsWrapperActions,
|
|
|
|
ContactsWrapperActions,
|
|
|
@ -57,18 +58,29 @@ import { HexKeyPair } from './keypairs';
|
|
|
|
import { queueAllCachedFromSource } from './receiver';
|
|
|
|
import { queueAllCachedFromSource } from './receiver';
|
|
|
|
import { EnvelopePlus } from './types';
|
|
|
|
import { EnvelopePlus } from './types';
|
|
|
|
|
|
|
|
|
|
|
|
function groupByVariant(
|
|
|
|
function groupByNamespace(incomingConfigs: Array<RetrieveMessageItemWithNamespace>) {
|
|
|
|
incomingConfigs: Array<IncomingMessage<SignalService.ISharedConfigMessage>>
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
const groupedByVariant: Map<
|
|
|
|
const groupedByVariant: Map<
|
|
|
|
ConfigWrapperObjectTypes,
|
|
|
|
ConfigWrapperObjectTypes,
|
|
|
|
Array<IncomingMessage<SignalService.ISharedConfigMessage>>
|
|
|
|
Array<RetrieveMessageItemWithNamespace>
|
|
|
|
> = new Map();
|
|
|
|
> = new Map();
|
|
|
|
|
|
|
|
|
|
|
|
incomingConfigs.forEach(incomingConfig => {
|
|
|
|
incomingConfigs.forEach(incomingConfig => {
|
|
|
|
const { kind } = incomingConfig.message;
|
|
|
|
const { namespace } = incomingConfig;
|
|
|
|
|
|
|
|
|
|
|
|
const wrapperId = LibSessionUtil.kindToVariant(kind);
|
|
|
|
const wrapperId: ConfigWrapperObjectTypes | null =
|
|
|
|
|
|
|
|
namespace === SnodeNamespaces.UserProfile
|
|
|
|
|
|
|
|
? 'UserConfig'
|
|
|
|
|
|
|
|
: namespace === SnodeNamespaces.UserContacts
|
|
|
|
|
|
|
|
? 'ContactsConfig'
|
|
|
|
|
|
|
|
: namespace === SnodeNamespaces.UserGroups
|
|
|
|
|
|
|
|
? 'UserGroupsConfig'
|
|
|
|
|
|
|
|
: namespace === SnodeNamespaces.ConvoInfoVolatile
|
|
|
|
|
|
|
|
? 'ConvoInfoVolatileConfig'
|
|
|
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!wrapperId) {
|
|
|
|
|
|
|
|
throw new Error('Unexpected wrapperId');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!groupedByVariant.has(wrapperId)) {
|
|
|
|
if (!groupedByVariant.has(wrapperId)) {
|
|
|
|
groupedByVariant.set(wrapperId, []);
|
|
|
|
groupedByVariant.set(wrapperId, []);
|
|
|
@ -80,10 +92,10 @@ function groupByVariant(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function mergeConfigsWithIncomingUpdates(
|
|
|
|
async function mergeConfigsWithIncomingUpdates(
|
|
|
|
incomingConfigs: Array<IncomingMessage<SignalService.ISharedConfigMessage>>
|
|
|
|
incomingConfigs: Array<RetrieveMessageItemWithNamespace>
|
|
|
|
): Promise<Map<ConfigWrapperObjectTypes, IncomingConfResult>> {
|
|
|
|
): Promise<Map<ConfigWrapperObjectTypes, IncomingConfResult>> {
|
|
|
|
// first, group by variant so we do a single merge call
|
|
|
|
// first, group by variant so we do a single merge call
|
|
|
|
const groupedByVariant = groupByVariant(incomingConfigs);
|
|
|
|
const groupedByNamespace = groupByNamespace(incomingConfigs);
|
|
|
|
|
|
|
|
|
|
|
|
const groupedResults: Map<ConfigWrapperObjectTypes, IncomingConfResult> = new Map();
|
|
|
|
const groupedResults: Map<ConfigWrapperObjectTypes, IncomingConfResult> = new Map();
|
|
|
|
|
|
|
|
|
|
|
@ -91,15 +103,15 @@ async function mergeConfigsWithIncomingUpdates(
|
|
|
|
const publicKey = UserUtils.getOurPubKeyStrFromCache();
|
|
|
|
const publicKey = UserUtils.getOurPubKeyStrFromCache();
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
for (let index = 0; index < groupedByVariant.size; index++) {
|
|
|
|
for (let index = 0; index < groupedByNamespace.size; index++) {
|
|
|
|
const variant = [...groupedByVariant.keys()][index];
|
|
|
|
const variant = [...groupedByNamespace.keys()][index];
|
|
|
|
const sameVariant = groupedByVariant.get(variant);
|
|
|
|
const sameVariant = groupedByNamespace.get(variant);
|
|
|
|
if (!sameVariant?.length) {
|
|
|
|
if (!sameVariant?.length) {
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const toMerge = sameVariant.map(msg => ({
|
|
|
|
const toMerge = sameVariant.map(msg => ({
|
|
|
|
data: msg.message.data,
|
|
|
|
data: StringUtils.fromBase64ToArray(msg.data),
|
|
|
|
hash: msg.messageHash,
|
|
|
|
hash: msg.hash,
|
|
|
|
}));
|
|
|
|
}));
|
|
|
|
if (window.sessionFeatureFlags.debug.debugLibsessionDumps) {
|
|
|
|
if (window.sessionFeatureFlags.debug.debugLibsessionDumps) {
|
|
|
|
window.log.info(
|
|
|
|
window.log.info(
|
|
|
@ -110,9 +122,7 @@ async function mergeConfigsWithIncomingUpdates(
|
|
|
|
for (let dumpIndex = 0; dumpIndex < toMerge.length; dumpIndex++) {
|
|
|
|
for (let dumpIndex = 0; dumpIndex < toMerge.length; dumpIndex++) {
|
|
|
|
const element = toMerge[dumpIndex];
|
|
|
|
const element = toMerge[dumpIndex];
|
|
|
|
window.log.info(
|
|
|
|
window.log.info(
|
|
|
|
`printDumpsForDebugging: toMerge of ${dumpIndex}:${element.hash}: ${StringUtils.toHex(
|
|
|
|
`printDumpsForDebugging: toMerge of ${dumpIndex}:${element.hash}: ${element.data} `,
|
|
|
|
element.data
|
|
|
|
|
|
|
|
)} `,
|
|
|
|
|
|
|
|
StringUtils.toHex(await GenericWrapperActions.dump(variant))
|
|
|
|
StringUtils.toHex(await GenericWrapperActions.dump(variant))
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -122,8 +132,8 @@ async function mergeConfigsWithIncomingUpdates(
|
|
|
|
const needsPush = await GenericWrapperActions.needsPush(variant);
|
|
|
|
const needsPush = await GenericWrapperActions.needsPush(variant);
|
|
|
|
const needsDump = await GenericWrapperActions.needsDump(variant);
|
|
|
|
const needsDump = await GenericWrapperActions.needsDump(variant);
|
|
|
|
const mergedTimestamps = sameVariant
|
|
|
|
const mergedTimestamps = sameVariant
|
|
|
|
.filter(m => hashesMerged.includes(m.messageHash))
|
|
|
|
.filter(m => hashesMerged.includes(m.hash))
|
|
|
|
.map(m => m.envelopeTimestamp);
|
|
|
|
.map(m => m.timestamp);
|
|
|
|
const latestEnvelopeTimestamp = Math.max(...mergedTimestamps);
|
|
|
|
const latestEnvelopeTimestamp = Math.max(...mergedTimestamps);
|
|
|
|
|
|
|
|
|
|
|
|
window.log.debug(
|
|
|
|
window.log.debug(
|
|
|
@ -895,7 +905,7 @@ async function processMergingResults(results: Map<ConfigWrapperObjectTypes, Inco
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function handleConfigMessagesViaLibSession(
|
|
|
|
async function handleConfigMessagesViaLibSession(
|
|
|
|
configMessages: Array<IncomingMessage<SignalService.ISharedConfigMessage>>
|
|
|
|
configMessages: Array<RetrieveMessageItemWithNamespace>
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
|
|
|
|
const userConfigLibsession = await ReleasedFeatures.checkIsUserConfigFeatureReleased();
|
|
|
|
|
|
|
|
|
|
|
@ -910,9 +920,8 @@ async function handleConfigMessagesViaLibSession(
|
|
|
|
window?.log?.debug(
|
|
|
|
window?.log?.debug(
|
|
|
|
`Handling our sharedConfig message via libsession_util ${JSON.stringify(
|
|
|
|
`Handling our sharedConfig message via libsession_util ${JSON.stringify(
|
|
|
|
configMessages.map(m => ({
|
|
|
|
configMessages.map(m => ({
|
|
|
|
variant: LibSessionUtil.kindToVariant(m.message.kind),
|
|
|
|
namespace: m.namespace,
|
|
|
|
hash: m.messageHash,
|
|
|
|
hash: m.hash,
|
|
|
|
seqno: (m.message.seqno as Long).toNumber(),
|
|
|
|
|
|
|
|
}))
|
|
|
|
}))
|
|
|
|
)}`
|
|
|
|
)}`
|
|
|
|
);
|
|
|
|
);
|
|
|
|