mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-02-08 16:13:09 +00:00
fix: using ctx
This commit is contained in:
parent
0359d19e7b
commit
78d90b7b11
@ -73,7 +73,7 @@ registerReqFFI(CreateClientRequest, ctx: ptr FFIContext[Client]):
|
||||
proc(
|
||||
configJson: cstring, chatCallbacks: ChatCallbacks
|
||||
): Future[Result[string, string]] {.async.} =
|
||||
ctx[].myLib[] = (await createChatClient(configJson, chatCallbacks)).valueOr:
|
||||
ctx.myLib[] = (await createChatClient(configJson, chatCallbacks)).valueOr:
|
||||
error "CreateClientRequest failed", error = error
|
||||
return err($error)
|
||||
return ok("")
|
||||
@ -88,7 +88,7 @@ proc chat_start(
|
||||
userData: pointer
|
||||
) {.ffi.} =
|
||||
try:
|
||||
await ctx[].myLib[].start()
|
||||
await ctx.myLib[].start()
|
||||
return ok("")
|
||||
except CatchableError as e:
|
||||
error "chat_start failed", error = e.msg
|
||||
@ -100,7 +100,7 @@ proc chat_stop(
|
||||
userData: pointer
|
||||
) {.ffi.} =
|
||||
try:
|
||||
await ctx[].myLib[].stop()
|
||||
await ctx.myLib[].stop()
|
||||
return ok("")
|
||||
except CatchableError as e:
|
||||
error "chat_stop failed", error = e.msg
|
||||
@ -116,7 +116,7 @@ proc chat_get_id(
|
||||
userData: pointer
|
||||
) {.ffi.} =
|
||||
## Get the client's identifier
|
||||
let clientId = ctx[].myLib[].getId()
|
||||
let clientId = ctx.myLib[].getId()
|
||||
return ok(clientId)
|
||||
|
||||
proc chat_get_default_inbox_id(
|
||||
@ -125,7 +125,7 @@ proc chat_get_default_inbox_id(
|
||||
userData: pointer
|
||||
) {.ffi.} =
|
||||
## Get the default inbox conversation ID
|
||||
let inboxId = ctx[].myLib[].defaultInboxConversationId()
|
||||
let inboxId = ctx.myLib[].defaultInboxConversationId()
|
||||
return ok(inboxId)
|
||||
|
||||
#################################################
|
||||
@ -138,7 +138,7 @@ proc chat_list_conversations(
|
||||
userData: pointer
|
||||
) {.ffi.} =
|
||||
## List all conversations as JSON array
|
||||
let convos = ctx[].myLib[].listConversations()
|
||||
let convos = ctx.myLib[].listConversations()
|
||||
var convoList = newJArray()
|
||||
for convo in convos:
|
||||
convoList.add(%*{"id": convo.id()})
|
||||
@ -151,6 +151,6 @@ proc chat_get_conversation(
|
||||
convoId: cstring
|
||||
) {.ffi.} =
|
||||
## Get a specific conversation by ID
|
||||
let convo = ctx[].myLib[].getConversation($convoId)
|
||||
let convo = ctx.myLib[].getConversation($convoId)
|
||||
return ok($(%*{"id": convo.id()}))
|
||||
|
||||
|
||||
@ -44,7 +44,7 @@ proc chat_new_private_conversation(
|
||||
let content = hexToSeqByte($contentHex)
|
||||
|
||||
# Create the conversation
|
||||
let errOpt = await ctx[].myLib[].newPrivateConversation(introBundle, content)
|
||||
let errOpt = await ctx.myLib[].newPrivateConversation(introBundle, content)
|
||||
if errOpt.isSome():
|
||||
return err("failed to create conversation: " & $errOpt.get())
|
||||
|
||||
@ -68,7 +68,7 @@ proc chat_send_message(
|
||||
## convoId: Conversation ID string
|
||||
## contentHex: Message content as hex-encoded string
|
||||
try:
|
||||
let convo = ctx[].myLib[].getConversation($convoId)
|
||||
let convo = ctx.myLib[].getConversation($convoId)
|
||||
let content = hexToSeqByte($contentHex)
|
||||
|
||||
let msgId = await convo.sendMessage(content)
|
||||
|
||||
@ -26,7 +26,7 @@ proc chat_get_identity(
|
||||
) {.ffi.} =
|
||||
## Get the client identity
|
||||
## Returns JSON string: {"name": "...", "address": "...", "pubkey": "hex..."}
|
||||
let ident = ctx[].myLib[].identity()
|
||||
let ident = ctx.myLib[].identity()
|
||||
let identJson = %*{
|
||||
"name": ident.getName(),
|
||||
"address": ident.getAddr(),
|
||||
@ -45,7 +45,7 @@ proc chat_create_intro_bundle(
|
||||
) {.ffi.} =
|
||||
## Create an IntroBundle for initiating private conversations
|
||||
## Returns JSON string: {"ident": "hex...", "ephemeral": "hex..."}
|
||||
let bundle = ctx[].myLib[].createIntroBundle()
|
||||
let bundle = ctx.myLib[].createIntroBundle()
|
||||
let bundleJson = %*{
|
||||
"ident": bundle.ident.toHex(),
|
||||
"ephemeral": bundle.ephemeral.toHex()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user