Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions examples/pingpong.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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())

)

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/chat_sdk/client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions src/chat_sdk/conversations/convo_type.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import strformat
import strutils

import ../proto_types
import ../delivery/waku_client
import ../utils
import ../types

Expand All @@ -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")
18 changes: 9 additions & 9 deletions src/chat_sdk/conversations/private_v1.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -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"

5 changes: 2 additions & 3 deletions src/chat_sdk/inbox.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"