Skip to content

Commit

Permalink
feat: streamAll method and ConversationContainer interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cameronvoell committed Feb 14, 2024
1 parent 4816fd4 commit bbfe753
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
14 changes: 10 additions & 4 deletions example/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { content } from '@xmtp/proto'
import ReactNativeBlobUtil from 'react-native-blob-util'
import { TextEncoder, TextDecoder } from 'text-encoding'
import { DecodedMessage } from 'xmtp-react-native-sdk/lib/DecodedMessage'
import { DefaultContentTypes } from 'xmtp-react-native-sdk/lib/types/DefaultContentType'

Check warning on line 5 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

'DefaultContentTypes' is defined but never used

import {
Query,
Expand All @@ -15,7 +16,6 @@ import {
ConversationContainer,
ConversationVersion,
} from '../../src/index'
import { DefaultContentTypes } from 'xmtp-react-native-sdk/lib/types/DefaultContentType'

type EncodedContent = content.EncodedContent
type ContentTypeId = content.ContentTypeId
Expand Down Expand Up @@ -612,7 +612,7 @@ test('can stream all groups and conversations', async () => {
throw Error('Unexpected num groups (should be 1): ' + containers.length)
}
if (containers[0].version === ConversationVersion.GROUP) {
(containers[0] as Group).sync()
;(containers[0] as Group).sync()
} else {
console.log(JSON.stringify(containers[0] as Group))
throw Error('Unexpected first ConversationContainer should be a group')
Expand All @@ -628,8 +628,14 @@ test('can stream all groups and conversations', async () => {
throw Error('Unexpected num groups (should be 2): ' + containers.length)
}

if(containers[1].version === ConversationVersion.DIRECT && bobConversation.conversationID != (containers[1] as Conversation<any>).conversationID) {
throw Error('Conversation from streamed all should match conversationID with created conversation')
if (
containers[1].version === ConversationVersion.DIRECT &&
bobConversation.conversationID !=

Check warning on line 633 in example/src/tests.ts

View workflow job for this annotation

GitHub Actions / lint

Expected '!==' and instead saw '!='
(containers[1] as Conversation<any>).conversationID
) {
throw Error(
'Conversation from streamed all should match conversationID with created conversation'
)
}

// * Note Alice creating a v2 Conversation does trigger alice conversations
Expand Down
5 changes: 4 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,10 @@ export * from './XMTP.types'
export { Client } from './lib/Client'
export * from './lib/ContentCodec'
export { Conversation } from './lib/Conversation'
export { ConversationContainer, ConversationVersion } from './lib/ConversationContainer'
export {
ConversationContainer,
ConversationVersion,
} from './lib/ConversationContainer'
export { Query } from './lib/Query'
export { XMTPPush } from './lib/XMTPPush'
export { ConsentListEntry, DecodedMessage }
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import {
} from './ConversationContainer'
import { ConversationSendPayload } from './types/ConversationCodecs'
import { DefaultContentTypes } from './types/DefaultContentType'
import { SendOptions } from './types/SendOptions'
import * as XMTP from '../index'
import {
ConversationContext,
DecodedMessage,
PreparedLocalMessage,
} from '../index'
import { SendOptions } from './types/SendOptions'

export class Conversation<ContentTypes extends DefaultContentTypes>
implements ConversationContainer<ContentTypes>
Expand Down
4 changes: 2 additions & 2 deletions src/lib/ConversationContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { DefaultContentTypes } from './types/DefaultContentType'
import * as XMTP from '../index'

export enum ConversationVersion {
DIRECT = "DIRECT",
GROUP = "GROUP"
DIRECT = 'DIRECT',
GROUP = 'GROUP',
}

export interface ConversationContainer<
Expand Down
4 changes: 2 additions & 2 deletions src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
import { DecodedMessage } from './DecodedMessage'
import { ConversationSendPayload } from './types/ConversationCodecs'
import { DefaultContentTypes } from './types/DefaultContentType'
import * as XMTP from '../index'
import { SendOptions } from './types/SendOptions'
import * as XMTP from '../index'

export class Group<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
Expand Down Expand Up @@ -134,7 +134,7 @@ export class Group<
async removeMembers(addresses: string[]): Promise<void> {
return XMTP.removeGroupMembers(this.client.address, this.id, addresses)
}

isActive(): boolean {
return XMTP.isGroupActive(this.client.address, this.id)
}
Expand Down

0 comments on commit bbfe753

Please sign in to comment.