chore: rename all groupv3 to groupv2

pull/2873/head
Audric Ackermann 2 years ago
parent 84451399e3
commit b0e38670ab

@ -22,7 +22,7 @@ import { SignalService } from '../protobuf';
import { getMessageQueue } from '../session';
import { ConvoHub } from '../session/conversations';
import {
ClosedGroupV3VisibleMessage,
ClosedGroupV2VisibleMessage,
ClosedGroupVisibleMessage,
} from '../session/messages/outgoing/visibleMessage/ClosedGroupVisibleMessage';
import { PubKey } from '../session/types';
@ -112,6 +112,7 @@ import {
READ_MESSAGE_STATE,
} from './conversationAttributes';
import { PreConditionFailed } from '../session/utils/errors';
import { LibSessionUtil } from '../session/utils/libsession/libsession_utils';
import { SessionUtilUserProfile } from '../session/utils/libsession/libsession_utils_user_profile';
import { ReduxSogsRoomInfos } from '../state/ducks/sogsRoomInfo';
@ -126,7 +127,6 @@ import {
getSubscriberCountOutsideRedux,
} from '../state/selectors/sogsRoomInfo';
import { markAttributesAsReadIfNeeded } from './messageFactory';
import { PreConditionFailed } from '../session/utils/errors';
type InMemoryConvoInfos = {
mentionedUs: boolean;
@ -186,7 +186,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
switch (type) {
case ConversationTypeEnum.PRIVATE:
return this.id;
case ConversationTypeEnum.GROUPV3:
case ConversationTypeEnum.GROUPV2:
return `group(${ed25519Str(this.id)})`;
case ConversationTypeEnum.GROUP: {
if (this.isPublic()) {
@ -225,13 +225,13 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public isClosedGroup(): boolean {
return Boolean(
(this.get('type') === ConversationTypeEnum.GROUP && this.id.startsWith('05')) ||
this.isClosedGroupV3()
this.isClosedGroupV2()
);
}
public isClosedGroupV3(): boolean {
public isClosedGroupV2(): boolean {
return Boolean(
this.get('type') === ConversationTypeEnum.GROUPV3 && PubKey.isClosedGroupV2(this.id)
this.get('type') === ConversationTypeEnum.GROUPV2 && PubKey.isClosedGroupV2(this.id)
);
}
@ -1728,7 +1728,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public isKickedFromGroup(): boolean {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
if (this.isClosedGroupV2()) {
// console.info('isKickedFromGroup using lib todo'); // debugger
}
return !!this.get('isKickedFromGroup');
@ -1738,7 +1738,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public isLeft(): boolean {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
if (this.isClosedGroupV2()) {
// console.info('isLeft using lib todo'); // debugger
}
return !!this.get('left');
@ -1759,7 +1759,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public getGroupMembers(): Array<string> {
if (this.isClosedGroup()) {
if (this.isClosedGroupV3()) {
if (this.isClosedGroupV2()) {
return getLibGroupMembersOutsideRedux(this.id);
}
const members = this.get('members');
@ -1771,7 +1771,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
public getGroupZombies(): Array<string> {
if (this.isClosedGroup()) {
// closed group with 03 prefix does not have the concepts of zombies
if (this.isClosedGroupV3()) {
if (this.isClosedGroupV2()) {
return [];
}
const zombies = this.get('zombies');
@ -1891,9 +1891,9 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
return;
}
if (this.isClosedGroupV3()) {
if (this.isClosedGroupV2()) {
// we need the return await so that errors are caught in the catch {}
await this.sendMessageToGroupV3(chatMessageParams);
await this.sendMessageToGroupV2(chatMessageParams);
return;
}
@ -1918,16 +1918,16 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
}
}
private async sendMessageToGroupV3(chatMessageParams: VisibleMessageParams) {
private async sendMessageToGroupV2(chatMessageParams: VisibleMessageParams) {
const visibleMessage = new VisibleMessage(chatMessageParams);
const groupVisibleMessage = new ClosedGroupV3VisibleMessage({
const groupVisibleMessage = new ClosedGroupV2VisibleMessage({
chatMessage: visibleMessage,
destination: this.id,
namespace: SnodeNamespaces.ClosedGroupMessages,
});
// we need the return await so that errors are caught in the catch {}
await getMessageQueue().sendToGroupV3({
await getMessageQueue().sendToGroupV2({
message: groupVisibleMessage,
});
}

@ -13,14 +13,14 @@ import { LastMessageStatusType } from '../state/ducks/conversations';
*/
export enum ConversationTypeEnum {
GROUP = 'group',
GROUPV3 = 'groupv3',
GROUPV2 = 'groupv2',
PRIVATE = 'private',
}
export function isOpenOrClosedGroup(conversationType: ConversationTypeEnum) {
return (
conversationType === ConversationTypeEnum.GROUP ||
conversationType === ConversationTypeEnum.GROUPV3
conversationType === ConversationTypeEnum.GROUPV2
);
}
@ -50,7 +50,7 @@ export type ConversationAttributesWithNotSavedOnes = ConversationAttributes &
export interface ConversationAttributes {
id: string;
type: ConversationTypeEnum.PRIVATE | ConversationTypeEnum.GROUPV3 | ConversationTypeEnum.GROUP;
type: ConversationTypeEnum.PRIVATE | ConversationTypeEnum.GROUPV2 | ConversationTypeEnum.GROUP;
// 0 means inactive (undefined and null too but we try to get rid of them and only have 0 = inactive)
active_at: number; // this field is the one used to sort conversations in the left pane from most recent

@ -638,7 +638,7 @@ async function handleSingleGroupUpdate({
}
if (!ConvoHub.use().get(groupPk)) {
const created = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV3);
const created = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV2);
const joinedAt = groupInWrapper.joinedAtSeconds * 1000 || Date.now();
created.set({
active_at: joinedAt,

@ -195,10 +195,10 @@ export async function handleSwarmDataMessage(
);
const isGroupMessage = !!envelope.senderIdentity;
const isGroupV3Message = isGroupMessage && PubKey.isClosedGroupV2(envelope.source);
const isGroupV2Message = isGroupMessage && PubKey.isClosedGroupV2(envelope.source);
let typeOfConvo = ConversationTypeEnum.PRIVATE;
if (isGroupV3Message) {
typeOfConvo = ConversationTypeEnum.GROUPV3;
if (isGroupV2Message) {
typeOfConvo = ConversationTypeEnum.GROUPV2;
} else if (isGroupMessage) {
typeOfConvo = ConversationTypeEnum.GROUP;
}

@ -18,7 +18,7 @@ export const uploadFileToRoomSogs3 = async (
const roomDetails = OpenGroupData.getV2OpenGroupRoomByRoomId(roomInfos);
if (!roomDetails || !roomDetails.serverPublicKey) {
window.log.warn('uploadFileOpenGroupV3: roomDetails is invalid');
window.log.warn('uploadFileOpenGroup: roomDetails is invalid');
return null;
}

@ -5,4 +5,4 @@ import { ConversationTypeEnum } from '../../../models/conversationAttributes';
export type PollForUs = [pubkey: string, type: ConversationTypeEnum.PRIVATE];
export type PollForLegacy = [pubkey: string, type: ConversationTypeEnum.GROUP];
export type PollForGroup = [pubkey: GroupPubkeyType, type: ConversationTypeEnum.GROUPV3];
export type PollForGroup = [pubkey: GroupPubkeyType, type: ConversationTypeEnum.GROUPV2];

@ -219,7 +219,7 @@ export class SwarmPolling {
.filter(m => this.shouldPollByTimeout(m)) // should we poll from it depending on this group activity?
.filter(m => allGroupsInWrapper.some(w => w.pubkeyHex === m.pubkey.key)) // we don't poll from groups which are not in the usergroup wrapper
.map(m => m.pubkey.key as GroupPubkeyType) // extract the pubkey
.map(m => [m, ConversationTypeEnum.GROUPV3] as PollForGroup);
.map(m => [m, ConversationTypeEnum.GROUPV2] as PollForGroup);
toPollDetails = concat(toPollDetails, allGroupsTracked);
@ -267,7 +267,7 @@ export class SwarmPolling {
pubkey: string;
}) {
// if all snodes returned an error (null), no need to update the lastPolledTimestamp
if (type === ConversationTypeEnum.GROUP || type === ConversationTypeEnum.GROUPV3) {
if (type === ConversationTypeEnum.GROUP || type === ConversationTypeEnum.GROUPV2) {
window?.log?.debug(
`Polled for group(${ed25519Str(pubkey)}):, got ${countMessages} messages back.`
);
@ -302,7 +302,7 @@ export class SwarmPolling {
await SwarmPollingUserConfig.handleUserSharedConfigMessages(confMessages);
return;
}
if (type === ConversationTypeEnum.GROUPV3 && PubKey.isClosedGroupV2(pubkey)) {
if (type === ConversationTypeEnum.GROUPV2 && PubKey.isClosedGroupV2(pubkey)) {
await SwarmPollingGroupConfig.handleGroupSharedConfigMessages(confMessages, pubkey);
}
}
@ -370,7 +370,7 @@ export class SwarmPolling {
perfStart(`handleSeenMessages-${pubkey}`);
const newMessages = await this.handleSeenMessages(uniqOtherMsgs);
perfEnd(`handleSeenMessages-${pubkey}`, 'handleSeenMessages');
if (type === ConversationTypeEnum.GROUPV3) {
if (type === ConversationTypeEnum.GROUPV2) {
for (let index = 0; index < newMessages.length; index++) {
const msg = newMessages[index];
const retrieveResult = new Uint8Array(StringUtils.encode(msg.data, 'base64'));
@ -454,7 +454,7 @@ export class SwarmPolling {
window.log.debug(`configHashesToBump private: ${configHashesToBump}`);
return configHashesToBump;
}
if (type === ConversationTypeEnum.GROUPV3 && PubKey.isClosedGroupV2(pubkey)) {
if (type === ConversationTypeEnum.GROUPV2 && PubKey.isClosedGroupV2(pubkey)) {
const toBump = await MetaGroupWrapperActions.currentHashes(pubkey);
window.log.debug(`configHashesToBump group: ${toBump}`);
return toBump;
@ -606,7 +606,7 @@ export class SwarmPolling {
if (type === ConversationTypeEnum.GROUP) {
return [SnodeNamespaces.LegacyClosedGroup];
}
if (type === ConversationTypeEnum.GROUPV3) {
if (type === ConversationTypeEnum.GROUPV2) {
return [
SnodeNamespaces.ClosedGroupMessages,
SnodeNamespaces.ClosedGroupInfo,
@ -712,7 +712,7 @@ function filterMessagesPerTypeOfConvo<T extends ConversationTypeEnum>(
otherMessages: retrieveItemWithNamespace(retrieveResults),
};
case ConversationTypeEnum.GROUPV3: {
case ConversationTypeEnum.GROUPV2: {
const groupConfs = retrieveResults.filter(m =>
SnodeNamespace.isGroupConfigNamespace(m.namespace)
);

@ -92,12 +92,12 @@ class ConvoController {
if (
type !== ConversationTypeEnum.PRIVATE &&
type !== ConversationTypeEnum.GROUP &&
type !== ConversationTypeEnum.GROUPV3
type !== ConversationTypeEnum.GROUPV2
) {
throw new TypeError(`'type' must be 'private' or 'group' or 'groupv3' but got: '${type}'`);
throw new TypeError(`'type' must be 'private' or 'group' or 'groupv2' but got: '${type}'`);
}
if (type === ConversationTypeEnum.GROUPV3 && !PubKey.isClosedGroupV2(id)) {
if (type === ConversationTypeEnum.GROUPV2 && !PubKey.isClosedGroupV2(id)) {
throw new Error(
'required v3 closed group but the pubkey does not match the 03 prefix for them'
);

@ -97,7 +97,7 @@ export async function createClosedGroup(groupName: string, members: Array<string
/**
* Sends a group invite message to each member of the group.
* @returns Array of promises for group invite messages sent to group members.
* This function takes care of the groupv3 specificities
* This function takes care of the groupv2 specificities
*/
async function sendToGroupMembers(
listOfMembers: Array<string>,

@ -1,7 +1,6 @@
import _, { isFinite, isNumber } from 'lodash';
import { v4 as uuidv4 } from 'uuid';
import { PubKey } from '../types';
import { getMessageQueue } from '..';
import { Data } from '../../data/data';
import { ConversationModel } from '../../models/conversation';
@ -23,6 +22,7 @@ import { ClosedGroupEncryptionPairMessage } from '../messages/outgoing/controlMe
import { ClosedGroupNameChangeMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupNameChangeMessage';
import { ClosedGroupNewMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupNewMessage';
import { ClosedGroupRemovedMembersMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupRemovedMembersMessage';
import { PubKey } from '../types';
import { UserUtils } from '../utils';
import { fromHexToArray, toHex } from '../utils/String';
@ -60,10 +60,10 @@ export async function initiateClosedGroupUpdate(
groupName: string,
members: Array<string>
) {
const isGroupV3 = PubKey.isClosedGroupV2(groupId);
const isGroupV2 = PubKey.isClosedGroupV2(groupId);
const convo = await ConvoHub.use().getOrCreateAndWait(
groupId,
isGroupV3 ? ConversationTypeEnum.GROUPV3 : ConversationTypeEnum.GROUP
isGroupV2 ? ConversationTypeEnum.GROUPV2 : ConversationTypeEnum.GROUP
);
// do not give an admins field here. We don't want to be able to update admins and
@ -210,7 +210,7 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) {
const conversation = await ConvoHub.use().getOrCreateAndWait(
id,
isV3 ? ConversationTypeEnum.GROUPV3 : ConversationTypeEnum.GROUP
isV3 ? ConversationTypeEnum.GROUPV2 : ConversationTypeEnum.GROUP
);
const updates: Pick<
@ -219,7 +219,7 @@ export async function updateOrCreateClosedGroup(details: GroupInfo) {
> = {
displayNameInProfile: details.name,
members: details.members,
type: isV3 ? ConversationTypeEnum.GROUPV3 : ConversationTypeEnum.GROUP,
type: isV3 ? ConversationTypeEnum.GROUPV2 : ConversationTypeEnum.GROUP,
active_at: details.activeAt ? details.activeAt : 0,
left: !details.activeAt,
};

@ -1,11 +1,11 @@
import { GroupPubkeyType } from 'libsession_util_nodejs';
import { SignalService } from '../../../../protobuf';
import { SnodeNamespaces } from '../../../apis/snode_api/namespaces';
import { PubKey } from '../../../types';
import { StringUtils } from '../../../utils';
import { VisibleMessage } from './VisibleMessage';
import { ClosedGroupMessage } from '../controlMessage/group/ClosedGroupMessage';
import { DataMessage } from '../DataMessage';
import { SnodeNamespaces } from '../../../apis/snode_api/namespaces';
import { ClosedGroupMessage } from '../controlMessage/group/ClosedGroupMessage';
import { VisibleMessage } from './VisibleMessage';
interface ClosedGroupVisibleMessageParams {
identifier?: string;
@ -52,7 +52,7 @@ export class ClosedGroupVisibleMessage extends ClosedGroupMessage {
type WithDestinationGroupPk = { destination: GroupPubkeyType };
type WithGroupMessageNamespace = { namespace: SnodeNamespaces.ClosedGroupMessages };
export class ClosedGroupV3VisibleMessage extends DataMessage {
export class ClosedGroupV2VisibleMessage extends DataMessage {
private readonly chatMessage: VisibleMessage;
public readonly destination: GroupPubkeyType;
public readonly namespace: SnodeNamespaces.ClosedGroupMessages;
@ -69,7 +69,7 @@ export class ClosedGroupV3VisibleMessage extends DataMessage {
this.chatMessage = params.chatMessage;
if (!PubKey.isClosedGroupV2(params.destination)) {
throw new Error('ClosedGroupV3VisibleMessage only work with 03-groups destination');
throw new Error('ClosedGroupV2VisibleMessage only work with 03-groups destination');
}
this.destination = params.destination;
this.namespace = params.namespace;

@ -15,10 +15,7 @@ import { ClosedGroupEncryptionPairMessage } from '../messages/outgoing/controlMe
import { ClosedGroupMemberLeftMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupMemberLeftMessage';
import { ClosedGroupNewMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupNewMessage';
import { ClosedGroupRemovedMembersMessage } from '../messages/outgoing/controlMessage/group/ClosedGroupRemovedMembersMessage';
import {
ClosedGroupV3VisibleMessage,
ClosedGroupVisibleMessage,
} from '../messages/outgoing/visibleMessage/ClosedGroupVisibleMessage';
import { ClosedGroupVisibleMessage } from '../messages/outgoing/visibleMessage/ClosedGroupVisibleMessage';
import { SyncMessageType } from '../utils/sync/syncUtils';
import { MessageSentHandler } from './MessageSentHandler';
@ -198,15 +195,15 @@ export class MessageQueue {
return this.sendToPubKey(PubKey.cast(destinationPubKey), message, namespace, sentCb, true);
}
public async sendToGroupV3({
public async sendToGroupV2({
message,
sentCb,
}: {
message: ClosedGroupV3VisibleMessage;
message: ClosedGroupV2VisibleMessage;
sentCb?: (message: RawMessage) => Promise<void>;
}): Promise<void> {
if (!message.destination) {
throw new Error('Invalid group message passed in sendToGroupV3.');
throw new Error('Invalid group message passed in sendToGroupV2.');
}
return this.sendToPubKey(

@ -23,7 +23,7 @@ export enum KeyPrefixType {
/**
* used for participants in open groups
*/
groupV3 = '03',
groupV2 = '03',
}
// TODO make that Pubkey class more useful, add fields for what types of pubkey it is (group, legacy group, private)
@ -41,7 +41,7 @@ export class PubKey {
public static readonly PREFIX_GROUP_TEXTSECURE = '__textsecure_group__!';
// prettier-ignore
private static readonly regex: RegExp = new RegExp(
`^(${PubKey.PREFIX_GROUP_TEXTSECURE})?(${KeyPrefixType.standard}|${KeyPrefixType.blinded15}|${KeyPrefixType.blinded25}|${KeyPrefixType.unblinded}|${KeyPrefixType.groupV3})?(${PubKey.HEX}{64}|${PubKey.HEX}{32})$`
`^(${PubKey.PREFIX_GROUP_TEXTSECURE})?(${KeyPrefixType.standard}|${KeyPrefixType.blinded15}|${KeyPrefixType.blinded25}|${KeyPrefixType.unblinded}|${KeyPrefixType.groupV2})?(${PubKey.HEX}{64}|${PubKey.HEX}{32})$`
);
/**
* If you want to update this regex. Be sure that those are matches ;
@ -236,7 +236,7 @@ export class PubKey {
}
public static isClosedGroupV2(key: string): key is GroupPubkeyType {
const regex = new RegExp(`^${KeyPrefixType.groupV3}${PubKey.HEX}{64}$`);
const regex = new RegExp(`^${KeyPrefixType.groupV2}${PubKey.HEX}{64}$`);
return regex.test(key);
}
}

@ -47,7 +47,7 @@ async function uploadV3(params: UploadParamsV2): Promise<AttachmentPointerWithUr
const fileDetails = await uploadFileToRoomSogs3(new Uint8Array(paddedAttachment), openGroup);
if (!fileDetails) {
throw new Error(`upload to fileopengroupv3 of ${attachment.fileName} failed`);
throw new Error(`upload to fileopengroup of ${attachment.fileName} failed`);
}
return {

@ -118,7 +118,7 @@ const initNewGroupInWrapper = createAsyncThunk(
);
}
const convo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV3);
const convo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV2);
await convo.setIsApproved(true, false);
@ -185,7 +185,7 @@ const handleUserGroupUpdate = createAsyncThunk(
window.log.warn(`failed to init metawrapper ${groupPk}`);
}
const convo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV3);
const convo = await ConvoHub.use().getOrCreateAndWait(groupPk, ConversationTypeEnum.GROUPV2);
await convo.setIsApproved(true, false);

@ -4,9 +4,9 @@ import { ConversationTypeEnum, isOpenOrClosedGroup } from '../../models/conversa
import { PubKey } from '../../session/types';
import { UserUtils } from '../../session/utils';
import { StateType } from '../reducer';
import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo';
import { getIsMessageSelectionMode, getSelectedConversation } from './conversations';
import { getLibMembersPubkeys, useLibGroupName } from './groups';
import { getCanWrite, getModerators, getSubscriberCount } from './sogsRoomInfo';
/**
* Returns the formatted text for notification setting.
@ -134,7 +134,7 @@ export const isClosedGroupConversation = (state: StateType): boolean => {
}
return (
(selected.type === ConversationTypeEnum.GROUP && !selected.isPublic) ||
selected.type === ConversationTypeEnum.GROUPV3 ||
selected.type === ConversationTypeEnum.GROUPV2 ||
false
);
};

@ -19,7 +19,7 @@ describe('LibSessionUtil saveDumpsToDb', () => {
let groupPk: GroupPubkeyType;
beforeEach(() => {
groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
});
afterEach(() => {
@ -132,7 +132,7 @@ describe('LibSessionUtil saveDumpsToDb', () => {
describe('LibSessionUtil pendingChangesForGroup', () => {
let groupPk: GroupPubkeyType;
beforeEach(() => {
groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
});
afterEach(() => {

@ -108,7 +108,7 @@ describe('libsession_groups', () => {
SessionUtilUserGroups.isUserGroupToStoreInWrapper(
new ConversationModel({
...validArgs,
type: ConversationTypeEnum.GROUPV3,
type: ConversationTypeEnum.GROUPV2,
id: '03123456564',
} as any)
)

@ -272,7 +272,7 @@ describe('formatRowOfConversation', () => {
formatRowOfConversation(
fillConvoAttributesWithDefaults({
id: '1234565',
type: ConversationTypeEnum.GROUPV3,
type: ConversationTypeEnum.GROUPV2,
nickname: 'nickname',
displayNameInProfile: 'displayNameInProfile',
profileKey: '',

@ -22,8 +22,8 @@ import {
import { ConvoHub } from '../../../../session/conversations';
import { LibSodiumWrappers } from '../../../../session/crypto';
import { UserUtils } from '../../../../session/utils';
import { expectAsyncToThrow, stubData, stubWindowLog } from '../../../test-utils/utils';
import { TestUtils } from '../../../test-utils';
import { expectAsyncToThrow, stubData, stubWindowLog } from '../../../test-utils/utils';
const serverPublicKey = 'serverPublicKey';
const blindedId = '151111';
@ -572,8 +572,8 @@ describe('knownBlindedKeys', () => {
expect(real).to.eq(undefined);
});
it('does iterate over all the conversations but is not private so must fail: groupv3', () => {
// we actually cannot test this one as we would need to create a conversation with groupv3 as type but 05 as prefix, and the conversation controller denies it, as expected
it('does iterate over all the conversations but is not private so must fail: groupv2', () => {
// we actually cannot test this one as we would need to create a conversation with groupv2 as type but 05 as prefix, and the conversation controller denies it, as expected
});
});
});

@ -1,10 +1,10 @@
import { expect } from 'chai';
import Sinon from 'sinon';
import { ConversationTypeEnum } from '../../../../models/conversationAttributes';
import { SnodeNamespaces } from '../../../../session/apis/snode_api/namespaces';
import { TestUtils } from '../../../test-utils';
import { getSwarmPollingInstance } from '../../../../session/apis/snode_api';
import { SnodeNamespaces } from '../../../../session/apis/snode_api/namespaces';
import { SwarmPolling } from '../../../../session/apis/snode_api/swarmPolling';
import { TestUtils } from '../../../test-utils';
describe('SwarmPolling:getNamespacesToPollFrom', () => {
let swarmPolling: SwarmPolling;
@ -31,7 +31,7 @@ describe('SwarmPolling:getNamespacesToPollFrom', () => {
});
it('for group v2 (03 prefix) ', () => {
expect(swarmPolling.getNamespacesToPollFrom(ConversationTypeEnum.GROUPV3)).to.deep.equal([
expect(swarmPolling.getNamespacesToPollFrom(ConversationTypeEnum.GROUPV2)).to.deep.equal([
SnodeNamespaces.ClosedGroupMessages,
SnodeNamespaces.ClosedGroupInfo,
SnodeNamespaces.ClosedGroupMembers,

@ -1,14 +1,14 @@
import { expect } from 'chai';
import Sinon from 'sinon';
import { ConversationTypeEnum } from '../../../../models/conversationAttributes';
import { SWARM_POLLING_TIMEOUT } from '../../../../session/constants';
import { PubKey } from '../../../../session/types';
import { TestUtils } from '../../../test-utils';
import {
SwarmPolling,
getSwarmPollingInstance,
} from '../../../../session/apis/snode_api/swarmPolling';
import { SWARM_POLLING_TIMEOUT } from '../../../../session/constants';
import { ConvoHub } from '../../../../session/conversations/ConversationController';
import { PubKey } from '../../../../session/types';
import { TestUtils } from '../../../test-utils';
import { stubData } from '../../../test-utils/utils';
describe('SwarmPolling:getPollingTimeout', () => {
@ -86,11 +86,11 @@ describe('SwarmPolling:getPollingTimeout', () => {
});
});
describe('groupv3', () => {
describe('groupv2', () => {
it('returns ACTIVE for convo with less than two days old activeAt', () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV3PkStr(),
ConversationTypeEnum.GROUPV3
TestUtils.generateFakeClosedGroupV2PkStr(),
ConversationTypeEnum.GROUPV2
);
convo.set('active_at', Date.now() - 2 * 23 * 3600 * 1000); // 23 * 2 = 46 hours old
expect(swarmPolling.getPollingTimeout(PubKey.cast(convo.id as string))).to.eq(
@ -100,8 +100,8 @@ describe('SwarmPolling:getPollingTimeout', () => {
it('returns INACTIVE for convo with undefined activeAt', () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV3PkStr(),
ConversationTypeEnum.GROUPV3
TestUtils.generateFakeClosedGroupV2PkStr(),
ConversationTypeEnum.GROUPV2
);
convo.set('active_at', undefined);
expect(swarmPolling.getPollingTimeout(PubKey.cast(convo.id as string))).to.eq(
@ -111,8 +111,8 @@ describe('SwarmPolling:getPollingTimeout', () => {
it('returns MEDIUM_ACTIVE for convo with activeAt of more than 2 days but less than a week old', () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV3PkStr(),
ConversationTypeEnum.GROUPV3
TestUtils.generateFakeClosedGroupV2PkStr(),
ConversationTypeEnum.GROUPV2
);
convo.set('active_at', Date.now() - 1000 * 3600 * 25 * 2); // 25 hours x 2 = 50 hours old
expect(swarmPolling.getPollingTimeout(PubKey.cast(convo.id as string))).to.eq(
@ -127,8 +127,8 @@ describe('SwarmPolling:getPollingTimeout', () => {
it('returns INACTIVE for convo with activeAt of more than a week', () => {
const convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV3PkStr(),
ConversationTypeEnum.GROUPV3
TestUtils.generateFakeClosedGroupV2PkStr(),
ConversationTypeEnum.GROUPV2
);
convo.set('active_at', Date.now() - 1000 * 3600 * 24 * 8); // 8 days
expect(swarmPolling.getPollingTimeout(PubKey.cast(convo.id as string))).to.eq(

@ -24,7 +24,7 @@ const pollOnceForGroupLegacyArgs = (groupLegacy: string) => [
[groupLegacy, ConversationTypeEnum.GROUP],
];
const pollOnceForGroupArgs = (group: GroupPubkeyType) => [[group, ConversationTypeEnum.GROUPV3]];
const pollOnceForGroupArgs = (group: GroupPubkeyType) => [[group, ConversationTypeEnum.GROUPV2]];
function stubWithLegacyGroups(pubkeys: Array<string>) {
const groups = pubkeys.map(m => ({ pubkeyHex: m }) as LegacyGroupInfo);
@ -345,8 +345,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
describe('03 group', () => {
it('does run for group pubkey on start no matter the recent timestamp', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
convo.set('active_at', Date.now());
@ -362,8 +362,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
});
it('does only poll from -10 for closed groups', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
convo.set('active_at', 1);
@ -382,8 +382,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
});
it('does run for group pubkey on start but not another time if activeAt is old ', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
@ -401,8 +401,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
});
it('does run twice if activeAt less than one hour ', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
@ -430,8 +430,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
});
it('does run twice if activeAt is inactive and we tick longer than 2 minutes', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
@ -460,8 +460,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
});
it('does run once only if group is inactive and we tick less than 2 minutes ', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV3);
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const convo = ConvoHub.use().getOrCreate(groupPk, ConversationTypeEnum.GROUPV2);
stubWithLegacyGroups([]);
stubWithGroups([groupPk]);
@ -487,8 +487,8 @@ describe('SwarmPolling:pollForAllKeys', () => {
beforeEach(async () => {
convo = ConvoHub.use().getOrCreate(
TestUtils.generateFakeClosedGroupV3PkStr(),
ConversationTypeEnum.GROUPV3
TestUtils.generateFakeClosedGroupV2PkStr(),
ConversationTypeEnum.GROUPV2
);
stubWithLegacyGroups([]);

@ -81,7 +81,7 @@ describe('getPollingDetails', () => {
it('new group NOT in wrapper should be requested for leaving', async () => {
TestUtils.stubUserGroupWrapper('getAllLegacyGroups', []);
TestUtils.stubUserGroupWrapper('getAllGroups', []);
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
Sinon.stub(swarmPolling, 'getPollingTimeout').returns(SWARM_POLLING_TIMEOUT.ACTIVE);
@ -120,7 +120,7 @@ describe('getPollingDetails', () => {
});
it('new group', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
TestUtils.stubUserGroupWrapper('getAllLegacyGroups', []);
TestUtils.stubUserGroupWrapper('getAllGroups', [{ pubkeyHex: groupPk } as UserGroupsGet]);
@ -163,7 +163,7 @@ describe('getPollingDetails', () => {
});
it('new group in wrapper should be polled', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
TestUtils.stubUserGroupWrapper('getAllLegacyGroups', []);
TestUtils.stubUserGroupWrapper('getAllGroups', [{ pubkeyHex: groupPk } as UserGroupsGet]);
@ -176,7 +176,7 @@ describe('getPollingDetails', () => {
expect(toPollDetails.length).to.be.eq(2);
expect(toPollDetails[0]).to.be.deep.eq([ourNumber, ConversationTypeEnum.PRIVATE]);
expect(toPollDetails[1]).to.be.deep.eq([groupPk, ConversationTypeEnum.GROUPV3]);
expect(toPollDetails[1]).to.be.deep.eq([groupPk, ConversationTypeEnum.GROUPV2]);
// no groups to leave nor legacy ones
expect(legacyGroupsToLeave.length).to.be.eq(0);
expect(groupsToLeave.length).to.be.eq(0);
@ -186,8 +186,8 @@ describe('getPollingDetails', () => {
describe('multiple groups', () => {
it('one legacy group with a few v2 group not in wrapper', async () => {
const groupPk = TestUtils.generateFakePubKeyStr();
const groupV2Pk = TestUtils.generateFakeClosedGroupV3PkStr();
const groupV2Pk2 = TestUtils.generateFakeClosedGroupV3PkStr();
const groupV2Pk = TestUtils.generateFakeClosedGroupV2PkStr();
const groupV2Pk2 = TestUtils.generateFakeClosedGroupV2PkStr();
TestUtils.stubUserGroupWrapper('getAllLegacyGroups', [
{ pubkeyHex: groupPk } as LegacyGroupInfo,
@ -213,7 +213,7 @@ describe('getPollingDetails', () => {
});
it('new group in wrapper with a few legacy groups not in wrapper', async () => {
const groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
const groupPkLeg1 = TestUtils.generateFakePubKeyStr();
const groupPkLeg2 = TestUtils.generateFakePubKeyStr();
@ -231,7 +231,7 @@ describe('getPollingDetails', () => {
expect(toPollDetails.length).to.be.eq(2);
expect(toPollDetails[0]).to.be.deep.eq([ourNumber, ConversationTypeEnum.PRIVATE]);
expect(toPollDetails[1]).to.be.deep.eq([groupPk, ConversationTypeEnum.GROUPV3]);
expect(toPollDetails[1]).to.be.deep.eq([groupPk, ConversationTypeEnum.GROUPV2]);
expect(legacyGroupsToLeave.length).to.be.eq(2);
expect(legacyGroupsToLeave[0]).to.be.eq(groupPkLeg1);
expect(legacyGroupsToLeave[1]).to.be.eq(groupPkLeg2);
@ -239,8 +239,8 @@ describe('getPollingDetails', () => {
});
it('two of each, all should be polled', async () => {
const groupPk1 = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk2 = TestUtils.generateFakeClosedGroupV3PkStr();
const groupPk1 = TestUtils.generateFakeClosedGroupV2PkStr();
const groupPk2 = TestUtils.generateFakeClosedGroupV2PkStr();
const groupPkLeg1 = TestUtils.generateFakePubKeyStr();
const groupPkLeg2 = TestUtils.generateFakePubKeyStr();
@ -267,8 +267,8 @@ describe('getPollingDetails', () => {
expect(toPollDetails[0]).to.be.deep.eq([ourNumber, ConversationTypeEnum.PRIVATE]);
expect(toPollDetails[1]).to.be.deep.eq([groupPkLeg1, ConversationTypeEnum.GROUP]);
expect(toPollDetails[2]).to.be.deep.eq([groupPkLeg2, ConversationTypeEnum.GROUP]);
expect(toPollDetails[3]).to.be.deep.eq([groupPk1, ConversationTypeEnum.GROUPV3]);
expect(toPollDetails[4]).to.be.deep.eq([groupPk2, ConversationTypeEnum.GROUPV3]);
expect(toPollDetails[3]).to.be.deep.eq([groupPk1, ConversationTypeEnum.GROUPV2]);
expect(toPollDetails[4]).to.be.deep.eq([groupPk2, ConversationTypeEnum.GROUPV2]);
// no groups to leave nor legacy ones
expect(legacyGroupsToLeave.length).to.be.eq(0);

@ -58,7 +58,7 @@ describe('GroupSyncJob run()', () => {
});
it('throws if no user keys', async () => {
const job = new GroupSync.GroupSyncJob({
identifier: TestUtils.generateFakeClosedGroupV3PkStr(),
identifier: TestUtils.generateFakeClosedGroupV2PkStr(),
});
const func = async () => job.run();
@ -67,7 +67,7 @@ describe('GroupSyncJob run()', () => {
it('permanent failure if group is not a 03 one', async () => {
const job = new GroupSync.GroupSyncJob({
identifier: TestUtils.generateFakeClosedGroupV3PkStr().slice(2),
identifier: TestUtils.generateFakeClosedGroupV2PkStr().slice(2),
});
const result = await job.run();
expect(result).to.be.eq(RunJobResult.PermanentFailure);
@ -78,7 +78,7 @@ describe('GroupSyncJob run()', () => {
Sinon.stub(UserUtils, 'getUserED25519KeyPairBytes').resolves(undefined);
Sinon.stub(ConvoHub.use(), 'get').resolves({}); // anything not falsy
const job = new GroupSync.GroupSyncJob({
identifier: TestUtils.generateFakeClosedGroupV3PkStr(),
identifier: TestUtils.generateFakeClosedGroupV2PkStr(),
});
const result = await job.run();
expect(result).to.be.eq(RunJobResult.PermanentFailure);
@ -89,7 +89,7 @@ describe('GroupSyncJob run()', () => {
Sinon.stub(UserUtils, 'getUserED25519KeyPairBytes').resolves({} as any); // anything not falsy
Sinon.stub(ConvoHub.use(), 'get').returns(undefined as any);
const job = new GroupSync.GroupSyncJob({
identifier: TestUtils.generateFakeClosedGroupV3PkStr(),
identifier: TestUtils.generateFakeClosedGroupV2PkStr(),
});
const result = await job.run();
expect(result).to.be.eq(RunJobResult.PermanentFailure);
@ -103,7 +103,7 @@ describe('GroupSyncJob run()', () => {
);
Sinon.stub(ConvoHub.use(), 'get').returns({} as any); // anything not falsy
const job = new GroupSync.GroupSyncJob({
identifier: TestUtils.generateFakeClosedGroupV3PkStr(),
identifier: TestUtils.generateFakeClosedGroupV2PkStr(),
});
const result = await job.run();
expect(result).to.be.eq(RunJobResult.Success);
@ -257,7 +257,7 @@ describe('GroupSyncJob pushChangesToGroupSwarmIfNeeded', () => {
beforeEach(async () => {
sodium = await getSodiumNode();
groupPk = TestUtils.generateFakeClosedGroupV3PkStr();
groupPk = TestUtils.generateFakeClosedGroupV2PkStr();
userkeys = await TestUtils.generateUserKeyPairs();
Sinon.stub(UserUtils, 'getOurPubKeyStrFromCache').returns(userkeys.x25519KeyPair.pubkeyHex);
Sinon.stub(UserUtils, 'getUserED25519KeyPairBytes').resolves(userkeys.ed25519KeyPair);

@ -70,7 +70,7 @@ export async function generateGroupV2(privateEd25519: Uint8Array) {
return groupWrapper.createGroup();
}
export function generateFakeClosedGroupV3PkStr(): GroupPubkeyType {
export function generateFakeClosedGroupV2PkStr(): GroupPubkeyType {
// Generates a mock pubkey for testing
const numBytes = PubKey.PUBKEY_LEN / 2 - 1;
const hexBuffer = crypto.randomBytes(numBytes).toString('hex');

Loading…
Cancel
Save