@@ -16,6 +16,8 @@ import {
16
16
Conversation ,
17
17
ConversationId ,
18
18
ConversationVersion ,
19
+ GroupUpdatedCodec ,
20
+ GroupUpdatedContent ,
19
21
JSContentCodec ,
20
22
} from '../../../src/index'
21
23
@@ -1328,3 +1330,57 @@ test('messages dont disappear newGroupWithIdentities', async () => {
1328
1330
1329
1331
return true
1330
1332
} )
1333
+
1334
+ test ( 'new groups and dms contain a message including who added the user' , async ( ) => {
1335
+ const [ alix , bo ] = await createClients ( 2 )
1336
+
1337
+ // Register the GroupUpdatedCodec to handle group updated messages
1338
+ Client . register ( new GroupUpdatedCodec ( ) )
1339
+
1340
+ // Test that group we are added to contains the GroupUpdated message with who added us
1341
+ const alixGroup = await alix . conversations . newGroup ( [ bo . inboxId ] )
1342
+ await bo . conversations . sync ( )
1343
+ const boGroup = await bo . conversations . findGroup ( alixGroup . id )
1344
+ const boGroupMessages = await boGroup ?. messages ( )
1345
+ assert ( boGroupMessages ! . length === 1 , 'Bo group should have 1 message' )
1346
+
1347
+ const message = boGroupMessages ! [ 0 ]
1348
+ await assertEqual (
1349
+ message . contentTypeId ,
1350
+ 'xmtp.org/group_updated:1.0' ,
1351
+ 'Message should be a group updated message'
1352
+ )
1353
+ console . log ( message . contentTypeId )
1354
+
1355
+ const groupUpdatedMessage : GroupUpdatedContent = message . content ( )
1356
+ const addedByInboxId = groupUpdatedMessage . initiatedByInboxId
1357
+ await assertEqual (
1358
+ addedByInboxId ,
1359
+ alix . inboxId ,
1360
+ 'Added by inbox id should be alix'
1361
+ )
1362
+
1363
+ // Test that dm we are added to contains the GroupUpdated message with who added us
1364
+ const boDm = await bo . conversations . findOrCreateDm ( alix . inboxId )
1365
+ await bo . conversations . sync ( )
1366
+ const alixDm = await bo . conversations . findConversation ( boDm . id )
1367
+ const alixDmMessages = await alixDm ?. messages ( )
1368
+ assert ( alixDmMessages ! . length === 1 , 'Bo dm should have 1 message' )
1369
+ const dmMessage = alixDmMessages ! [ 0 ]
1370
+ await assertEqual (
1371
+ dmMessage . contentTypeId ,
1372
+ 'xmtp.org/group_updated:1.0' ,
1373
+ 'Message should be a group updated message'
1374
+ )
1375
+ console . log ( dmMessage . contentTypeId )
1376
+
1377
+ const dmGroupUpdatedMessage : GroupUpdatedContent = dmMessage . content ( )
1378
+ const dmAddedByInboxId = dmGroupUpdatedMessage . initiatedByInboxId
1379
+ await assertEqual (
1380
+ dmAddedByInboxId ,
1381
+ bo . inboxId ,
1382
+ 'Added by inbox id should be bo'
1383
+ )
1384
+
1385
+ return true
1386
+ } )
0 commit comments