From 5fbe422ce3aed8b45d84cfb1ddac6c9066cb9ca1 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Wed, 26 Nov 2025 16:51:31 -0800 Subject: [PATCH] Remove WakuClient from convo.sendMessage --- examples/pingpong.nim | 10 +++++----- src/chat_sdk/client.nim | 2 +- src/chat_sdk/conversations/convo_type.nim | 4 +--- src/chat_sdk/conversations/private_v1.nim | 18 +++++++++--------- src/chat_sdk/inbox.nim | 5 ++--- 5 files changed, 18 insertions(+), 21 deletions(-) diff --git a/examples/pingpong.nim b/examples/pingpong.nim index 7f557c7..99ef647 100644 --- a/examples/pingpong.nim +++ b/examples/pingpong.nim @@ -39,7 +39,7 @@ proc main() {.async.} = saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} = echo " Saro <------ :: " & getContent(msg.content) await sleepAsync(5000.milliseconds) - discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame()) + discard await convo.sendMessage(initTextFrame("Ping").toContentFrame()) ) @@ -53,17 +53,17 @@ proc main() {.async.} = raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} = echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content) await sleepAsync(500.milliseconds) - discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame()) + discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame()) await sleepAsync(800.milliseconds) - discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame()) + discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame()) await sleepAsync(500.milliseconds) - discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame()) + discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame()) inc ri ) raya.onNewConversation(proc(convo: Conversation) {.async.} = echo " ------> Raya :: New Conversation: " & convo.id() - discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame()) + discard await convo.sendMessage(initTextFrame("Hello").toContentFrame()) ) raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} = echo " raya -- Read Receipt for " & msgId diff --git a/src/chat_sdk/client.nim b/src/chat_sdk/client.nim index b816a39..ee52046 100644 --- a/src/chat_sdk/client.nim +++ b/src/chat_sdk/client.nim @@ -218,7 +218,7 @@ proc newPrivateConversation*(client: Client, var key : array[32, byte] key[2]=2 - var convo = initPrivateV1Sender(client.identity(), destPubkey, key, deliveryAckCb) + var convo = initPrivateV1Sender(client.identity(), client.ds, destPubkey, key, deliveryAckCb) client.addConversation(convo) # TODO: Subscribe to new content topic diff --git a/src/chat_sdk/conversations/convo_type.nim b/src/chat_sdk/conversations/convo_type.nim index 3be91c1..d497fd9 100644 --- a/src/chat_sdk/conversations/convo_type.nim +++ b/src/chat_sdk/conversations/convo_type.nim @@ -3,7 +3,6 @@ import strformat import strutils import ../proto_types -import ../delivery/waku_client import ../utils import ../types @@ -25,7 +24,6 @@ method id*(self: Conversation): string {.raises: [Defect, ValueError].} = # TODO: make this a compile time check panic("ProgramError: Missing concrete implementation") -method sendMessage*(convo: Conversation, ds: WakuClient, - content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} = +method sendMessage*(convo: Conversation, content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} = # TODO: make this a compile time check panic("ProgramError: Missing concrete implementation") diff --git a/src/chat_sdk/conversations/private_v1.nim b/src/chat_sdk/conversations/private_v1.nim index 543704e..7554bc9 100644 --- a/src/chat_sdk/conversations/private_v1.nim +++ b/src/chat_sdk/conversations/private_v1.nim @@ -34,7 +34,7 @@ proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFr type PrivateV1* = ref object of Conversation - # Placeholder for PrivateV1 conversation type + ds: WakuClient sdsClient: ReliabilityManager owner: Identity topic: string @@ -126,7 +126,7 @@ proc wireCallbacks(convo: PrivateV1, deliveryAckCb: proc( -proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, byte], +proc initPrivateV1*(owner: Identity, ds:WakuClient, participant: PublicKey, seedKey: array[32, byte], discriminator: string = "default", isSender: bool, deliveryAckCb: proc( conversation: Conversation, msgId: string): Future[void] {.async.} = nil): @@ -138,6 +138,7 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, raise newException(ValueError, fmt"sds initialization: {repr(error)}") result = PrivateV1( + ds: ds, sdsClient: rm, owner: owner, topic: derive_topic(participants, discriminator), @@ -152,13 +153,13 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, raise newException(ValueError, "bad sds channel") -proc initPrivateV1Sender*(owner:Identity, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc( +proc initPrivateV1Sender*(owner:Identity, ds: WakuClient, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc( conversation: Conversation, msgId: string): Future[void] {.async.} = nil): PrivateV1 = - initPrivateV1(owner, participant, seedKey, "default", true, deliveryAckCb) + initPrivateV1(owner, ds, participant, seedKey, "default", true, deliveryAckCb) -proc initPrivateV1Recipient*(owner:Identity, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc( +proc initPrivateV1Recipient*(owner:Identity,ds: WakuClient, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc( conversation: Conversation, msgId: string): Future[void] {.async.} = nil): PrivateV1 = - initPrivateV1(owner, participant, seedKey, "default", false, deliveryAckCb) + initPrivateV1(owner,ds, participant, seedKey, "default", false, deliveryAckCb) proc sendFrame(self: PrivateV1, ds: WakuClient, @@ -216,14 +217,13 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T, notice "Got Placeholder", text = frame.placeholder.counter -method sendMessage*(convo: PrivateV1, ds: WakuClient, - content_frame: ContentFrame) : Future[MessageId] {.async.} = +method sendMessage*(convo: PrivateV1, content_frame: ContentFrame) : Future[MessageId] {.async.} = try: let frame = PrivateV1Frame(sender: @(convo.owner.getPubkey().bytes()), timestamp: getCurrentTimestamp(), content: content_frame) - result = await convo.sendFrame(ds, frame) + result = await convo.sendFrame(convo.ds, frame) except Exception as e: error "Unknown error in PrivateV1:SendMessage" diff --git a/src/chat_sdk/inbox.nim b/src/chat_sdk/inbox.nim index e94335d..14beed2 100644 --- a/src/chat_sdk/inbox.nim +++ b/src/chat_sdk/inbox.nim @@ -81,7 +81,7 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T, var key : array[32, byte] key[2]=2 - let convo = initPrivateV1Recipient(client.identity(), destPubkey, key, deliveryAckCb) + let convo = initPrivateV1Recipient(client.identity(), client.ds, destPubkey, key, deliveryAckCb) notice "Creating PrivateV1 conversation", client = client.getId(), topic = convo.getConvoId() client.addConversation(convo) @@ -107,7 +107,6 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[ notice "Receive Note", client = client.getId(), text = frame.note.text -method sendMessage*(convo: Inbox, ds: WakuClient, - content_frame: ContentFrame) : Future[MessageId] {.async.} = +method sendMessage*(convo: Inbox, content_frame: ContentFrame) : Future[MessageId] {.async.} = warn "Cannot send message to Inbox" result = "program_error"