Skip to content

Commit

Permalink
Revert "wip"
Browse files Browse the repository at this point in the history
This reverts commit fe69a54.
  • Loading branch information
nakajima committed Sep 21, 2023
1 parent d5f5c21 commit 2fd86e9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 54 deletions.
57 changes: 11 additions & 46 deletions example/src/LaunchScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function LaunchScreen({
let savedKeys = useSavedKeys();
const configureWallet = (
label: string,
configuring: Promise<XMTP.Client>
configuring: Promise<XMTP.Client>,
) => {
console.log("Connecting XMTP client", label);
configuring
Expand Down Expand Up @@ -73,8 +73,8 @@ export default function LaunchScreen({
color="green"
onPress={() => {
configureWallet(
"dev",
XMTP.Client.createRandom({ env: "dev", appVersion })
'dev',
XMTP.Client.createRandom({ env: 'dev', appVersion }),
);
}}
/>
Expand All @@ -85,8 +85,8 @@ export default function LaunchScreen({
color="purple"
onPress={() => {
configureWallet(
"local",
XMTP.Client.createRandom({ env: "local", appVersion })
'local',
XMTP.Client.createRandom({ env: 'local', appVersion }),
);
}}
/>
Expand All @@ -112,11 +112,11 @@ export default function LaunchScreen({
color="green"
onPress={() => {
configureWallet(
"dev",
'dev',
XMTP.Client.createFromKeyBundle(savedKeys.keyBundle!, {
env: "dev",
env: 'dev',
appVersion,
})
}),
);
}}
/>
Expand All @@ -127,11 +127,11 @@ export default function LaunchScreen({
color="purple"
onPress={() => {
configureWallet(
"local",
'local',
XMTP.Client.createFromKeyBundle(savedKeys.keyBundle!, {
env: "local",
env: 'local',
appVersion,
})
}),
);
}}
/>
Expand All @@ -145,41 +145,6 @@ export default function LaunchScreen({
</View>
</>
)}

<Button
title="Test Stream"
onPress={async () => {
console.log("testing streamsies");
const client1 = await XMTP.Client.createRandom();
const client2 = await XMTP.Client.createRandom();
const client3 = await XMTP.Client.createRandom();

const convo1 = await client3.conversations.newConversation(
client1.address
);

const convo2 = await client3.conversations.newConversation(
client2.address
);

await Promise.all([
client1.conversations.streamAllMessages(async (message) => {
console.log("client1 message", message);
}),

client2.conversations.streamAllMessages(async (message) => {
console.log("client2 message", message);
}),

async () => {
setTimeout(async () => {
console.log("sending message");
await convo1.send("hi");
}, 1000);
},
]);
}}
/>
</ScrollView>
);
}
Expand Down
14 changes: 6 additions & 8 deletions src/lib/Conversations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ export default class Conversations {
async importTopicData(topicData: string): Promise<Conversation> {
const conversation = await XMTPModule.importConversationTopicData(
this.client.address,
topicData
topicData,
);
this.known[conversation.topic] = true;
return conversation;
}

async newConversation(
peerAddress: string,
context?: ConversationContext
context?: ConversationContext,
): Promise<Conversation> {
return await XMTPModule.createConversation(
this.client.address,
peerAddress,
context
context,
);
}

Expand All @@ -61,12 +61,12 @@ export default class Conversations {

this.known[conversation.topic] = true;
await callback(new Conversation(conversation));
}
},
);
}

async streamAllMessages(
callback: (message: DecodedMessage) => Promise<void>
callback: (message: DecodedMessage) => Promise<void>,
) {
XMTPModule.subscribeToAllMessages(this.client.address);
XMTPModule.emitter.addListener(
Expand All @@ -79,17 +79,15 @@ export default class Conversations {
message: DecodedMessage;
}) => {
if (clientAddress !== this.client.address) {
console.log("client address doesnt match this client address");
return;
}
if (this.known[message.id]) {
console.log("known contains message id");
return;
}

this.known[message.id] = true;
await callback(message as DecodedMessage);
}
},
);
}

Expand Down

0 comments on commit 2fd86e9

Please sign in to comment.