chore: moved outgoing message wrapper functions to MessagWrapper.ts

pull/3052/head
Audric Ackermann 11 months ago
parent cd122c7252
commit 816f29d682

@ -1130,8 +1130,6 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk: this.id,
revokeSubRequest: null,
unrevokeSubRequest: null,
deleteAllMessagesSubRequest: null,
supplementalKeysSubRequest: [],
extraStoreRequests,

@ -4,7 +4,7 @@ import { SignalService } from '../../../../protobuf';
import { MetaGroupWrapperActions } from '../../../../webworker/workers/browser/libsession_worker_interface';
import { GroupUpdateInfoChangeMessage } from '../../../messages/outgoing/controlMessage/group_v2/to_group/GroupUpdateInfoChangeMessage';
import { GroupUpdateMemberChangeMessage } from '../../../messages/outgoing/controlMessage/group_v2/to_group/GroupUpdateMemberChangeMessage';
import { MessageSender } from '../../../sending';
import { MessageWrapper } from '../../../sending/MessageWrapper';
import { ed25519Str } from '../../../utils/String';
import { PendingChangesForGroup } from '../../../utils/libsession/libsession_utils';
import {
@ -35,7 +35,7 @@ async function makeGroupMessageSubRequest(
}
const messagesToEncrypt: Array<StoreGroupExtraData> = compactedMessages.map(updateMessage => {
const wrapped = MessageSender.wrapContentIntoEnvelope(
const wrapped = MessageWrapper.wrapContentIntoEnvelope(
SignalService.Envelope.Type.SESSION_MESSAGE,
undefined,
updateMessage.createAtNetworkTimestamp, // message is signed with this timestmap

@ -28,7 +28,7 @@ async function getRevokeSubaccountParams(
timestamp: GetNetworkTime.now(),
secretKey,
})
: null;
: undefined;
const unrevokeSubRequest = unrevokeChanges.length
? new SubaccountUnrevokeSubRequest({
groupPk,
@ -36,7 +36,7 @@ async function getRevokeSubaccountParams(
timestamp: GetNetworkTime.now(),
secretKey,
})
: null;
: undefined;
return {
revokeSubRequest,

@ -37,8 +37,8 @@ export type ShortenOrExtend = 'extend' | 'shorten' | '';
export type WithShortenOrExtend = { shortenOrExtend: ShortenOrExtend };
export type WithRevokeSubRequest = {
revokeSubRequest: SubaccountRevokeSubRequest | null;
unrevokeSubRequest: SubaccountUnrevokeSubRequest | null;
revokeSubRequest?: SubaccountRevokeSubRequest;
unrevokeSubRequest?: SubaccountUnrevokeSubRequest;
};
export type SignedHashesParams = WithSignature & {

@ -327,8 +327,6 @@ class ConvoController {
await MetaGroupWrapperActions.infoDestroy(groupPk);
const lastPushResult = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
deleteAllMessagesSubRequest,
extraStoreRequests: [],

@ -70,6 +70,7 @@ import { OutgoingRawMessage } from '../types/RawMessage';
import { UserUtils } from '../utils';
import { ed25519Str, fromUInt8ArrayToBase64 } from '../utils/String';
import { MessageSentHandler } from './MessageSentHandler';
import { MessageWrapper } from './MessageWrapper';
// ================ SNODE STORE ================
@ -546,7 +547,7 @@ async function encryptForGroupV2(
networkTimestamp,
} = params;
const envelope = wrapContentIntoEnvelope(
const envelope = MessageWrapper.wrapContentIntoEnvelope(
SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE,
destination,
networkTimestamp,
@ -599,13 +600,13 @@ async function encryptMessageAndWrap(
encryptionBasedOnConversation(recipient)
);
const envelope = wrapContentIntoEnvelope(
const envelope = MessageWrapper.wrapContentIntoEnvelope(
envelopeType,
recipient.key,
networkTimestamp,
cipherText
);
const data = wrapEnvelopeInWebSocketMessage(envelope);
const data = MessageWrapper.wrapEnvelopeInWebSocketMessage(envelope);
return {
encryptedAndWrappedData: data,
@ -736,51 +737,10 @@ async function sendUnencryptedDataToSnode<T extends GroupPubkeyType | PubkeyType
return sendEncryptedDataToSnode({
destination,
deleteHashesSubRequest: null,
revokeSubRequest: null,
unrevokeSubRequest: null,
storeRequests,
});
}
function wrapContentIntoEnvelope(
type: SignalService.Envelope.Type,
sskSource: string | undefined,
timestamp: number,
content: Uint8Array
): SignalService.Envelope {
let source: string | undefined;
if (type === SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE) {
source = sskSource;
}
return SignalService.Envelope.create({
type,
source,
timestamp,
content,
});
}
/**
* This is an outdated practice and we should probably just send the envelope data directly.
* Something to think about in the future.
*/
function wrapEnvelopeInWebSocketMessage(envelope: SignalService.Envelope): Uint8Array {
const request = SignalService.WebSocketRequestMessage.create({
id: 0,
body: SignalService.Envelope.encode(envelope).finish(),
verb: 'PUT',
path: '/api/v1/message',
});
const websocket = SignalService.WebSocketMessage.create({
type: SignalService.WebSocketMessage.Type.REQUEST,
request,
});
return SignalService.WebSocketMessage.encode(websocket).finish();
}
// ================ Open Group ================
/**
* Send a message to an open group v2.
@ -843,7 +803,6 @@ export const MessageSender = {
sendToOpenGroupV2,
sendSingleMessage,
isContentSyncMessage,
wrapContentIntoEnvelope,
getSignatureParamsFromNamespace,
signSubRequests,
encryptMessagesAndWrap,

@ -0,0 +1,41 @@
import { SignalService } from '../../protobuf';
function wrapContentIntoEnvelope(
type: SignalService.Envelope.Type,
sskSource: string | undefined,
timestamp: number,
content: Uint8Array
): SignalService.Envelope {
let source: string | undefined;
if (type === SignalService.Envelope.Type.CLOSED_GROUP_MESSAGE) {
source = sskSource;
}
return SignalService.Envelope.create({
type,
source,
timestamp,
content,
});
}
/**
* This is an outdated practice and we should probably just send the envelope data directly.
* Something to think about in the future.
*/
function wrapEnvelopeInWebSocketMessage(envelope: SignalService.Envelope): Uint8Array {
const request = SignalService.WebSocketRequestMessage.create({
id: 0,
body: SignalService.Envelope.encode(envelope).finish(),
verb: 'PUT',
path: '/api/v1/message',
});
const websocket = SignalService.WebSocketMessage.create({
type: SignalService.WebSocketMessage.Type.REQUEST,
request,
});
return SignalService.WebSocketMessage.encode(websocket).finish();
}
export const MessageWrapper = { wrapEnvelopeInWebSocketMessage, wrapContentIntoEnvelope };

@ -219,8 +219,6 @@ class GroupSyncJob extends PersistedJob<GroupSyncPersistedData> {
// return await so we catch exceptions in here
return await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk: thisJobDestination,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
extraStoreRequests: [],
});

@ -119,8 +119,6 @@ async function pushChangesToUserSwarmIfNeeded() {
storeRequests,
destination: us,
deleteHashesSubRequest,
revokeSubRequest: null,
unrevokeSubRequest: null,
});
const expectedReplyLength =

@ -209,8 +209,6 @@ const initNewGroupInWrapper = createAsyncThunk(
const result = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
deleteAllMessagesSubRequest: null,
extraStoreRequests,
@ -836,8 +834,6 @@ async function handleMemberRemovedFromUI({
const sequenceResult = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
supplementalKeysSubRequest: [],
revokeSubRequest: null,
unrevokeSubRequest: null,
deleteAllMessagesSubRequest: null,
extraStoreRequests,
});
@ -918,8 +914,6 @@ async function handleNameChangeFromUI({
const batchResult = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
supplementalKeysSubRequest: [],
revokeSubRequest: null,
unrevokeSubRequest: null,
deleteAllMessagesSubRequest: null,
extraStoreRequests,
});
@ -1041,8 +1035,6 @@ const triggerFakeAvatarUpdate = createAsyncThunk(
const batchResult = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
supplementalKeysSubRequest: [],
revokeSubRequest: null,
unrevokeSubRequest: null,
deleteAllMessagesSubRequest: null,
extraStoreRequests,
});

@ -275,8 +275,6 @@ describe('GroupSyncJob pushChangesToGroupSwarmIfNeeded', () => {
const result = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
extraStoreRequests: [],
});
@ -301,8 +299,6 @@ describe('GroupSyncJob pushChangesToGroupSwarmIfNeeded', () => {
});
const result = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
extraStoreRequests: [],
});
@ -335,8 +331,6 @@ describe('GroupSyncJob pushChangesToGroupSwarmIfNeeded', () => {
storeRequests: [expectedInfo, expectedMember],
destination: groupPk,
messagesHashesToDelete: new Set('123'),
unrevokeSubRequest: null,
revokeSubRequest: null,
};
expect(callArgs).to.be.deep.eq(expectedArgs);
});
@ -376,8 +370,6 @@ describe('GroupSyncJob pushChangesToGroupSwarmIfNeeded', () => {
]);
const result = await GroupSync.pushChangesToGroupSwarmIfNeeded({
groupPk,
revokeSubRequest: null,
unrevokeSubRequest: null,
supplementalKeysSubRequest: [],
extraStoreRequests: [],
});

@ -315,8 +315,6 @@ describe('UserSyncJob pushChangesToUserSwarmIfNeeded', () => {
storeRequests: [expectedProfile, expectedContact],
destination: sessionId,
messagesHashesToDelete: new Set('123'),
unrevokeSubRequest: null,
revokeSubRequest: null,
};
// callArgs.storeRequests = callArgs.storeRequests.map(_m => null) as any;
expect(callArgs).to.be.deep.eq(expectedArgs);

Loading…
Cancel
Save