drop groupUpdates which happened before we joined the group

pull/1424/head
Audric Ackermann 4 years ago
parent eb9828a3b7
commit 58be168227

@ -14,6 +14,7 @@ interface ConversationAttributes {
isArchived: boolean;
active_at: number;
timestamp: number; // timestamp of what?
lastJoinedTimestamp: number; // ClosedGroupV2: last time we were added to this group
groupAdmins?: Array<string>;
isKickedFromGroup?: boolean;
avatarPath?: string;

@ -58,6 +58,7 @@
isKickedFromGroup: false,
profileSharing: false,
left: false,
lastJoinedTimestamp: new Date('1970-01-01Z00:00:00:000').getTime(),
};
},

@ -189,7 +189,7 @@
const xor = _.xor(notPresentInNew, notPresentInOld);
if (xor.length === 0) {
window.log.log(
window.log.info(
'skipping group update: no detected changes in group member list'
);

@ -961,7 +961,7 @@ export class RegistrationTabs extends React.Component<any, State> {
const secretWords = window.mnemonic.pubkey_to_secret_words(pubkey);
this.setState({ secretWords });
} catch (e) {
window.log.log(e);
window.log.info(e);
await this.resetRegistration();
this.setState({

@ -181,6 +181,15 @@ async function handleNewClosedGroupV2(
const groupId = toHex(publicKey);
const members = membersAsData.map(toHex);
const admins = adminsAsData.map(toHex);
const ourPrimary = await UserUtil.getPrimary();
if (!members.includes(ourPrimary.key)) {
log.info(
'Got a new group message but apparently we are not a member of it. Dropping it.'
);
await removeFromCache(envelope);
return;
}
// FIXME maybe we should handle an expiretimer here too? And on ClosedGroupV2 updates?
const maybeConvo = ConversationController.getInstance().get(groupId);
@ -198,6 +207,7 @@ async function handleNewClosedGroupV2(
// Enable typing:
maybeConvo.set('isKickedFromGroup', false);
maybeConvo.set('left', false);
maybeConvo.set('lastJoinedTimestamp', Date.now());
} else {
log.warn(
'Ignoring a closed group v2 message of type NEW: the conversation already exists'
@ -222,14 +232,13 @@ async function handleNewClosedGroupV2(
'incoming'
);
// TODO: Check that we are even a part of this group
convo.set('name', name);
convo.set('members', members);
// mark a closed group v2 as a medium group.
// this field is used to poll for this groupPubKey on the swarm nodes, among other things
convo.set('is_medium_group', true);
convo.set('active_at', Date.now());
convo.set('lastJoinedTimestamp', Date.now());
// We only set group admins on group creation
convo.set('groupAdmins', admins);
@ -272,6 +281,25 @@ async function handleUpdateClosedGroupV2(
await removeFromCache(envelope);
return;
}
// Check that the message isn't from before the group was created
let lastJoinedTimestamp = convo.get('lastJoinedTimestamp');
// might happen for existing groups
if (!lastJoinedTimestamp) {
const aYearAgo = Date.now() - 1000 * 60 * 24 * 365;
convo.set({
lastJoinedTimestamp: aYearAgo,
});
lastJoinedTimestamp = aYearAgo;
}
if (envelope.timestamp <= lastJoinedTimestamp) {
window.log.warn(
'Got a group update with an older timestamp than when we joined this group last time. Dropping it'
);
await removeFromCache(envelope);
return;
}
const curAdmins = convo.get('groupAdmins');
// Check that the sender is a member of the group (before the update)
@ -520,6 +548,8 @@ export async function createClosedGroupV2(
// be sure to call this before sending the message.
// the sending pipeline needs to know from GroupUtils when a message is for a medium group
await ClosedGroupV2.updateOrCreateClosedGroupV2(groupDetails);
convo.set('lastJoinedTimestamp', Date.now());
// Send a closed group update message to all members individually
const promises = listOfMembers.map(async m => {
const messageParams: ClosedGroupV2NewMessageParams = {

@ -27,7 +27,7 @@ export async function handleContentMessage(envelope: EnvelopePlus) {
const plaintext = await decrypt(envelope, envelope.content);
if (!plaintext) {
window.log.warn('handleContentMessage: plaintext was falsey');
// window.log.warn('handleContentMessage: plaintext was falsey');
return;
} else if (plaintext instanceof ArrayBuffer && plaintext.byteLength === 0) {
return;

@ -91,6 +91,7 @@ export class MockConversation {
isArchived: false,
active_at: Date.now(),
timestamp: Date.now(),
lastJoinedTimestamp: Date.now(),
secondaryStatus: !this.isPrimary,
};
}

Loading…
Cancel
Save