@@ -17,6 +17,11 @@ import Session from './session';
17
17
import Storage from './storage' ;
18
18
import Otp from './otp' ;
19
19
import { syncAcknowledge } from './messages/syncAcknowledge' ;
20
+ import { PrismaClient } from '@prisma/client' ;
21
+ import { addConversation } from './storage/postgres/addConversation' ;
22
+ import { getConversationList } from './storage/postgres/getConversationList' ;
23
+ import { addMessage } from './storage/postgres/addMessage' ;
24
+ import { getMessages } from './storage/postgres/getMessages' ;
20
25
21
26
export enum RedisPrefix {
22
27
Conversation = 'conversation:' ,
@@ -59,8 +64,16 @@ export async function getRedisClient() {
59
64
return client ;
60
65
}
61
66
62
- export async function getDatabase ( _redis ?: Redis ) : Promise < IDatabase > {
67
+ export async function getPrismaClient ( ) {
68
+ return new PrismaClient ( ) ;
69
+ }
70
+
71
+ export async function getDatabase (
72
+ _redis ?: Redis ,
73
+ _prisma ?: PrismaClient ,
74
+ ) : Promise < IDatabase > {
63
75
const redis = _redis ?? ( await getRedisClient ( ) ) ;
76
+ const prisma = _prisma ?? ( await getPrismaClient ( ) ) ;
64
77
65
78
return {
66
79
//Messages
@@ -104,6 +117,12 @@ export async function getDatabase(_redis?: Redis): Promise<IDatabase> {
104
117
setOtp : Otp . setOtp ( redis ) ,
105
118
getOtp : Otp . getOtp ( redis ) ,
106
119
resetOtp : Otp . resetOtp ( redis ) ,
120
+ //Storage AddConversation
121
+ storage_addConversation : addConversation ( prisma ) ,
122
+ storage_getConversationList : getConversationList ( prisma ) ,
123
+ //Storage Add Messages
124
+ storage_addMessage : addMessage ( prisma ) ,
125
+ storage_getMessages : getMessages ( prisma ) ,
107
126
} ;
108
127
}
109
128
@@ -194,6 +213,23 @@ export interface IDatabase {
194
213
ensName : string ,
195
214
channelType : NotificationChannelType ,
196
215
) => Promise < void > ;
216
+
217
+ storage_addConversation : (
218
+ ensName : string ,
219
+ encryptedContactName : string ,
220
+ ) => Promise < boolean > ;
221
+ storage_getConversationList : ( ensName : string ) => Promise < string [ ] > ;
222
+ storage_addMessage : (
223
+ ensName : string ,
224
+ encryptedContactName : string ,
225
+ messageId : string ,
226
+ encryptedEnvelopContainer : string ,
227
+ ) => Promise < boolean > ;
228
+ storage_getMessages : (
229
+ ensName : string ,
230
+ encryptedContactName : string ,
231
+ page : number ,
232
+ ) => Promise < string [ ] > ;
197
233
}
198
234
199
235
export type Redis = Awaited < ReturnType < typeof getRedisClient > > ;
0 commit comments