feat: closed groups state now starts correctly

pull/2971/head
William Grant 2 years ago
parent 2a05185138
commit d923a0d611

@ -849,7 +849,7 @@ export class ConversationModel extends Backbone.Model<ConversationAttributes> {
isEqual(expireTimer, this.get('expireTimer'))
) {
window.log.info(
'WIP: updateExpireTimer() Dropping ExpireTimerUpdate message as we already have the same one set.'
'WIP: conversation: updateExpireTimer() Dropping ExpireTimerUpdate message as we already have the same one set.'
);
return;
}

@ -366,7 +366,8 @@ export async function handleNewClosedGroup(
members,
admins,
activeAt: envelopeTimestamp,
expirationType: 'off',
expirationType: 'unknown',
expireTimer: 0,
};
// be sure to call this before sending the message.

@ -615,7 +615,7 @@ async function handleLegacyGroupUpdate(latestEnvelopeTimestamp: number) {
expirationType:
fromWrapper.disappearingTimerSeconds && fromWrapper.disappearingTimerSeconds > 0
? 'deleteAfterSend'
: 'off',
: 'unknown',
expireTimer: fromWrapper.disappearingTimerSeconds,
};

@ -395,6 +395,7 @@ export async function handleMessageJob(
const expireTimer = messageModel.get('expireTimer');
// NOTE we handle incoming disappear afer send messages and are Note To Self sync messages here
// TODO I think this is incorrect? Let's fix
if (
conversation &&
(messageModel.isIncoming() || conversation.isMe()) &&
@ -450,7 +451,7 @@ export async function handleMessageJob(
) {
confirm?.();
window?.log?.info(
'Dropping ExpireTimerUpdate message as we already have the same one set.'
'WIP: queuedJob: Dropping ExpireTimerUpdate message as we already have the same one set.'
);
return;
}

@ -16,6 +16,7 @@ import { PubKey } from '../types';
import { UserUtils } from '../utils';
import { forceSyncConfigurationNowIfNeeded } from '../utils/sync/syncUtils';
import { getConversationController } from './ConversationController';
import { DisappearAfterSendOnly, DisappearingMessageType } from '../../util/expiringMessages';
export async function createClosedGroup(groupName: string, members: Array<string>, isV3: boolean) {
const setOfMembers = new Set(members);
@ -44,6 +45,8 @@ export async function createClosedGroup(groupName: string, members: Array<string
setOfMembers.add(us);
const listOfMembers = [...setOfMembers];
const admins = [us];
const existingExpirationType = 'unknown';
const existingExpireTimer = 0;
const groupDetails: ClosedGroup.GroupInfo = {
@ -53,7 +56,7 @@ export async function createClosedGroup(groupName: string, members: Array<string
admins,
activeAt: Date.now(),
// TODO This is only applicable for old closed groups - will be removed in future
expirationType: existingExpireTimer === 0 ? 'off' : 'deleteAfterSend',
expirationType: existingExpirationType,
expireTimer: existingExpireTimer,
};
@ -72,6 +75,7 @@ export async function createClosedGroup(groupName: string, members: Array<string
groupName,
admins,
encryptionKeyPair,
existingExpirationType,
existingExpireTimer
);
@ -99,6 +103,7 @@ async function sendToGroupMembers(
groupName: string,
admins: Array<string>,
encryptionKeyPair: ECKeyPair,
existingExprationType: DisappearAfterSendOnly,
existingExpireTimer: number,
isRetry: boolean = false
): Promise<any> {
@ -108,6 +113,7 @@ async function sendToGroupMembers(
groupName,
admins,
encryptionKeyPair,
existingExprationType,
existingExpireTimer
);
window?.log?.info(`Sending invites for group ${groupPublicKey} to ${listOfMembers}`);
@ -163,6 +169,7 @@ async function sendToGroupMembers(
groupName,
admins,
encryptionKeyPair,
existingExprationType,
existingExpireTimer,
isRetrySend
);
@ -180,6 +187,7 @@ function createInvitePromises(
groupName: string,
admins: Array<string>,
encryptionKeyPair: ECKeyPair,
existingExprationType: DisappearingMessageType,
existingExpireTimer: number
) {
return listOfMembers.map(async m => {
@ -190,6 +198,7 @@ function createInvitePromises(
admins,
keypair: encryptionKeyPair,
timestamp: Date.now(),
expirationType: existingExprationType,
expireTimer: existingExpireTimer,
};
const message = new ClosedGroupNewMessage(messageParams);

@ -26,7 +26,8 @@ import { ClosedGroupRemovedMembersMessage } from '../messages/outgoing/controlMe
import { UserUtils } from '../utils';
import { fromHexToArray, toHex } from '../utils/String';
import {
DisappearingMessageConversationType,
DisappearAfterSendOnly,
changeToDisappearingMessageConversationType,
changeToDisappearingMessageType,
setExpirationStartTimestamp,
} from '../../util/expiringMessages';
@ -37,7 +38,7 @@ export type GroupInfo = {
members: Array<string>;
zombies?: Array<string>;
activeAt?: number;
expirationType?: DisappearingMessageConversationType[0] | DisappearingMessageConversationType[2];
expirationType?: DisappearAfterSendOnly;
expireTimer?: number;
admins?: Array<string>;
};
@ -72,6 +73,12 @@ export async function initiateClosedGroupUpdate(
isGroupV3 ? ConversationTypeEnum.GROUPV3 : ConversationTypeEnum.GROUP
);
const expirationType = changeToDisappearingMessageType(convo, convo.get('expirationType'));
if (expirationType === 'deleteAfterRead') {
throw new Error(`Groups cannot be deleteAfterRead. convo id: ${convo.id}`);
}
// do not give an admins field here. We don't want to be able to update admins and
// updateOrCreateClosedGroup() will update them if given the choice.
const groupDetails: GroupInfo = {
@ -81,7 +88,7 @@ export async function initiateClosedGroupUpdate(
// remove from the zombies list the zombies not which are not in the group anymore
zombies: convo.get('zombies')?.filter(z => members.includes(z)),
activeAt: Date.now(),
expirationType: convo.get('expirationType') || undefined,
expirationType,
expireTimer: convo.get('expireTimer') || 0,
};
@ -253,17 +260,24 @@ export async function updateOrCreateClosedGroup(details: GroupInfo, fromLegacyCo
await conversation.updateGroupAdmins(details.admins, false);
}
await conversation.updateExpireTimer({
// TODO legacy messages support will be removed in a future release
providedExpirationType:
expirationType || (expireTimer && expireTimer > 0) ? 'deleteAfterSend' : 'off',
providedExpireTimer: expireTimer || 0,
providedChangeTimestamp: GetNetworkTime.getNowWithNetworkOffset(),
providedSource: UserUtils.getOurPubKeyStrFromCache(),
receivedAt: Date.now(),
fromSync: true,
fromConfigMessage: Boolean(fromLegacyConfig),
});
// if (
// details.expirationType !== conversation.get('expirationType') ||
// details.expireTimer !== conversation.get('expireTimer')
// ) {
// await conversation.updateExpireTimer({
// providedExpirationType: changeToDisappearingMessageConversationType(
// conversation,
// expirationType,
// expireTimer
// ),
// providedExpireTimer: expireTimer || 0,
// providedChangeTimestamp: GetNetworkTime.getNowWithNetworkOffset(),
// providedSource: UserUtils.getOurPubKeyStrFromCache(),
// receivedAt: Date.now(),
// fromSync: true,
// fromConfigMessage: Boolean(fromLegacyConfig),
// });
// }
await conversation.commit();
}

@ -17,6 +17,7 @@ import { ReleasedFeatures } from './releaseFeature';
// TODO double check this
export const DisappearingMessageMode = ['unknown', 'deleteAfterRead', 'deleteAfterSend'] as const;
export type DisappearingMessageType = typeof DisappearingMessageMode[number];
export type DisappearAfterSendOnly = Exclude<DisappearingMessageType, 'deleteAfterRead'>;
// NOTE these cannot be imported in the nodejs side yet. We need to move the types to the own file with no window imports
// TODO legacy messages support will be removed in a future release
// TODO NOTE legacy is strictly used in the UI and is not a valid disappearing message mode

Loading…
Cancel
Save