Skip to content

Commit

Permalink
Merge pull request #1132 from dm3-org/halt-delivery-msg-fix
Browse files Browse the repository at this point in the history
Halt delivery msg fix
  • Loading branch information
AlexNi245 authored Aug 5, 2024
2 parents 2940412 + 3f8399f commit 94dc2e9
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@
"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",
"test": "yarn run before:tests && DATABASE_URL='postgresql://prisma:prisma@localhost:5433/tests?schema=public' yarn jest --coverage --runInBand --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'",
"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",
Expand Down
6 changes: 3 additions & 3 deletions packages/delivery-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 11 additions & 3 deletions packages/lib/storage/src/new/cloudStorage/getCloudStorage.ts
Original file line number Diff line number Diff line change
@@ -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 = (
Expand Down Expand Up @@ -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 (
Expand Down
8 changes: 7 additions & 1 deletion packages/lib/storage/src/new/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface StorageAPI {
pageSize: number,
offset: number,
) => Promise<StorageEnvelopContainer[]>;
getHaltedMessages: () => Promise<StorageEnvelopContainer[]>;
getHaltedMessages: () => Promise<HaltedStorageEnvelopContainer[]>;
clearHaltedMessages: (
messageId: string,
aliasName: string,
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
StorageEnvelopContainer,
Conversation,
HaltedStorageEnvelopContainer,
} from '@dm3-org/dm3-lib-storage';
import { StorageContextType } from '../StorageContext';

Expand Down Expand Up @@ -56,7 +57,9 @@ export const getMockedStorageContext = (
): Promise<StorageEnvelopContainer[]> {
throw new Error('Function not implemented.');
},
getHaltedMessages: function (): Promise<StorageEnvelopContainer[]> {
getHaltedMessages: function (): Promise<
HaltedStorageEnvelopContainer[]
> {
throw new Error('Function not implemented.');
},
clearHaltedMessages: function (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -39,6 +40,7 @@ export const useHaltDelivery = () => {
),
),
);

//Resolve the tldNames to their aliases
const resolvedAliases = await Promise.all(
recipients.map(async (ensName) => ({
Expand Down Expand Up @@ -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:
Expand All @@ -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);
});
Expand Down
3 changes: 2 additions & 1 deletion packages/messenger-widget/src/hooks/storage/useStorage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down Expand Up @@ -209,7 +210,7 @@ export type GetMessages = (
pageSize: number,
offset: number,
) => Promise<StorageEnvelopContainerNew[]>;
export type GetHaltedMessages = () => Promise<StorageEnvelopContainerNew[]>;
export type GetHaltedMessages = () => Promise<HaltedStorageEnvelopContainer[]>;
export type ClearHaltedMessages = (
messageId: string,
aliasName: string,
Expand Down

0 comments on commit 94dc2e9

Please sign in to comment.