fix: remove the whole kind logic and use namespace instead
this is because session doesn't care about the config it receives anymore and just forwards them to libsessionpull/2873/head
parent
0ef2df801e
commit
d9300e67a0
@ -1,64 +0,0 @@
|
|||||||
import { compact, toNumber } from 'lodash';
|
|
||||||
import { RetrieveMessageItem } from '../types';
|
|
||||||
import { extractWebSocketContent } from '../swarmPolling';
|
|
||||||
import { SignalService } from '../../../../protobuf';
|
|
||||||
import { IncomingMessage } from '../../../messages/incoming/IncomingMessage';
|
|
||||||
import { EnvelopePlus } from '../../../../receiver/types';
|
|
||||||
|
|
||||||
function extractWebSocketContents(configMsgs: Array<RetrieveMessageItem>) {
|
|
||||||
try {
|
|
||||||
return compact(
|
|
||||||
configMsgs.map((m: RetrieveMessageItem) => {
|
|
||||||
return extractWebSocketContent(m.data, m.hash);
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
window.log.warn('extractWebSocketContents failed with ', e.message);
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function decryptSharedConfigMessages(
|
|
||||||
extractedMsgs: ReturnType<typeof extractWebSocketContents>,
|
|
||||||
decryptEnvelope: (envelope: EnvelopePlus) => Promise<ArrayBuffer | null>
|
|
||||||
) {
|
|
||||||
const allDecryptedConfigMessages: Array<IncomingMessage<SignalService.ISharedConfigMessage>> = [];
|
|
||||||
|
|
||||||
for (let index = 0; index < extractedMsgs.length; index++) {
|
|
||||||
const groupConfigMessage = extractedMsgs[index];
|
|
||||||
|
|
||||||
try {
|
|
||||||
const envelope: EnvelopePlus = SignalService.Envelope.decode(groupConfigMessage.body) as any;
|
|
||||||
// eslint-disable-next-line no-await-in-loop
|
|
||||||
const decryptedEnvelope = await decryptEnvelope(envelope);
|
|
||||||
if (!decryptedEnvelope?.byteLength) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const content = SignalService.Content.decode(new Uint8Array(decryptedEnvelope));
|
|
||||||
if (content.sharedConfigMessage) {
|
|
||||||
const asIncomingMsg: IncomingMessage<SignalService.ISharedConfigMessage> = {
|
|
||||||
envelopeTimestamp: toNumber(envelope.timestamp),
|
|
||||||
message: content.sharedConfigMessage,
|
|
||||||
messageHash: groupConfigMessage.messageHash,
|
|
||||||
authorOrGroupPubkey: envelope.source,
|
|
||||||
authorInGroup: envelope.senderIdentity,
|
|
||||||
};
|
|
||||||
allDecryptedConfigMessages.push(asIncomingMsg);
|
|
||||||
} else {
|
|
||||||
throw new Error(
|
|
||||||
'received a message to a namespace reserved for user config but not containign a sharedConfigMessage'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
window.log.warn(
|
|
||||||
`failed to decrypt message with hash "${groupConfigMessage.messageHash}": ${e.message}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return allDecryptedConfigMessages;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SwarmPollingConfigShared = {
|
|
||||||
decryptSharedConfigMessages,
|
|
||||||
extractWebSocketContents,
|
|
||||||
};
|
|
@ -1,59 +0,0 @@
|
|||||||
// this is not a very good name, but a configuration message is a message sent to our other devices so sync our current public and closed groups
|
|
||||||
import Long from 'long';
|
|
||||||
|
|
||||||
import { SignalService } from '../../../../protobuf';
|
|
||||||
import { MessageParams } from '../Message';
|
|
||||||
import { ContentMessage } from '..';
|
|
||||||
import { TTL_DEFAULT } from '../../../constants';
|
|
||||||
import { UserConfigKind } from '../../../../types/ProtobufKind';
|
|
||||||
|
|
||||||
interface SharedConfigParams<KindsPicked extends UserConfigKind> extends MessageParams {
|
|
||||||
seqno: Long;
|
|
||||||
data: Uint8Array;
|
|
||||||
kind: KindsPicked;
|
|
||||||
}
|
|
||||||
|
|
||||||
export abstract class SharedConfigMessage<
|
|
||||||
KindsPicked extends UserConfigKind,
|
|
||||||
> extends ContentMessage {
|
|
||||||
public readonly seqno: Long;
|
|
||||||
public readonly kind: KindsPicked;
|
|
||||||
public readonly data: Uint8Array;
|
|
||||||
|
|
||||||
constructor(params: SharedConfigParams<KindsPicked>) {
|
|
||||||
super({ timestamp: params.timestamp, identifier: params.identifier });
|
|
||||||
this.data = params.data;
|
|
||||||
this.kind = params.kind;
|
|
||||||
this.seqno = params.seqno;
|
|
||||||
}
|
|
||||||
|
|
||||||
public contentProto(): SignalService.Content {
|
|
||||||
return new SignalService.Content({
|
|
||||||
sharedConfigMessage: this.sharedConfigProto(),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public ttl(): number {
|
|
||||||
return TTL_DEFAULT.TTL_CONFIG;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected sharedConfigProto(): SignalService.SharedConfigMessage {
|
|
||||||
return new SignalService.SharedConfigMessage({
|
|
||||||
data: this.data,
|
|
||||||
kind: this.kind,
|
|
||||||
seqno: this.seqno,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export class SharedUserConfigMessage extends SharedConfigMessage<UserConfigKind> {
|
|
||||||
constructor(params: SharedConfigParams<UserConfigKind>) {
|
|
||||||
super({
|
|
||||||
timestamp: params.timestamp,
|
|
||||||
identifier: params.identifier,
|
|
||||||
data: params.data,
|
|
||||||
kind: params.kind,
|
|
||||||
seqno: params.seqno,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,20 +0,0 @@
|
|||||||
import { SignalService } from '../protobuf';
|
|
||||||
import { PickEnum } from './Enums';
|
|
||||||
|
|
||||||
export type UserConfigKind = PickEnum<
|
|
||||||
SignalService.SharedConfigMessage.Kind,
|
|
||||||
| SignalService.SharedConfigMessage.Kind.USER_PROFILE
|
|
||||||
| SignalService.SharedConfigMessage.Kind.CONTACTS
|
|
||||||
| SignalService.SharedConfigMessage.Kind.USER_GROUPS
|
|
||||||
| SignalService.SharedConfigMessage.Kind.CONVO_INFO_VOLATILE
|
|
||||||
>;
|
|
||||||
|
|
||||||
export function isUserKind(kind: SignalService.SharedConfigMessage.Kind): kind is UserConfigKind {
|
|
||||||
const Kind = SignalService.SharedConfigMessage.Kind;
|
|
||||||
return (
|
|
||||||
kind === Kind.USER_PROFILE ||
|
|
||||||
kind === Kind.CONTACTS ||
|
|
||||||
kind === Kind.USER_GROUPS ||
|
|
||||||
kind === Kind.CONVO_INFO_VOLATILE
|
|
||||||
);
|
|
||||||
}
|
|
Loading…
Reference in New Issue