diff --git a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt index d2808fb9a..41c7b0374 100644 --- a/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt +++ b/android/src/main/java/expo/modules/xmtpreactnativesdk/XMTPModule.kt @@ -247,7 +247,7 @@ class XMTPModule : Module() { findConversation(topic = topic, conversationId = conversationId) ?: return subscriptions[conversation.cacheKey] = CoroutineScope(Dispatchers.IO).launch { try { - conversation.streamMessages().collect() { message -> + conversation.streamMessages().collect { message -> sendEvent( "message", mapOf( diff --git a/example/src/ConversationView.tsx b/example/src/ConversationView.tsx index fd7f9d912..0eb82ecf7 100644 --- a/example/src/ConversationView.tsx +++ b/example/src/ConversationView.tsx @@ -67,19 +67,11 @@ export default function ConversationView({ route }: Props): JSX.Element { useEffect(() => { const unsubscribe = conversation.streamMessages(async (message) => { - const uniqueMessages = [ - ...new Map( - [message, ...messages].map((item: DecodedMessage) => [item.id, item]) - ).values(), - ].sort((a, b) => { - return a.sent > b.sent ? 1 : -1; - }); - - setMessages(uniqueMessages); + await loadMessages(); }); return unsubscribe; - }); + }, []); return ( <> diff --git a/src/index.ts b/src/index.ts index d2bc1a78d..a86b6e8a2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,7 +8,10 @@ export function address(): string { return XMTPModule.address(); } -export async function auth(address: string, environment: 'local' | 'dev' | 'production') { +export async function auth( + address: string, + environment: "local" | "dev" | "production" +) { return await XMTPModule.auth(address, environment); } @@ -16,7 +19,9 @@ export async function receiveSignature(requestID: string, signature: string) { return await XMTPModule.receiveSignature(requestID, signature); } -export async function createRandom(environment: 'local' | 'dev' | 'production'): Promise { +export async function createRandom( + environment: "local" | "dev" | "production" +): Promise { return await XMTPModule.createRandom(environment); } @@ -33,8 +38,15 @@ export async function listMessages( before?: Date | undefined, after?: Date | undefined ): Promise { - return (await XMTPModule.loadMessages(conversationTopic, conversationID, limit, before?.getTime, after?.getTime)).map( - (json: string) => { + return ( + await XMTPModule.loadMessages( + conversationTopic, + conversationID, + limit, + before?.getTime, + after?.getTime + ) + ).map((json: string) => { return JSON.parse(json); } ); diff --git a/src/lib/Client.ts b/src/lib/Client.ts index 2c25c154c..23bb94a99 100644 --- a/src/lib/Client.ts +++ b/src/lib/Client.ts @@ -8,7 +8,10 @@ export class Client { address: string; conversations: Conversations; - static async create(signer: Signer, environment: 'local' | 'dev' | 'production'): Promise { + static async create( + signer: Signer, + environment: "local" | "dev" | "production" + ): Promise { return new Promise((resolve, reject) => { (async () => { XMTPModule.emitter.addListener( @@ -40,7 +43,9 @@ export class Client { }); } - static async createRandom(environment: 'local' | 'dev' | 'production'): Promise { + static async createRandom( + environment: "local" | "dev" | "production" + ): Promise { const address = await XMTPModule.createRandom(environment); return new Client(address); } diff --git a/src/lib/Conversation.ts b/src/lib/Conversation.ts index 92fe44b10..b76219dc9 100644 --- a/src/lib/Conversation.ts +++ b/src/lib/Conversation.ts @@ -20,7 +20,11 @@ export class Conversation { } // TODO: Support pagination and conversation ID here - async messages(limit?: number | undefined, before?: Date | undefined, after?: Date | undefined): Promise { + async messages( + limit?: number | undefined, + before?: Date | undefined, + after?: Date | undefined + ): Promise { try { return await XMTP.listMessages(this.topic, this.conversationID, limit, before, after); } catch (e) {