fix: rename Client to ChatClient

This commit is contained in:
pablo 2026-01-12 18:16:01 +02:00
parent 78d90b7b11
commit ce0f4e2aae
No known key found for this signature in database
GPG Key ID: 78F35FCC60FDC63A
6 changed files with 45 additions and 45 deletions

View File

@ -26,7 +26,7 @@ type ChatCallbacks* = object
proc createChatClient(
configJson: cstring, chatCallbacks: ChatCallbacks
): Future[Result[Client, string]] {.async.} =
): Future[Result[ChatClient, string]] {.async.} =
try:
let config = parseJson($configJson)
@ -69,7 +69,7 @@ proc createChatClient(
except CatchableError as e:
return err("failed to create client: " & e.msg)
registerReqFFI(CreateClientRequest, ctx: ptr FFIContext[Client]):
registerReqFFI(CreateClientRequest, ctx: ptr FFIContext[ChatClient]):
proc(
configJson: cstring, chatCallbacks: ChatCallbacks
): Future[Result[string, string]] {.async.} =
@ -79,11 +79,11 @@ registerReqFFI(CreateClientRequest, ctx: ptr FFIContext[Client]):
return ok("")
#################################################
# Client Lifecycle Operations
# ChatClient Lifecycle Operations
#################################################
proc chat_start(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -95,7 +95,7 @@ proc chat_start(
return err("failed to start client: " & e.msg)
proc chat_stop(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -107,11 +107,11 @@ proc chat_stop(
return err("failed to stop client: " & e.msg)
#################################################
# Client Info Operations
# ChatClient Info Operations
#################################################
proc chat_get_id(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -120,7 +120,7 @@ proc chat_get_id(
return ok(clientId)
proc chat_get_default_inbox_id(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -133,7 +133,7 @@ proc chat_get_default_inbox_id(
#################################################
proc chat_list_conversations(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -145,7 +145,7 @@ proc chat_list_conversations(
return ok($convoList)
proc chat_get_conversation(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer,
convoId: cstring

View File

@ -19,7 +19,7 @@ logScope:
#################################################
proc chat_new_private_conversation(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer,
introBundleJson: cstring,
@ -58,7 +58,7 @@ proc chat_new_private_conversation(
#################################################
proc chat_send_message(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer,
convoId: cstring,

View File

@ -20,7 +20,7 @@ logScope:
#################################################
proc chat_get_identity(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =
@ -39,7 +39,7 @@ proc chat_get_identity(
#################################################
proc chat_create_intro_bundle(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.ffi.} =

View File

@ -4,7 +4,7 @@ import src/chat/client
declareLibrary("chat")
proc set_event_callback(
ctx: ptr FFIContext[Client],
ctx: ptr FFIContext[ChatClient],
callback: FFICallBack,
userData: pointer
) {.dynlib, exportc, cdecl.} =

View File

@ -34,20 +34,20 @@ proc chat_new(
): pointer {.dynlib, exportc, cdecl.} =
initializeLibrary()
## Creates a new instance of the Chat Client.
## Creates a new instance of the ChatClient.
if isNil(callback):
echo "error: missing callback in chat_new"
return nil
## Create the Chat thread that will keep waiting for req from the main thread.
var ctx = ffi.createFFIContext[Client]().valueOr:
var ctx = ffi.createFFIContext[ChatClient]().valueOr:
let msg = "Error in createFFIContext: " & $error
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData)
return nil
ctx.userData = userData
proc onNewMessage(ctx: ptr FFIContext[Client]): MessageCallback =
proc onNewMessage(ctx: ptr FFIContext[ChatClient]): MessageCallback =
return proc(conversation: Conversation, msg: ReceivedMessage): Future[void] {.async.} =
callEventCallback(ctx, "onNewMessage"):
$newJsonMessageEvent(
@ -57,12 +57,12 @@ proc chat_new(
msg.timestamp
)
proc onNewConversation(ctx: ptr FFIContext[Client]): NewConvoCallback =
proc onNewConversation(ctx: ptr FFIContext[ChatClient]): NewConvoCallback =
return proc(conversation: Conversation): Future[void] {.async.} =
callEventCallback(ctx, "onNewConversation"):
$newJsonConversationEvent(conversation.id(), "private")
proc onDeliveryAck(ctx: ptr FFIContext[Client]): DeliveryAckCallback =
proc onDeliveryAck(ctx: ptr FFIContext[ChatClient]): DeliveryAckCallback =
return proc(conversation: Conversation, msgId: MessageId): Future[void] {.async.} =
callEventCallback(ctx, "onDeliveryAck"):
$newJsonDeliveryAckEvent(conversation.id(), msgId)
@ -83,7 +83,7 @@ proc chat_new(
return ctx
proc chat_destroy(
ctx: ptr FFIContext[Client], callback: FFICallBack, userData: pointer
ctx: ptr FFIContext[ChatClient], callback: FFICallBack, userData: pointer
): cint {.dynlib, exportc, cdecl.} =
initializeLibrary()
checkParams(ctx, callback, userData)

View File

@ -47,7 +47,7 @@ type KeyEntry* = object
privateKey: PrivateKey
timestamp: int64
type Client* = ref object
type ChatClient* = ref object
ident: Identity
ds*: WakuClient
keyStore: Table[string, KeyEntry] # Keyed by HexEncoded Public Key
@ -64,9 +64,9 @@ type Client* = ref object
# Constructors
#################################################
proc newClient*(ds: WakuClient, ident: Identity): Client {.raises: [IOError,
proc newClient*(ds: WakuClient, ident: Identity): ChatClient {.raises: [IOError,
ValueError, SerializationError].} =
## Creates new instance of a `Client` with a given `WakuConfig`
## Creates new instance of a `ChatClient` with a given `WakuConfig`
try:
let rm = newReliabilityManager().valueOr:
raise newException(ValueError, fmt"SDS InitializationError")
@ -74,7 +74,7 @@ proc newClient*(ds: WakuClient, ident: Identity): Client {.raises: [IOError,
let defaultInbox = initInbox(ident)
var q = QueueRef(queue: newAsyncQueue[ChatPayload](10))
var c = Client(ident: ident,
var c = ChatClient(ident: ident,
ds: ds,
keyStore: initTable[string, KeyEntry](),
conversations: initTable[string, Conversation](),
@ -96,17 +96,17 @@ proc newClient*(ds: WakuClient, ident: Identity): Client {.raises: [IOError,
# Parameter Access
#################################################
proc getId*(client: Client): string =
proc getId*(client: ChatClient): string =
result = client.ident.getName()
proc identity*(client: Client): Identity =
proc identity*(client: ChatClient): Identity =
result = client.ident
proc defaultInboxConversationId*(self: Client): string =
proc defaultInboxConversationId*(self: ChatClient): string =
## Returns the default inbox address for the client.
result = conversationIdFor(self.ident.getPubkey())
proc getConversationFromHint(self: Client,
proc getConversationFromHint(self: ChatClient,
conversationHint: string): Result[Option[Conversation], string] =
# TODO: Implementing Hinting
@ -116,31 +116,31 @@ proc getConversationFromHint(self: Client,
ok(some(self.conversations[conversationHint]))
proc listConversations*(client: Client): seq[Conversation] =
proc listConversations*(client: ChatClient): seq[Conversation] =
result = toSeq(client.conversations.values())
#################################################
# Callback Handling
#################################################
proc onNewMessage*(client: Client, callback: MessageCallback) =
proc onNewMessage*(client: ChatClient, callback: MessageCallback) =
client.newMessageCallbacks.add(callback)
proc notifyNewMessage*(client: Client, convo: Conversation, msg: ReceivedMessage) =
proc notifyNewMessage*(client: ChatClient, convo: Conversation, msg: ReceivedMessage) =
for cb in client.newMessageCallbacks:
discard cb(convo, msg)
proc onNewConversation*(client: Client, callback: NewConvoCallback) =
proc onNewConversation*(client: ChatClient, callback: NewConvoCallback) =
client.newConvoCallbacks.add(callback)
proc notifyNewConversation(client: Client, convo: Conversation) =
proc notifyNewConversation(client: ChatClient, convo: Conversation) =
for cb in client.newConvoCallbacks:
discard cb(convo)
proc onDeliveryAck*(client: Client, callback: DeliveryAckCallback) =
proc onDeliveryAck*(client: ChatClient, callback: DeliveryAckCallback) =
client.deliveryAckCallbacks.add(callback)
proc notifyDeliveryAck(client: Client, convo: Conversation,
proc notifyDeliveryAck(client: ChatClient, convo: Conversation,
messageId: MessageId) =
for cb in client.deliveryAckCallbacks:
discard cb(convo, messageId)
@ -149,7 +149,7 @@ proc notifyDeliveryAck(client: Client, convo: Conversation,
# Functional
#################################################
proc createIntroBundle*(self: var Client): IntroBundle =
proc createIntroBundle*(self: var ChatClient): IntroBundle =
## Generates an IntroBundle for the client, which includes
## the required information to send a message.
@ -175,16 +175,16 @@ proc createIntroBundle*(self: var Client): IntroBundle =
# Conversation Initiation
#################################################
proc addConversation*(client: Client, convo: Conversation) =
proc addConversation*(client: ChatClient, convo: Conversation) =
notice "Creating conversation", client = client.getId(), convoId = convo.id()
client.conversations[convo.id()] = convo
client.notifyNewConversation(convo)
proc getConversation*(client: Client, convoId: string): Conversation =
proc getConversation*(client: ChatClient, convoId: string): Conversation =
notice "Get conversation", client = client.getId(), convoId = convoId
result = client.conversations[convoId]
proc newPrivateConversation*(client: Client,
proc newPrivateConversation*(client: ChatClient,
introBundle: IntroBundle, content: Content): Future[Option[ChatError]] {.async.} =
## Creates a private conversation with the given `IntroBundle`.
## `IntroBundles` are provided out-of-band.
@ -202,7 +202,7 @@ proc newPrivateConversation*(client: Client,
# Receives a incoming payload, decodes it, and processes it.
#################################################
proc parseMessage(client: Client, msg: ChatPayload) {.raises: [ValueError,
proc parseMessage(client: ChatClient, msg: ChatPayload) {.raises: [ValueError,
SerializationError].} =
let envelopeRes = decode(msg.bytes, WapEnvelopeV1)
if envelopeRes.isErr:
@ -231,7 +231,7 @@ proc parseMessage(client: Client, msg: ChatPayload) {.raises: [ValueError,
# Async Tasks
#################################################
proc messageQueueConsumer(client: Client) {.async.} =
proc messageQueueConsumer(client: ChatClient) {.async.} =
## Main message processing loop
info "Message listener started"
@ -257,8 +257,8 @@ proc messageQueueConsumer(client: Client) {.async.} =
# Control Functions
#################################################
proc start*(client: Client) {.async.} =
## Start `Client` and listens for incoming messages.
proc start*(client: ChatClient) {.async.} =
## Start `ChatClient` and listens for incoming messages.
client.ds.addDispatchQueue(client.inboundQueue)
asyncSpawn client.ds.start()
@ -268,7 +268,7 @@ proc start*(client: Client) {.async.} =
notice "Client start complete", client = client.getId()
proc stop*(client: Client) {.async.} =
proc stop*(client: ChatClient) {.async.} =
## Stop the client.
await client.ds.stop()
client.isRunning = false