feat: add contacts & user profile handling of incoming messages
parent
141c22ed43
commit
d1cefd4729
@ -0,0 +1,56 @@
|
||||
import Long from 'long';
|
||||
import { SignalService } from '../../../protobuf';
|
||||
|
||||
type IncomingMessageAvailableTypes =
|
||||
| SignalService.DataMessage
|
||||
| SignalService.CallMessage
|
||||
| SignalService.ReceiptMessage
|
||||
| SignalService.TypingMessage
|
||||
| SignalService.ConfigurationMessage
|
||||
| SignalService.DataExtractionNotification
|
||||
| SignalService.Unsend
|
||||
| SignalService.MessageRequestResponse
|
||||
| SignalService.SharedConfigMessage;
|
||||
|
||||
export class IncomingMessage<T extends IncomingMessageAvailableTypes> {
|
||||
public readonly envelopeTimestamp: number;
|
||||
public readonly authorOrGroupPubkey: any;
|
||||
public readonly authorInGroup: string | null;
|
||||
public readonly messageHash: string;
|
||||
public readonly message: T;
|
||||
|
||||
/**
|
||||
*
|
||||
* - `messageHash` is the hash as retrieved from the `/receive` request
|
||||
* - `envelopeTimestamp` is part of the message envelope and the what our sent timestamp must be.
|
||||
* - `authorOrGroupPubkey`:
|
||||
* * for a 1o1 message, the is the sender
|
||||
* * for a message in a group, this is the pubkey of the group (as everyone
|
||||
* in a group send message to the group pubkey)
|
||||
* - `authorInGroup` is only set when this message is incoming from a closed group. This is the old `senderIdentity` and is the publicKey of the sender inside the message itself once decrypted. This is the real sender of a closed group message.
|
||||
* - `message` is the data of the ContentMessage itself.
|
||||
*/
|
||||
constructor({
|
||||
envelopeTimestamp,
|
||||
authorOrGroupPubkey,
|
||||
authorInGroup,
|
||||
message,
|
||||
messageHash,
|
||||
}: {
|
||||
messageHash: string;
|
||||
envelopeTimestamp: Long;
|
||||
authorOrGroupPubkey: string;
|
||||
authorInGroup: string | null;
|
||||
message: T;
|
||||
}) {
|
||||
if (envelopeTimestamp > Long.fromNumber(Number.MAX_SAFE_INTEGER)) {
|
||||
throw new Error('envelopeTimestamp as Long is > Number.MAX_SAFE_INTEGER');
|
||||
}
|
||||
|
||||
this.envelopeTimestamp = envelopeTimestamp.toNumber();
|
||||
this.authorOrGroupPubkey = authorOrGroupPubkey;
|
||||
this.authorInGroup = authorInGroup;
|
||||
this.messageHash = messageHash;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
import { difference } from 'lodash';
|
||||
import { UserUtils } from '..';
|
||||
import { ConfigDumpData } from '../../../data/configDump/configDump';
|
||||
import { ConfigWrapperObjectTypes } from '../../../webworker/workers/browser/libsession_worker_functions';
|
||||
import { callLibSessionWorker } from '../../../webworker/workers/browser/libsession_worker_interface';
|
||||
|
||||
export async function initializeLibSessionUtilWrappers() {
|
||||
const keypair = await UserUtils.getUserED25519KeyPairBytes();
|
||||
if (!keypair) {
|
||||
throw new Error('edkeypair not found for current user');
|
||||
}
|
||||
const privateKeyEd25519 = keypair.privKeyBytes;
|
||||
const dumps = await ConfigDumpData.getAllDumpsWithData();
|
||||
|
||||
const userVariantsBuildWithoutErrors = new Set<ConfigWrapperObjectTypes>();
|
||||
|
||||
for (let index = 0; index < dumps.length; index++) {
|
||||
const dump = dumps[index];
|
||||
try {
|
||||
await callLibSessionWorker([
|
||||
dump.variant,
|
||||
'init',
|
||||
privateKeyEd25519,
|
||||
dump.data.length ? dump.data : null,
|
||||
]);
|
||||
|
||||
userVariantsBuildWithoutErrors.add(dump.variant);
|
||||
} catch (e) {
|
||||
window.log.warn(`init of UserConfig failed with ${e.message} `);
|
||||
throw new Error(`initializeLibSessionUtilWrappers failed with ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO complete this list
|
||||
const requiredVariants: Array<ConfigWrapperObjectTypes> = ['UserConfig', 'ContactsConfig']; // 'conversations'
|
||||
const missingRequiredVariants: Array<ConfigWrapperObjectTypes> = difference(requiredVariants, [
|
||||
...userVariantsBuildWithoutErrors.values(),
|
||||
]);
|
||||
|
||||
for (let index = 0; index < missingRequiredVariants.length; index++) {
|
||||
const missingVariant = missingRequiredVariants[index];
|
||||
await callLibSessionWorker([missingVariant, 'init', privateKeyEd25519, null]);
|
||||
}
|
||||
}
|
@ -1,21 +1,28 @@
|
||||
import { BaseConfigActions, BaseConfigWrapper, UserConfigActionsType } from 'session_util_wrapper';
|
||||
import {
|
||||
BaseConfigActions,
|
||||
BaseConfigWrapper,
|
||||
ContactsConfigActionsType,
|
||||
UserConfigActionsType,
|
||||
} from 'session_util_wrapper';
|
||||
|
||||
type UserConfig = 'UserConfig'; // we can only have one of those wrapper for our current user (but we can have a few configs for it to be merged into one)
|
||||
type ClosedGroupConfigPrefix = 'ClosedGroupConfig-03'; // we can have a bunch of those wrapper as we need to be able to send them to a different swarm for each group
|
||||
type ClosedGroupConfig = `${ClosedGroupConfigPrefix}${string}`;
|
||||
type ContactsConfig = 'ContactsConfig';
|
||||
|
||||
export type ConfigWrapperObjectTypes = UserConfig | ClosedGroupConfig;
|
||||
// type ClosedGroupConfigPrefix = 'ClosedGroupConfig-03'; // we can have a bunch of those wrapper as we need to be able to send them to a different swarm for each group
|
||||
// type ClosedGroupConfig = `${ClosedGroupConfigPrefix}${string}`;
|
||||
// | ClosedGroupConfig;
|
||||
export type ConfigWrapperObjectTypes = UserConfig | ContactsConfig;
|
||||
|
||||
|
||||
/**Those are the actions inherited from BaseConfigWrapper to UserConfigWrapper */
|
||||
type UserConfigInheritedActions = [UserConfig, ...BaseConfigActions];
|
||||
type UserConfigActions = [UserConfig,...UserConfigActionsType] | [UserConfig, 'init'];
|
||||
type UserConfigFunctions =
|
||||
| [UserConfig, ...BaseConfigActions]
|
||||
| [UserConfig, ...UserConfigActionsType];
|
||||
type ContactsConfigFunctions =
|
||||
| [ContactsConfig, ...BaseConfigActions]
|
||||
| [ContactsConfig, ...ContactsConfigActionsType];
|
||||
|
||||
/**Those are the actions inherited from BaseConfigWrapper to ClosedGroupConfigWrapper */
|
||||
type ClosedGroupConfigFromBase = [ClosedGroupConfig, ...BaseConfigActions];
|
||||
|
||||
|
||||
type UserConfigFunctions = UserConfigInheritedActions | UserConfigActions;
|
||||
type ClosedGroupConfigFunctions = ClosedGroupConfigFromBase;
|
||||
// type ClosedGroupConfigFromBase = [ClosedGroupConfig, ...BaseConfigActions];
|
||||
// type ClosedGroupConfigFunctions = ClosedGroupConfigFromBase;
|
||||
//| ClosedGroupConfigFunctions;
|
||||
|
||||
export type LibSessionWorkerFunctions = UserConfigFunctions | ClosedGroupConfigFunctions;
|
||||
export type LibSessionWorkerFunctions = UserConfigFunctions | ContactsConfigFunctions;
|
||||
|
Loading…
Reference in New Issue