Skip to content

Commit 5fbe422

Browse files
committed
Remove WakuClient from convo.sendMessage
1 parent 26c4131 commit 5fbe422

File tree

5 files changed

+18
-21
lines changed

5 files changed

+18
-21
lines changed

examples/pingpong.nim

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ proc main() {.async.} =
3939
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
4040
echo " Saro <------ :: " & getContent(msg.content)
4141
await sleepAsync(5000.milliseconds)
42-
discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame())
42+
discard await convo.sendMessage(initTextFrame("Ping").toContentFrame())
4343

4444
)
4545

@@ -53,17 +53,17 @@ proc main() {.async.} =
5353
raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} =
5454
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
5555
await sleepAsync(500.milliseconds)
56-
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
56+
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
5757
await sleepAsync(800.milliseconds)
58-
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
58+
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
5959
await sleepAsync(500.milliseconds)
60-
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
60+
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
6161
inc ri
6262
)
6363

6464
raya.onNewConversation(proc(convo: Conversation) {.async.} =
6565
echo " ------> Raya :: New Conversation: " & convo.id()
66-
discard await convo.sendMessage(raya.ds, initTextFrame("Hello").toContentFrame())
66+
discard await convo.sendMessage(initTextFrame("Hello").toContentFrame())
6767
)
6868
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
6969
echo " raya -- Read Receipt for " & msgId

src/chat_sdk/client.nim

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ proc newPrivateConversation*(client: Client,
218218
var key : array[32, byte]
219219
key[2]=2
220220

221-
var convo = initPrivateV1Sender(client.identity(), destPubkey, key, deliveryAckCb)
221+
var convo = initPrivateV1Sender(client.identity(), client.ds, destPubkey, key, deliveryAckCb)
222222
client.addConversation(convo)
223223

224224
# TODO: Subscribe to new content topic

src/chat_sdk/conversations/convo_type.nim

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import strformat
33
import strutils
44

55
import ../proto_types
6-
import ../delivery/waku_client
76
import ../utils
87
import ../types
98

@@ -25,7 +24,6 @@ method id*(self: Conversation): string {.raises: [Defect, ValueError].} =
2524
# TODO: make this a compile time check
2625
panic("ProgramError: Missing concrete implementation")
2726

28-
method sendMessage*(convo: Conversation, ds: WakuClient,
29-
content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} =
27+
method sendMessage*(convo: Conversation, content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} =
3028
# TODO: make this a compile time check
3129
panic("ProgramError: Missing concrete implementation")

src/chat_sdk/conversations/private_v1.nim

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFr
3434

3535
type
3636
PrivateV1* = ref object of Conversation
37-
# Placeholder for PrivateV1 conversation type
37+
ds: WakuClient
3838
sdsClient: ReliabilityManager
3939
owner: Identity
4040
topic: string
@@ -126,7 +126,7 @@ proc wireCallbacks(convo: PrivateV1, deliveryAckCb: proc(
126126

127127

128128

129-
proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32, byte],
129+
proc initPrivateV1*(owner: Identity, ds:WakuClient, participant: PublicKey, seedKey: array[32, byte],
130130
discriminator: string = "default", isSender: bool, deliveryAckCb: proc(
131131
conversation: Conversation,
132132
msgId: string): Future[void] {.async.} = nil):
@@ -138,6 +138,7 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32,
138138
raise newException(ValueError, fmt"sds initialization: {repr(error)}")
139139

140140
result = PrivateV1(
141+
ds: ds,
141142
sdsClient: rm,
142143
owner: owner,
143144
topic: derive_topic(participants, discriminator),
@@ -152,13 +153,13 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32,
152153
raise newException(ValueError, "bad sds channel")
153154

154155

155-
proc initPrivateV1Sender*(owner:Identity, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc(
156+
proc initPrivateV1Sender*(owner:Identity, ds: WakuClient, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc(
156157
conversation: Conversation, msgId: string): Future[void] {.async.} = nil): PrivateV1 =
157-
initPrivateV1(owner, participant, seedKey, "default", true, deliveryAckCb)
158+
initPrivateV1(owner, ds, participant, seedKey, "default", true, deliveryAckCb)
158159

159-
proc initPrivateV1Recipient*(owner:Identity, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc(
160+
proc initPrivateV1Recipient*(owner:Identity,ds: WakuClient, participant: PublicKey, seedKey: array[32, byte], deliveryAckCb: proc(
160161
conversation: Conversation, msgId: string): Future[void] {.async.} = nil): PrivateV1 =
161-
initPrivateV1(owner, participant, seedKey, "default", false, deliveryAckCb)
162+
initPrivateV1(owner,ds, participant, seedKey, "default", false, deliveryAckCb)
162163

163164

164165
proc sendFrame(self: PrivateV1, ds: WakuClient,
@@ -216,14 +217,13 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
216217
notice "Got Placeholder", text = frame.placeholder.counter
217218

218219

219-
method sendMessage*(convo: PrivateV1, ds: WakuClient,
220-
content_frame: ContentFrame) : Future[MessageId] {.async.} =
220+
method sendMessage*(convo: PrivateV1, content_frame: ContentFrame) : Future[MessageId] {.async.} =
221221

222222
try:
223223
let frame = PrivateV1Frame(sender: @(convo.owner.getPubkey().bytes()),
224224
timestamp: getCurrentTimestamp(), content: content_frame)
225225

226-
result = await convo.sendFrame(ds, frame)
226+
result = await convo.sendFrame(convo.ds, frame)
227227
except Exception as e:
228228
error "Unknown error in PrivateV1:SendMessage"
229229

src/chat_sdk/inbox.nim

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T,
8181
var key : array[32, byte]
8282
key[2]=2
8383

84-
let convo = initPrivateV1Recipient(client.identity(), destPubkey, key, deliveryAckCb)
84+
let convo = initPrivateV1Recipient(client.identity(), client.ds, destPubkey, key, deliveryAckCb)
8585
notice "Creating PrivateV1 conversation", client = client.getId(),
8686
topic = convo.getConvoId()
8787
client.addConversation(convo)
@@ -107,7 +107,6 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[
107107
notice "Receive Note", client = client.getId(), text = frame.note.text
108108

109109

110-
method sendMessage*(convo: Inbox, ds: WakuClient,
111-
content_frame: ContentFrame) : Future[MessageId] {.async.} =
110+
method sendMessage*(convo: Inbox, content_frame: ContentFrame) : Future[MessageId] {.async.} =
112111
warn "Cannot send message to Inbox"
113112
result = "program_error"

0 commit comments

Comments
 (0)