@@ -35,23 +35,17 @@ export interface UserReturnType {
35
35
wallet : ReturnType < typeof createWalletClient > ;
36
36
}
37
37
38
- export type xmtpConfig = {
39
- path ?: string ;
40
- hideInitLogMessage ?: boolean ;
41
- } & ClientOptions ;
42
-
43
- export type Agent = {
38
+ export type xmtpClientType = {
44
39
name ?: string ;
45
40
walletKey ?: string ;
46
41
encryptionKey ?: string ;
47
42
onMessage ?: ( message : Message ) => Promise < void > ;
48
- config ?: xmtpConfig ;
43
+ config ?: ClientOptions ;
49
44
} ;
50
45
51
46
export type Message = {
52
47
id : string ; // Unique identifier for the message
53
48
sent : Date ; // Date when the message was sent
54
- isDM : boolean ; // Whether the message is a direct message
55
49
content : {
56
50
text ?: string | undefined ; // Text content of the message
57
51
reply ?: string | undefined ; // Reply content if the message is a reply
@@ -90,7 +84,7 @@ export type Message = {
90
84
} ;
91
85
} ;
92
86
93
- export async function xmtpClient ( agent ?: Agent ) : Promise < XMTP > {
87
+ export async function xmtpClient ( agent ?: xmtpClientType ) : Promise < XMTP > {
94
88
let xmtp : XMTP | null = null ; // Ensure a single instance
95
89
xmtp = new XMTP ( agent ) ;
96
90
await xmtp . init ( ) ;
@@ -102,9 +96,9 @@ export class XMTP {
102
96
address : string | undefined ;
103
97
inboxId : string | undefined ;
104
98
onMessage : ( message : Message ) => Promise < void > ;
105
- agent ?: Agent ;
99
+ agent ?: xmtpClientType ;
106
100
107
- constructor ( agent ?: Agent ) {
101
+ constructor ( agent ?: xmtpClientType ) {
108
102
this . onMessage = agent ?. onMessage ?? ( ( ) => Promise . resolve ( ) ) ;
109
103
this . agent = agent ;
110
104
}
@@ -133,18 +127,18 @@ export class XMTP {
133
127
let env = this . agent ?. config ?. env ;
134
128
if ( ! env ) env = "production" ;
135
129
136
- const volumePath =
130
+ const dbPath =
137
131
process . env . RAILWAY_VOLUME_MOUNT_PATH ??
138
- this . agent ?. config ?. path ??
132
+ this . agent ?. config ?. dbPath ??
139
133
".data/xmtp" ;
140
134
141
- if ( ! fs . existsSync ( volumePath ) ) {
142
- fs . mkdirSync ( volumePath , { recursive : true } ) ;
135
+ if ( ! fs . existsSync ( dbPath ) ) {
136
+ fs . mkdirSync ( dbPath , { recursive : true } ) ;
143
137
}
144
138
145
139
const defaultConfig : ClientOptions = {
146
140
env : env ,
147
- dbPath : `${ volumePath } /${ user . account . address . toLowerCase ( ) } -${ env } ` ,
141
+ dbPath : `${ dbPath } /${ user . account . address . toLowerCase ( ) } -${ env } ` ,
148
142
codecs : [ new TextCodec ( ) ] ,
149
143
} ;
150
144
@@ -291,17 +285,14 @@ export function createUser(key: string): UserReturnType {
291
285
}
292
286
293
287
export async function parseMessage (
294
- message : DecodedMessage | undefined | null ,
288
+ message : DecodedMessage ,
295
289
conversation : Conversation | undefined ,
296
290
client : Client ,
297
291
) : Promise < Message | undefined > {
298
- if ( message === null || message === undefined ) return undefined ;
299
-
300
292
const content = {
301
293
text : message . content as string ,
302
294
} ;
303
295
304
- const date = message . sentAt ;
305
296
let sender :
306
297
| {
307
298
inboxId : string ;
@@ -335,7 +326,7 @@ export async function parseMessage(
335
326
admins : conversation ?. admins ,
336
327
superAdmins : conversation ?. superAdmins ,
337
328
} ,
338
- sent : date ,
329
+ sent : message . sentAt ,
339
330
content,
340
331
typeId : "text" ,
341
332
client : {
0 commit comments