fix: make sure joined_at is in seconds before saving

pull/3281/head
Audric Ackermann 5 months ago
parent 8d3ed1a2b7
commit fa98d0397a
No known key found for this signature in database

@ -789,7 +789,6 @@ async function handleGroupUpdate(latestEnvelopeTimestamp: number) {
for (let index = 0; index < allGroupsInWrapper.length; index++) {
const groupInWrapper = allGroupsInWrapper[index];
window.inboxStore?.dispatch(groupInfoActions.handleUserGroupUpdate(groupInWrapper) as any);
await handleSingleGroupUpdate({ groupInWrapper, latestEnvelopeTimestamp, userEdKeypair });
}

@ -68,7 +68,7 @@ async function getInitializedGroupObject({
if (!found) {
found = {
authData: null,
joinedAtSeconds: Date.now(),
joinedAtSeconds: Math.floor(Date.now()/ 1000),
name: groupName,
priority: 0,
pubkeyHex: groupPk,

@ -462,6 +462,7 @@ export class SwarmPolling {
);
// We always handle the config messages first (for groups 03 or our own messages)
await this.handleUserOrGroupConfMessages({ confMessages, pubkey, type });
await this.handleRevokedMessages({ revokedMessages, groupPk: pubkey, type });
// Merge results into one list of unique messages
@ -716,15 +717,17 @@ export class SwarmPolling {
}
private async handleSeenMessages(
messages: Array<RetrieveMessageItem>
): Promise<Array<RetrieveMessageItem>> {
messages: Array<RetrieveMessageItemWithNamespace>
): Promise<Array<RetrieveMessageItemWithNamespace>> {
if (!messages.length) {
return [];
}
const incomingHashes = messages.map((m: RetrieveMessageItem) => m.hash);
const incomingHashes = messages.map((m: RetrieveMessageItemWithNamespace) => m.hash);
const dupHashes = await Data.getSeenMessagesByHashList(incomingHashes);
const newMessages = messages.filter((m: RetrieveMessageItem) => !dupHashes.includes(m.hash));
const newMessages = messages.filter(
(m: RetrieveMessageItemWithNamespace) => !dupHashes.includes(m.hash)
);
return newMessages;
}

@ -1,6 +1,6 @@
import { expect } from 'chai';
import { LegacyGroupInfo } from 'libsession_util_nodejs';
import { LegacyGroupInfo, UserGroupsWrapperNode } from 'libsession_util_nodejs';
import { describe } from 'mocha';
import Sinon from 'sinon';
import { ConversationModel } from '../../../../models/conversation';
@ -223,6 +223,21 @@ describe('libsession_user_groups', () => {
'joinedAtSeconds in the wrapper should match the inputted group'
).to.equal(group.get('lastJoinedTimestamp'));
});
it('throws when joined_at is too far in the future', async () => {
const us = await TestUtils.generateUserKeyPairs();
const groupWrapper = new UserGroupsWrapperNode(us.ed25519KeyPair.privKeyBytes, null);
const group = groupWrapper.createGroup();
group.joinedAtSeconds = 4099680000 - 1; // 4099680000 is 1st january 2100 GMT
groupWrapper.setGroup(group); // shouldn't throw
group.joinedAtSeconds = 4099680000 + 1; // 4099680000 is 1st january 2100 GMT
expect(() => {
groupWrapper.setGroup(group);
}).to.throw();
});
it('if disappearing messages is on then the wrapper returned values should match the inputted group', async () => {
const group = new ConversationModel({
...validArgs,

@ -57,7 +57,7 @@ function validUserGroup03WithSecKey(pubkey?: GroupPubkeyType) {
secretKey: new Uint8Array(30),
destroyed: false,
invitePending: false,
joinedAtSeconds: Date.now(),
joinedAtSeconds: Math.floor(Date.now()/1000),
kicked: false,
priority: 0,
pubkeyHex: pubkey || TestUtils.generateFakeClosedGroupV2PkStr(),

Loading…
Cancel
Save