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++) { for (let index = 0; index < allGroupsInWrapper.length; index++) {
const groupInWrapper = allGroupsInWrapper[index]; const groupInWrapper = allGroupsInWrapper[index];
window.inboxStore?.dispatch(groupInfoActions.handleUserGroupUpdate(groupInWrapper) as any); window.inboxStore?.dispatch(groupInfoActions.handleUserGroupUpdate(groupInWrapper) as any);
await handleSingleGroupUpdate({ groupInWrapper, latestEnvelopeTimestamp, userEdKeypair }); await handleSingleGroupUpdate({ groupInWrapper, latestEnvelopeTimestamp, userEdKeypair });
} }

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

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

@ -1,6 +1,6 @@
import { expect } from 'chai'; import { expect } from 'chai';
import { LegacyGroupInfo } from 'libsession_util_nodejs'; import { LegacyGroupInfo, UserGroupsWrapperNode } from 'libsession_util_nodejs';
import { describe } from 'mocha'; import { describe } from 'mocha';
import Sinon from 'sinon'; import Sinon from 'sinon';
import { ConversationModel } from '../../../../models/conversation'; import { ConversationModel } from '../../../../models/conversation';
@ -223,6 +223,21 @@ describe('libsession_user_groups', () => {
'joinedAtSeconds in the wrapper should match the inputted group' 'joinedAtSeconds in the wrapper should match the inputted group'
).to.equal(group.get('lastJoinedTimestamp')); ).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 () => { it('if disappearing messages is on then the wrapper returned values should match the inputted group', async () => {
const group = new ConversationModel({ const group = new ConversationModel({
...validArgs, ...validArgs,

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

Loading…
Cancel
Save