mirror of
https://github.com/logos-messaging/logos-chat.git
synced 2026-02-27 20:33:07 +00:00
Contract interface for bindings
This commit is contained in:
parent
3921bd8bbd
commit
9cd25d4f53
@ -26,12 +26,9 @@ proc main() {.async.} =
|
||||
var waku_saro = initWakuClient(DefaultConfig())
|
||||
var waku_raya = initWakuClient(DefaultConfig())
|
||||
|
||||
let sKey = loadPrivateKeyFromBytes(@[45u8, 216, 160, 24, 19, 207, 193, 214, 98, 92, 153, 145, 222, 247, 101, 99, 96, 131, 149, 185, 33, 187, 229, 251, 100, 158, 20, 131, 111, 97, 181, 210]).get()
|
||||
let rKey = loadPrivateKeyFromBytes(@[43u8, 12, 160, 51, 212, 90, 199, 160, 154, 164, 129, 229, 147, 69, 151, 17, 239, 51, 190, 33, 86, 164, 50, 105, 39, 250, 182, 116, 138, 132, 114, 234]).get()
|
||||
|
||||
# Create Clients
|
||||
var saro = newClient(waku_saro, Identity(name: "saro", privateKey: sKey))
|
||||
var raya = newClient(waku_raya, Identity(name: "raya", privateKey: rKey))
|
||||
var saro = newClient(waku_saro).get()
|
||||
var raya = newClient(waku_raya).get()
|
||||
|
||||
# Wire Saro Callbacks
|
||||
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async, closure.} =
|
||||
|
||||
@ -62,7 +62,6 @@ type KeyEntry* = object
|
||||
type ChatClient* = ref object
|
||||
libchatCtx: LibChat
|
||||
ds*: WakuClient
|
||||
id: string
|
||||
inboundQueue: QueueRef
|
||||
isRunning: bool
|
||||
|
||||
@ -74,34 +73,38 @@ type ChatClient* = ref object
|
||||
# Constructors
|
||||
#################################################
|
||||
|
||||
proc newClient*(ds: WakuClient, ident: Identity): ChatClient {.raises: [IOError, ValueError].} =
|
||||
## Creates new instance of a `ChatClient` with a given `WakuConfig`
|
||||
## TODO: (P1) Currently the passed in Identity is not used. Libchat Generates one for every invocation.
|
||||
proc newClient*(ds: WakuClient, ephemeral: bool = true, installation_name: string = "default"): Result[ChatClient, string] =
|
||||
## Creates new instance of a `ChatClient` with a given `WakuConfig`.
|
||||
## A new installation is created if no saved installation with `installation_name` is found
|
||||
|
||||
if not ephemeral:
|
||||
return err("persistence is not currently supported")
|
||||
|
||||
try:
|
||||
|
||||
var q = QueueRef(queue: newAsyncQueue[ChatPayload](10))
|
||||
var c = ChatClient(
|
||||
libchatCtx: newConversationsContext(),
|
||||
ds: ds,
|
||||
id: ident.getName(),
|
||||
inboundQueue: q,
|
||||
isRunning: false,
|
||||
newMessageCallbacks: @[],
|
||||
newConvoCallbacks: @[])
|
||||
|
||||
|
||||
notice "Client started", client = c.id
|
||||
notice "Client started"
|
||||
|
||||
result = c
|
||||
result = ok(c)
|
||||
except Exception as e:
|
||||
error "newCLient", err = e.msg
|
||||
result = err(e.msg)
|
||||
|
||||
#################################################
|
||||
# Parameter Access
|
||||
#################################################
|
||||
|
||||
proc getId*(client: ChatClient): string =
|
||||
result = client.id
|
||||
result = "PLACEHOLDER_CLIENT_ID" # TODO: (!) get from Libchat.
|
||||
|
||||
|
||||
proc listConversations*(client: ChatClient): seq[Conversation] =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user