@@ -2,29 +2,36 @@ import {
22 ConversationV1 ,
33 decodeMessageV1 ,
44 decodeMessageV2 ,
5- encodeMessageV1 , encodeMessageV2
6- } from "./../../src/conversations/Conversation" ;
7- import { DecodedMessage , DecodedMessageExport , MessageV1 } from "./../../src/Message" ;
8- import { buildDirectMessageTopic , buildUserIntroTopic } from "../../src/utils" ;
5+ encodeMessageV1 ,
6+ encodeMessageV2 ,
7+ } from './../../src/conversations/Conversation'
8+ import {
9+ DecodedMessage ,
10+ DecodedMessageExport ,
11+ MessageV1 ,
12+ } from './../../src/Message'
13+ import { buildDirectMessageTopic , buildUserIntroTopic } from '../../src/utils'
914import {
1015 Client ,
1116 Compression ,
1217 ContentTypeFallback ,
1318 ContentTypeId ,
14- ContentTypeText , PublicKeyBundle , TextCodec
15- } from "../../src" ;
16- import { SortDirection } from "../../src"
19+ ContentTypeText ,
20+ PublicKeyBundle ,
21+ TextCodec ,
22+ } from '../../src'
23+ import { SortDirection } from '../../src'
1724import { sleep } from '../../src/utils'
1825import { newLocalHostClient , newWallet , waitForUserContact } from '../helpers'
1926import {
2027 PrivateKey ,
2128 PrivateKeyBundleV1 ,
2229 SignedPublicKeyBundle ,
2330} from '../../src/crypto'
24- import { ConversationV2 } from " ../../src/conversations"
31+ import { ConversationV2 } from ' ../../src/conversations'
2532import { ContentTypeTestKey , TestKeyCodec } from '../ContentTypeTestKey'
2633import { content as proto , fetcher } from '@xmtp/proto'
27- import Stream from " ../../src/Stream" ;
34+ import Stream from ' ../../src/Stream'
2835
2936describe ( 'conversation' , ( ) => {
3037 let alice : Client
@@ -668,8 +675,8 @@ describe('conversation', () => {
668675
669676 describe ( 'encode/decode is classless on V1' , ( ) => {
670677 beforeEach ( async ( ) => {
671- alice = await newLocalHostClient ( { publishLegacyContact : true } )
672- bob = await newLocalHostClient ( { publishLegacyContact : true } )
678+ alice = await newLocalHostClient ( { publishLegacyContact : true } )
679+ bob = await newLocalHostClient ( { publishLegacyContact : true } )
673680 await waitForUserContact ( alice , alice )
674681 await waitForUserContact ( bob , bob )
675682 } )
@@ -682,22 +689,26 @@ describe('conversation', () => {
682689 alice . address
683690 )
684691 const baseCodecs = {
685- [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] : new TextCodec ( ) ,
692+ [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] :
693+ new TextCodec ( ) ,
686694 }
687695
688696 const stream = await Stream . create < DecodedMessageExport > (
689697 aliceConversation . getClient ( ) ,
690698 [ aliceConversation . topic ] ,
691699 async ( e ) => {
692700 const convo = deepcopy ( aliceConversation . export ( ) )
693- if ( convo . version !== 'v1' ) {
701+ if ( convo . version !== 'v1' ) {
694702 throw new Error ( 'unexpected convo version' )
695703 }
696704 const keys = deepcopy ( aliceConversation . getClient ( ) . legacyKeys )
697705 return await decodeMessageV1 (
698706 e ,
699707 convo ,
700- { codecFor : ( c : ContentTypeId ) => baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] } ,
708+ {
709+ codecFor : ( c : ContentTypeId ) =>
710+ baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] ,
711+ } ,
701712 keys
702713 )
703714 }
@@ -724,21 +735,28 @@ describe('conversation', () => {
724735 alice . address
725736 )
726737 const baseCodecs = {
727- [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] : new TextCodec ( ) ,
738+ [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] :
739+ new TextCodec ( ) ,
728740 }
729741
730742 await sleep ( 100 )
731743
732744 let topics : string [ ]
733- let recipient = await bobConversation . getClient ( ) . getUserContact ( bobConversation . peerAddress )
745+ let recipient = await bobConversation
746+ . getClient ( )
747+ . getUserContact ( bobConversation . peerAddress )
734748 if ( ! recipient ) {
735- throw new Error ( `recipient ${ bobConversation . peerAddress } is not registered` )
749+ throw new Error (
750+ `recipient ${ bobConversation . peerAddress } is not registered`
751+ )
736752 }
737753 if ( ! ( recipient instanceof PublicKeyBundle ) ) {
738754 recipient = recipient . toLegacyBundle ( )
739755 }
740756
741- if ( ! bobConversation . getClient ( ) . contacts . has ( bobConversation . peerAddress ) ) {
757+ if (
758+ ! bobConversation . getClient ( ) . contacts . has ( bobConversation . peerAddress )
759+ ) {
742760 topics = [
743761 buildUserIntroTopic ( bobConversation . peerAddress ) ,
744762 buildUserIntroTopic ( bobConversation . getClient ( ) . address ) ,
@@ -751,12 +769,10 @@ describe('conversation', () => {
751769
752770 const keys = deepcopy ( bobConversation . getClient ( ) . legacyKeys )
753771
754- const msg = await encodeMessageV1 (
755- "Hi Alice!" ,
756- keys ,
757- recipient ,
758- { codecFor : ( c : ContentTypeId ) => baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] } ,
759- )
772+ const msg = await encodeMessageV1 ( 'Hi Alice!' , keys , recipient , {
773+ codecFor : ( c : ContentTypeId ) =>
774+ baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] ,
775+ } )
760776
761777 await bobConversation . getClient ( ) . publishEnvelopes (
762778 topics . map ( ( topic ) => ( {
@@ -768,9 +784,7 @@ describe('conversation', () => {
768784
769785 await sleep ( 100 )
770786
771- const [ aliceMessages ] = await Promise . all ( [
772- aliceConversation . messages ( ) ,
773- ] )
787+ const [ aliceMessages ] = await Promise . all ( [ aliceConversation . messages ( ) ] )
774788
775789 expect ( aliceMessages ) . toHaveLength ( 1 )
776790 expect ( aliceMessages [ 0 ] . messageVersion ) . toBe ( 'v1' )
@@ -795,22 +809,22 @@ describe('conversation', () => {
795809 alice . address
796810 )
797811 const baseCodecs = {
798- [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] : new TextCodec ( ) ,
812+ [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] :
813+ new TextCodec ( ) ,
799814 }
800815
801816 const stream = await Stream . create < DecodedMessageExport > (
802817 aliceConversation . getClient ( ) ,
803818 [ aliceConversation . topic ] ,
804819 async ( e ) => {
805820 const convo = deepcopy ( aliceConversation . export ( ) )
806- if ( convo . version !== 'v2' ) {
821+ if ( convo . version !== 'v2' ) {
807822 throw new Error ( 'unexpected convo version' )
808823 }
809- return await decodeMessageV2 (
810- e ,
811- convo ,
812- { codecFor : ( c : ContentTypeId ) => baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] }
813- )
824+ return await decodeMessageV2 ( e , convo , {
825+ codecFor : ( c : ContentTypeId ) =>
826+ baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] ,
827+ } )
814828 }
815829 )
816830
@@ -835,42 +849,42 @@ describe('conversation', () => {
835849 alice . address
836850 )
837851 const baseCodecs = {
838- [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] : new TextCodec ( ) ,
852+ [ `${ ContentTypeText . authorityId } /${ ContentTypeText . typeId } ` ] :
853+ new TextCodec ( ) ,
839854 }
840855
841856 const convo = bobConversation . export ( )
842- if ( convo . version !== 'v2' ) {
857+ if ( convo . version !== 'v2' ) {
843858 throw new Error ( 'unexpected convo version' )
844859 }
845860
846861 const msg = await encodeMessageV2 (
847- " Hi Alice!" ,
862+ ' Hi Alice!' ,
848863 deepcopy ( convo ) ,
849864 deepcopy ( bobConversation . getClient ( ) . keys ) ,
850- { codecFor : ( c : ContentTypeId ) => baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] } ,
865+ {
866+ codecFor : ( c : ContentTypeId ) =>
867+ baseCodecs [ `${ c . authorityId } /${ c . typeId } ` ] ,
868+ } ,
851869 undefined
852870 )
853871 await bobConversation . getClient ( ) . publishEnvelopes ( [
854872 {
855873 contentTopic : bobConversation . topic ,
856874 message : msg . toBytes ( ) ,
857875 timestamp : msg . sent ,
858- } ]
859- )
876+ } ,
877+ ] )
860878
861879 await sleep ( 100 )
862880
863- const [ aliceMessages ] = await Promise . all ( [
864- aliceConversation . messages ( ) ,
865- ] )
881+ const [ aliceMessages ] = await Promise . all ( [ aliceConversation . messages ( ) ] )
866882
867883 expect ( aliceMessages ) . toHaveLength ( 1 )
868884 expect ( aliceMessages [ 0 ] . messageVersion ) . toBe ( 'v2' )
869885 expect ( aliceMessages [ 0 ] . error ) . toBeUndefined ( )
870886 expect ( aliceMessages [ 0 ] . senderAddress ) . toBe ( bob . address )
871887 expect ( aliceMessages [ 0 ] . conversation . topic ) . toBe ( aliceConversation . topic )
872888 } )
873-
874889 } )
875-
876890} )
0 commit comments