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')) isEqual(expireTimer, this.get('expireTimer'))
) { ) {
window.log.info( 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; return;
} }

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

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

@ -395,6 +395,7 @@ export async function handleMessageJob(
const expireTimer = messageModel.get('expireTimer'); const expireTimer = messageModel.get('expireTimer');
// NOTE we handle incoming disappear afer send messages and are Note To Self sync messages here // 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 ( if (
conversation && conversation &&
(messageModel.isIncoming() || conversation.isMe()) && (messageModel.isIncoming() || conversation.isMe()) &&
@ -450,7 +451,7 @@ export async function handleMessageJob(
) { ) {
confirm?.(); confirm?.();
window?.log?.info( 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; return;
} }

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

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

@ -17,6 +17,7 @@ import { ReleasedFeatures } from './releaseFeature';
// TODO double check this // TODO double check this
export const DisappearingMessageMode = ['unknown', 'deleteAfterRead', 'deleteAfterSend'] as const; export const DisappearingMessageMode = ['unknown', 'deleteAfterRead', 'deleteAfterSend'] as const;
export type DisappearingMessageType = typeof DisappearingMessageMode[number]; 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 // 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 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 // TODO NOTE legacy is strictly used in the UI and is not a valid disappearing message mode

Loading…
Cancel
Save