Skip to content

Commit

Permalink
do the android side
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Dec 9, 2024
1 parent 9834035 commit 86d6983
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,26 @@ class XMTPModule : Module() {
}
}

AsyncFunction("sendEncodedContent") Coroutine { installationId: String, conversationId: String, encodedContentData: List<Int> ->
withContext(Dispatchers.IO) {
logV("sendEncodedContent")
val client = clients[installationId] ?: throw XMTPException("No client")
val conversation = client.findConversation(conversationId)
?: throw XMTPException("no conversation found for $conversationId")
val encodedContentDataBytes =
encodedContentData.foldIndexed(ByteArray(encodedContentData.size)) { i, a, v ->
a.apply {
set(
i,
v.toByte()
)
}
}
val encodedContent = EncodedContent.parseFrom(encodedContentDataBytes)
conversation.send(encodedContent)
}
}

AsyncFunction("sendMessage") Coroutine { installationId: String, id: String, contentJson: String ->
withContext(Dispatchers.IO) {
logV("sendMessage")
Expand Down
23 changes: 23 additions & 0 deletions ios/XMTPModule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,29 @@ public class XMTPModule: Module {
return nil
}
}

AsyncFunction("sendEncodedContent") {
(
installationId: String, conversationId: String,
encodedContentData: [UInt8]
) -> String in
guard
let client = await clientsManager.getClient(key: installationId)
else {
throw Error.noClient
}
guard
let conversation = try client.findConversation(
conversationId: conversationId)
else {
throw Error.conversationNotFound(
"no conversation found for \(conversationId)")
}
let encodedContent = try EncodedContent(
serializedBytes: Data(encodedContentData))

return try await conversation.send(encodedContent: encodedContent)
}

AsyncFunction("sendMessage") {
(installationId: String, id: String, contentJson: String) -> String
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ export async function findDmByAddress<
}

export async function sendWithContentType<T>(
inboxId: InboxId,
installationId: InboxId,
conversationId: ConversationId,
content: T,
codec: ContentCodec<T>
Expand All @@ -549,7 +549,7 @@ export async function sendWithContentType<T>(
const encodedContentData = EncodedContent.encode(encodedContent).finish()

return await XMTPModule.sendEncodedContent(
inboxId,
installationId,
conversationId,
Array.from(encodedContentData)
)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Dm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class Dm<ContentTypes extends DefaultContentTypes = DefaultContentTypes>
}

return await XMTP.sendWithContentType(
this.client.inboxId,
this.client.installationId,
this.id,
content,
codec
Expand Down
2 changes: 1 addition & 1 deletion src/lib/Group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export class Group<
}

return await XMTP.sendWithContentType(
this.client.inboxId,
this.client.installationId,
this.id,
content,
codec
Expand Down

0 comments on commit 86d6983

Please sign in to comment.