Skip to content

Commit

Permalink
Merge branch '1108-Ackknowledge-messages-by-messageHash-instead-of-ti…
Browse files Browse the repository at this point in the history
…mestamp' into testing
  • Loading branch information
AlexNi245 committed Jul 17, 2024
2 parents 4d0c2a5 + a66b8aa commit 6be783d
Show file tree
Hide file tree
Showing 21 changed files with 15 additions and 785 deletions.
16 changes: 1 addition & 15 deletions packages/backend/src/persistence/getDatabase.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Session as DSSession, spamFilter } from '@dm3-org/dm3-lib-delivery';
import { IAccountDatabase } from '@dm3-org/dm3-lib-server-side';
import { UserStorage } from '@dm3-org/dm3-lib-storage';
import { PrismaClient } from '@prisma/client';
import { createClient } from 'redis';
import Session from './session';
Expand All @@ -14,7 +13,7 @@ export enum RedisPrefix {
Sync = 'sync:',
// Account used to be called Session. The prefix still resolves to "session:" for now.
Account = 'session:',
UserStorage = 'user.storage:',
Session = 'session:',
NotificationChannel = 'notificationChannel:',
GlobalNotification = 'globalNotification:',
Otp = 'otp:',
Expand Down Expand Up @@ -65,9 +64,6 @@ export async function getDatabase(
//Session
setAccount: Session.setAccount(redis),
getAccount: Session.getAccount(redis),
//Legacy remove after storage has been merged
getUserStorage: Storage.getUserStorageOld(redis),
setUserStorage: Storage.setUserStorageOld(redis),
//Storage AddConversation
addConversation: Storage.addConversation(prisma),
getConversationList: Storage.getConversationList(prisma),
Expand All @@ -87,10 +83,6 @@ export async function getDatabase(
getHaltedMessages: Storage.getHaltedMessages(prisma),
//Storage Delete Halted Message
clearHaltedMessage: Storage.clearHaltedMessage(prisma),
//Get the user db migration status
getUserDbMigrationStatus: Storage.getUserDbMigrationStatus(redis),
//Set the user db migration status to true
setUserDbMigrated: Storage.setUserDbMigrated(redis),
};
}

Expand All @@ -102,10 +94,6 @@ export interface IDatabase extends IAccountDatabase {
})
| null
>;
//Legacy remove after storage has been merged
getUserStorage: (ensName: string) => Promise<UserStorage | null>;
setUserStorage: (ensName: string, data: string) => Promise<void>;

addConversation: (
ensName: string,
encryptedContactName: string,
Expand Down Expand Up @@ -147,8 +135,6 @@ export interface IDatabase extends IAccountDatabase {
aliasName: string,
messageId: string,
) => Promise<boolean>;
getUserDbMigrationStatus: (ensName: string) => Promise<boolean>;
setUserDbMigrated: (ensName: string) => Promise<void>;
}

export type Redis = Awaited<ReturnType<typeof getRedisClient>>;

This file was deleted.

17 changes: 0 additions & 17 deletions packages/backend/src/persistence/storage/getUserStorage.ts

This file was deleted.

14 changes: 0 additions & 14 deletions packages/backend/src/persistence/storage/getUserStorageOld.ts

This file was deleted.

9 changes: 1 addition & 8 deletions packages/backend/src/persistence/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { getUserStorageOld } from './getUserStorageOld';
import { setUserStorageOld } from './setUserStorageOld';
import { addConversation } from './postgres/addConversation';
import { addMessageBatch } from './postgres/addMessageBatch';
import { editMessageBatch } from './postgres/editMessageBatch';
Expand All @@ -9,14 +7,11 @@ import { getNumberOfConversations } from './postgres/getNumberOfConversations';
import { getNumberOfMessages } from './postgres/getNumberOfMessages';
import { toggleHideConversation } from './postgres/toggleHideConversation';
import { MessageRecord } from './postgres/dto/MessageRecord';
import { getUserDbMigrationStatus } from './getUserDbMigrationStatus';
import { setUserDbMigrated } from './setUserDbMigrated';

import { getHaltedMessages } from './postgres/haltedMessage/getHaltedMessages';
import { clearHaltedMessage } from './postgres/haltedMessage/clearHaltedMessage';

export default {
getUserStorageOld,
setUserStorageOld,
addConversation,
addMessageBatch,
editMessageBatch,
Expand All @@ -27,8 +22,6 @@ export default {
toggleHideConversation,
getHaltedMessages,
clearHaltedMessage,
getUserDbMigrationStatus,
setUserDbMigrated,
};

export type { MessageRecord };
8 changes: 0 additions & 8 deletions packages/backend/src/persistence/storage/setUserDbMigrated.ts

This file was deleted.

18 changes: 0 additions & 18 deletions packages/backend/src/persistence/storage/setUserStorage.ts

This file was deleted.

12 changes: 0 additions & 12 deletions packages/backend/src/persistence/storage/setUserStorageOld.ts

This file was deleted.

30 changes: 0 additions & 30 deletions packages/backend/src/storage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1384,34 +1384,4 @@ describe('Storage', () => {
);
});
});
describe('Migration', () => {
it('should migrate storage', async () => {
const { body: preMigrationStatus } = await request(app)
.get(`/new/bob.eth/migrationStatus`)
.set({
authorization: 'Bearer ' + token,
})
.send();

expect(preMigrationStatus).toBe(false);

const { status } = await request(app)
.post(`/new/bob.eth/migrationStatus`)
.set({
authorization: 'Bearer ' + token,
})
.send();

expect(status).toBe(200);

const { body: postMigrationStatus } = await request(app)
.get(`/new/bob.eth/migrationStatus`)
.set({
authorization: 'Bearer ' + token,
})
.send();

expect(postMigrationStatus).toBe(true);
});
});
});
48 changes: 1 addition & 47 deletions packages/backend/src/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import { sha256, validateSchema } from '@dm3-org/dm3-lib-shared';
import cors from 'cors';
import { ethers } from 'ethers';
import express, { NextFunction, Request, Response } from 'express';
import stringify from 'safe-stable-stringify';
import { IDatabase } from './persistence/getDatabase';
import { MessageRecord } from './persistence/storage';
import { AddMessageBatchRequest } from './schema/storage/AddMessageBatchRequest';
import { AddMessageRequest } from './schema/storage/AddMesssageRequest';
import { EditMessageBatchRequest } from './schema/storage/EditMessageBatchRequest';
import { PaginatedRequest } from './schema/storage/PaginatedRequest';
import { AddHaltedMessageRequest } from './schema/storage/AddHaltedMessageSchema';
import { MessageRecord } from './persistence/storage';

const DEFAULT_CONVERSATION_PAGE_SIZE = 10;
const DEFAULT_MESSAGE_PAGE_SIZE = 100;
Expand Down Expand Up @@ -323,49 +321,5 @@ export default (
},
);

router.get('/new/:ensName/migrationStatus', async (req, res, next) => {
try {
const ensName = normalizeEnsName(req.params.ensName);
const status = await db.getUserDbMigrationStatus(ensName);
return res.json(status);
} catch (e) {
next(e);
}
});

router.post('/new/:ensName/migrationStatus', async (req, res, next) => {
try {
const ensName = normalizeEnsName(req.params.ensName);
await db.setUserDbMigrated(ensName);
return res.send();
} catch (e) {
next(e);
}
});

router.get('/:ensName', async (req, res, next) => {
try {
const account = normalizeEnsName(req.params.ensName);
const userStorage = await db.getUserStorage(account);
return res.json(userStorage);
} catch (e) {
next(e);
}
});

router.post('/:ensName', async (req, res, next) => {
try {
const account = normalizeEnsName(req.params.ensName);

await db.setUserStorage(account, stringify(req.body)!);

res.json({
timestamp: new Date().getTime(),
});
} catch (e) {
next(e);
}
});

return router;
};
7 changes: 3 additions & 4 deletions packages/delivery-service/src/delivery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ const syncAcknowledgementParamsSchema = {
type: 'object',
properties: {
ensName: { type: 'string' },
messageHash: { type: 'string' },
},
required: ['ensName', 'messageHash'],
required: ['ensName'],
additionalProperties: false,
};
const syncAcknowledgementBodySchema = {
Expand Down Expand Up @@ -97,7 +96,7 @@ export default (
},
);
router.post(
'/messages/:ensName/syncAcknowledgment/:messageHash',
'/messages/:ensName/syncAcknowledgments/',
async (req, res, next) => {
const hasValidParams = validateSchema(
syncAcknowledgementParamsSchema,
Expand Down Expand Up @@ -129,7 +128,7 @@ export default (

await db.syncAcknowledge(
conversationId,
req.params.messageHash,
ack.messageHash,
);
},
),
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/delivery/src/Messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { SpamFilterRules } from './spam-filter/SpamFilterRules';

export interface Acknowledgment {
contactAddress: string;
messageDeliveryServiceTimestamp: number;
messageHash: string;
}

export function getConversationId(ensNameA: string, ensNameB: string): string {
Expand Down
Loading

0 comments on commit 6be783d

Please sign in to comment.