Skip to content

Commit

Permalink
write react native side
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Jun 24, 2024
1 parent 82fa1a2 commit f3f0b5a
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,21 @@ class XMTPModule : Module() {
withContext(Dispatchers.IO) {
logV("findV3Message")
val client = clients[inboxId] ?: throw XMTPException("No client")
client.findMessage(Hex.hexStringToByteArray(messageId))
val message = client.findMessage(Hex.hexStringToByteArray(messageId))
message?.let {
DecodedMessageWrapper.encode(it.decrypt())
}
}
}

AsyncFunction("findGroup") Coroutine { inboxId: String, groupId: String ->
withContext(Dispatchers.IO) {
logV("findGroup")
val client = clients[inboxId] ?: throw XMTPException("No client")
client.findGroup(Hex.hexStringToByteArray(groupId))
val group = client.findGroup(Hex.hexStringToByteArray(groupId))
group?.let {
GroupWrapper.encode(client, it)
}
}
}

Expand Down
49 changes: 43 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ export function inboxId(): string {
return XMTPModule.inboxId()
}

export async function findInboxIdFromAddress(
inboxId: string,
address: string
): Promise<string> {
return XMTPModule.findInboxIdFromAddress(inboxId, address)
}

export async function deleteLocalDatabase(inboxId: string) {
return XMTPModule.deleteLocalDatabase(inboxId)
}
Expand All @@ -58,6 +65,10 @@ export async function reconnectLocalDatabase(inboxId: string) {
return XMTPModule.reconnectLocalDatabase(inboxId)
}

export async function requestMessageHistorySync(inboxId: string) {
return XMTPModule.requestMessageHistorySync(inboxId)
}

export async function auth(
inboxId: string,
environment: 'local' | 'dev' | 'production',
Expand All @@ -66,7 +77,8 @@ export async function auth(
hasEnableIdentityCallback?: boolean | undefined,
enableV3?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,
dbDirectory?: string | undefined
dbDirectory?: string | undefined,
historySyncUrl?: string | undefined
) {
return await XMTPModule.auth(
inboxId,
Expand All @@ -76,7 +88,8 @@ export async function auth(
hasEnableIdentityCallback,
enableV3,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,
dbDirectory
dbDirectory,
historySyncUrl
)
}

Expand All @@ -91,7 +104,8 @@ export async function createRandom(
hasEnableIdentityCallback?: boolean | undefined,
enableV3?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,
dbDirectory?: string | undefined
dbDirectory?: string | undefined,
historySyncUrl?: string | undefined
): Promise<string> {
return await XMTPModule.createRandom(
environment,
Expand All @@ -100,7 +114,8 @@ export async function createRandom(
hasEnableIdentityCallback,
enableV3,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,
dbDirectory
dbDirectory,
historySyncUrl
)
}

Expand All @@ -110,15 +125,17 @@ export async function createFromKeyBundle(
appVersion?: string | undefined,
enableV3?: boolean | undefined,
dbEncryptionKey?: Uint8Array | undefined,
dbDirectory?: string | undefined
dbDirectory?: string | undefined,
historySyncUrl?: string | undefined
): Promise<string> {
return await XMTPModule.createFromKeyBundle(
keyBundle,
environment,
appVersion,
enableV3,
dbEncryptionKey ? Array.from(dbEncryptionKey) : undefined,
dbDirectory
dbDirectory,
historySyncUrl
)
}

Expand Down Expand Up @@ -207,6 +224,26 @@ export async function groupMessages<
})
}

export async function findGroup<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
>(
client: Client<ContentTypes>,
groupId: string
): Promise<Group<ContentTypes> | undefined> {
const group = await XMTPModule.findGroup(client.inboxId, groupId)
return new Group(client, JSON.parse(group))
}

export async function findV3Message<
ContentTypes extends DefaultContentTypes = DefaultContentTypes,
>(
client: Client<ContentTypes>,
messageId: string
): Promise<DecodedMessage<ContentTypes> | undefined> {
const message = await XMTPModule.findV3Message(client.inboxId, messageId)
return DecodedMessage.from(message, client)
}

export async function syncGroups(inboxId: string) {
await XMTPModule.syncGroups(inboxId)
}
Expand Down

0 comments on commit f3f0b5a

Please sign in to comment.