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; isArchived: boolean;
active_at: number; active_at: number;
timestamp: number; // timestamp of what? timestamp: number; // timestamp of what?
lastJoinedTimestamp: number; // ClosedGroupV2: last time we were added to this group
groupAdmins?: Array<string>; groupAdmins?: Array<string>;
isKickedFromGroup?: boolean; isKickedFromGroup?: boolean;
avatarPath?: string; avatarPath?: string;

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

@ -189,7 +189,7 @@
const xor = _.xor(notPresentInNew, notPresentInOld); const xor = _.xor(notPresentInNew, notPresentInOld);
if (xor.length === 0) { if (xor.length === 0) {
window.log.log( window.log.info(
'skipping group update: no detected changes in group member list' '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); const secretWords = window.mnemonic.pubkey_to_secret_words(pubkey);
this.setState({ secretWords }); this.setState({ secretWords });
} catch (e) { } catch (e) {
window.log.log(e); window.log.info(e);
await this.resetRegistration(); await this.resetRegistration();
this.setState({ this.setState({

@ -181,6 +181,15 @@ async function handleNewClosedGroupV2(
const groupId = toHex(publicKey); const groupId = toHex(publicKey);
const members = membersAsData.map(toHex); const members = membersAsData.map(toHex);
const admins = adminsAsData.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? // FIXME maybe we should handle an expiretimer here too? And on ClosedGroupV2 updates?
const maybeConvo = ConversationController.getInstance().get(groupId); const maybeConvo = ConversationController.getInstance().get(groupId);
@ -198,6 +207,7 @@ async function handleNewClosedGroupV2(
// Enable typing: // Enable typing:
maybeConvo.set('isKickedFromGroup', false); maybeConvo.set('isKickedFromGroup', false);
maybeConvo.set('left', false); maybeConvo.set('left', false);
maybeConvo.set('lastJoinedTimestamp', Date.now());
} else { } else {
log.warn( log.warn(
'Ignoring a closed group v2 message of type NEW: the conversation already exists' 'Ignoring a closed group v2 message of type NEW: the conversation already exists'
@ -222,14 +232,13 @@ async function handleNewClosedGroupV2(
'incoming' 'incoming'
); );
// TODO: Check that we are even a part of this group
convo.set('name', name); convo.set('name', name);
convo.set('members', members); convo.set('members', members);
// mark a closed group v2 as a medium group. // 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 // this field is used to poll for this groupPubKey on the swarm nodes, among other things
convo.set('is_medium_group', true); convo.set('is_medium_group', true);
convo.set('active_at', Date.now()); convo.set('active_at', Date.now());
convo.set('lastJoinedTimestamp', Date.now());
// We only set group admins on group creation // We only set group admins on group creation
convo.set('groupAdmins', admins); convo.set('groupAdmins', admins);
@ -272,6 +281,25 @@ async function handleUpdateClosedGroupV2(
await removeFromCache(envelope); await removeFromCache(envelope);
return; 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'); const curAdmins = convo.get('groupAdmins');
// Check that the sender is a member of the group (before the update) // 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. // 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 // the sending pipeline needs to know from GroupUtils when a message is for a medium group
await ClosedGroupV2.updateOrCreateClosedGroupV2(groupDetails); await ClosedGroupV2.updateOrCreateClosedGroupV2(groupDetails);
convo.set('lastJoinedTimestamp', Date.now());
// Send a closed group update message to all members individually // Send a closed group update message to all members individually
const promises = listOfMembers.map(async m => { const promises = listOfMembers.map(async m => {
const messageParams: ClosedGroupV2NewMessageParams = { const messageParams: ClosedGroupV2NewMessageParams = {

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

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

Loading…
Cancel
Save