diff --git a/packages/backend/package.json b/packages/backend/package.json index ed07599af..798606304 100644 --- a/packages/backend/package.json +++ b/packages/backend/package.json @@ -27,7 +27,7 @@ "yaml": "^2.1.3" }, "scripts": { - "docker:up": "docker-compose up -d", + "docker:up": "docker compose up -d", "prisma-init": "prisma generate && prisma migrate deploy ", "start": "yarn prisma-init && node ./dist/index.js", "start-inspect": "node --inspect=0.0.0.0:9229 ./dist/index.js", @@ -35,7 +35,7 @@ "build": "yarn tsc && cp ./config.yml ./dist/config.yml | true", "build:schema": "sh ./schemas.sh", "createDeliveryServiceProfile": "node --no-warnings ./cli.js", - "before:tests": "docker-compose -f docker-compose.test.yml up -d && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn prisma-init" + "before:tests": "docker compose -f docker-compose.test.yml up -d && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn prisma-init" }, "devDependencies": { "@babel/core": "^7.19.6", diff --git a/packages/delivery-service/package.json b/packages/delivery-service/package.json index d9c3a4a17..e8588f753 100644 --- a/packages/delivery-service/package.json +++ b/packages/delivery-service/package.json @@ -24,14 +24,14 @@ "yaml": "^2.1.3" }, "scripts": { - "docker:up": "docker-compose up -d", + "docker:up": "docker compose up -d", "start": "node ./dist/index.js", "start-inspect": "node --inspect=0.0.0.0:9229 ./dist/index.js", "test": "yarn run before:tests && jest --coverage --runInBand --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)' ", "build": "yarn tsc ", "createDeliveryServiceProfile": "node --no-warnings ./cli.js", - "before:tests": "docker-compose -f docker-compose.test.yml up -d", - "after:tests": "docker-compose -f docker-compose.test.yml down" + "before:tests": "docker compose -f docker-compose.test.yml up -d", + "after:tests": "docker compose -f docker-compose.test.yml down" }, "devDependencies": { "@babel/core": "^7.19.6", diff --git a/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts b/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts index 580d39ac3..c6b93acdd 100644 --- a/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts +++ b/packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts @@ -1,6 +1,11 @@ import { IBackendConnector } from '@dm3-org/dm3-lib-shared'; import { MessageRecord } from '../chunkStorage/ChunkStorageTypes'; -import { Encryption, StorageAPI, StorageEnvelopContainer } from '../types'; +import { + Encryption, + HaltedStorageEnvelopContainer, + StorageAPI, + StorageEnvelopContainer, +} from '../types'; //getCloudStorages is the interface to the cloud storage. //It encrypts and decrypts the data before sending/reciving it to/from the cloud storage of the DM3 backend export const getCloudStorage = ( @@ -83,11 +88,14 @@ export const getCloudStorage = ( message.encryptedEnvelopContainer, ); - return JSON.parse(decryptedEnvelopContainer); + return { + ...JSON.parse(decryptedEnvelopContainer), + messageId: message.messageId, + } as HaltedStorageEnvelopContainer; }), ); - return decryptedMessages as StorageEnvelopContainer[]; + return decryptedMessages; }; const clearHaltedMessages = async ( diff --git a/packages/lib/storage/src/new/types.ts b/packages/lib/storage/src/new/types.ts index 5c7401267..f02d3cf61 100644 --- a/packages/lib/storage/src/new/types.ts +++ b/packages/lib/storage/src/new/types.ts @@ -7,7 +7,7 @@ export interface StorageAPI { pageSize: number, offset: number, ) => Promise; - getHaltedMessages: () => Promise; + getHaltedMessages: () => Promise; clearHaltedMessages: ( messageId: string, aliasName: string, @@ -39,6 +39,12 @@ export interface StorageEnvelopContainer { envelop: Envelop; } +export interface HaltedStorageEnvelopContainer { + messageState: MessageState; + envelop: Envelop; + messageId: string; +} + export interface Conversation { //the contactEnsName is the ensName of the contact contactEnsName: string; diff --git a/packages/messenger-widget/src/context/testHelper/getMockedStorageContext.ts b/packages/messenger-widget/src/context/testHelper/getMockedStorageContext.ts index 00d59b749..75d0632dd 100644 --- a/packages/messenger-widget/src/context/testHelper/getMockedStorageContext.ts +++ b/packages/messenger-widget/src/context/testHelper/getMockedStorageContext.ts @@ -1,6 +1,7 @@ import { StorageEnvelopContainer, Conversation, + HaltedStorageEnvelopContainer, } from '@dm3-org/dm3-lib-storage'; import { StorageContextType } from '../StorageContext'; @@ -56,7 +57,9 @@ export const getMockedStorageContext = ( ): Promise { throw new Error('Function not implemented.'); }, - getHaltedMessages: function (): Promise { + getHaltedMessages: function (): Promise< + HaltedStorageEnvelopContainer[] + > { throw new Error('Function not implemented.'); }, clearHaltedMessages: function ( diff --git a/packages/messenger-widget/src/hooks/haltDelivery/useHaltDelivery.ts b/packages/messenger-widget/src/hooks/haltDelivery/useHaltDelivery.ts index 17e8f88f4..c9fb4f632 100644 --- a/packages/messenger-widget/src/hooks/haltDelivery/useHaltDelivery.ts +++ b/packages/messenger-widget/src/hooks/haltDelivery/useHaltDelivery.ts @@ -31,6 +31,7 @@ export const useHaltDelivery = () => { // Fetch all messages the user has halted. Then check if they can be delivered now. const handleHaltedMessages = async () => { const haltedMessages = await getHaltedMessages(); + //Get all recipients of the halted messages const recipients = Array.from( new Set( @@ -39,6 +40,7 @@ export const useHaltDelivery = () => { ), ), ); + //Resolve the tldNames to their aliases const resolvedAliases = await Promise.all( recipients.map(async (ensName) => ({ @@ -124,9 +126,7 @@ export const useHaltDelivery = () => { ); return { //To clear the envelop that has been used to store the halted message - haltedEnvelopId: - message.envelop.metadata - ?.encryptedMessageHash!, + haltedEnvelopId: message.messageId, ...dispatchableEnvelop, //we keep the alias name for the receiver. In case it differes from the ensName aliasName: @@ -145,6 +145,7 @@ export const useHaltDelivery = () => { await submitEnvelopsToReceiversDs(dispatchableEnvelops); + // clear the halted messages as those are sent dispatchableEnvelops.map((envelop) => { clearHaltedMessages(envelop.haltedEnvelopId, envelop.aliasName); }); diff --git a/packages/messenger-widget/src/hooks/storage/useStorage.tsx b/packages/messenger-widget/src/hooks/storage/useStorage.tsx index 91745bba9..ea78b93a2 100644 --- a/packages/messenger-widget/src/hooks/storage/useStorage.tsx +++ b/packages/messenger-widget/src/hooks/storage/useStorage.tsx @@ -15,6 +15,7 @@ import { sha256, stringify } from '@dm3-org/dm3-lib-shared'; import { Conversation, StorageAPI } from '@dm3-org/dm3-lib-storage'; import { useEffect, useState } from 'react'; import { BackendContextType } from '../../context/BackendContext'; +import { HaltedStorageEnvelopContainer } from '@dm3-org/dm3-lib-storage'; //Handels storage sync and offers an interface for other hooks to interact with the storage export const useStorage = ( @@ -209,7 +210,7 @@ export type GetMessages = ( pageSize: number, offset: number, ) => Promise; -export type GetHaltedMessages = () => Promise; +export type GetHaltedMessages = () => Promise; export type ClearHaltedMessages = ( messageId: string, aliasName: string,