mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Remove WakuClient from convo.sendMessage
This commit is contained in:
parent
26c41313d4
commit
5fbe422ce3
@ -39,7 +39,7 @@ proc main() {.async.} =
|
|||||||
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
||||||
echo " Saro <------ :: " & getContent(msg.content)
|
echo " Saro <------ :: " & getContent(msg.content)
|
||||||
await sleepAsync(5000.milliseconds)
|
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.} =
|
raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} =
|
||||||
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
|
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
|
||||||
await sleepAsync(500.milliseconds)
|
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)
|
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)
|
await sleepAsync(500.milliseconds)
|
||||||
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
|
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
|
||||||
inc ri
|
inc ri
|
||||||
)
|
)
|
||||||
|
|
||||||
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||||
echo " ------> Raya :: New Conversation: " & convo.id()
|
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.} =
|
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||||
echo " raya -- Read Receipt for " & msgId
|
echo " raya -- Read Receipt for " & msgId
|
||||||
|
|||||||
@ -218,7 +218,7 @@ proc newPrivateConversation*(client: Client,
|
|||||||
var key : array[32, byte]
|
var key : array[32, byte]
|
||||||
key[2]=2
|
key[2]=2
|
||||||
|
|
||||||
var convo = initPrivateV1Sender(client.identity(), destPubkey, key, deliveryAckCb)
|
var convo = initPrivateV1Sender(client.identity(), client.ds, destPubkey, key, deliveryAckCb)
|
||||||
client.addConversation(convo)
|
client.addConversation(convo)
|
||||||
|
|
||||||
# TODO: Subscribe to new content topic
|
# TODO: Subscribe to new content topic
|
||||||
|
|||||||
@ -3,7 +3,6 @@ import strformat
|
|||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
import ../proto_types
|
import ../proto_types
|
||||||
import ../delivery/waku_client
|
|
||||||
import ../utils
|
import ../utils
|
||||||
import ../types
|
import ../types
|
||||||
|
|
||||||
@ -25,7 +24,6 @@ method id*(self: Conversation): string {.raises: [Defect, ValueError].} =
|
|||||||
# TODO: make this a compile time check
|
# TODO: make this a compile time check
|
||||||
panic("ProgramError: Missing concrete implementation")
|
panic("ProgramError: Missing concrete implementation")
|
||||||
|
|
||||||
method sendMessage*(convo: Conversation, ds: WakuClient,
|
method sendMessage*(convo: Conversation, content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} =
|
||||||
content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} =
|
|
||||||
# TODO: make this a compile time check
|
# TODO: make this a compile time check
|
||||||
panic("ProgramError: Missing concrete implementation")
|
panic("ProgramError: Missing concrete implementation")
|
||||||
|
|||||||
@ -34,7 +34,7 @@ proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFr
|
|||||||
|
|
||||||
type
|
type
|
||||||
PrivateV1* = ref object of Conversation
|
PrivateV1* = ref object of Conversation
|
||||||
# Placeholder for PrivateV1 conversation type
|
ds: WakuClient
|
||||||
sdsClient: ReliabilityManager
|
sdsClient: ReliabilityManager
|
||||||
owner: Identity
|
owner: Identity
|
||||||
topic: string
|
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(
|
discriminator: string = "default", isSender: bool, deliveryAckCb: proc(
|
||||||
conversation: Conversation,
|
conversation: Conversation,
|
||||||
msgId: string): Future[void] {.async.} = nil):
|
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)}")
|
raise newException(ValueError, fmt"sds initialization: {repr(error)}")
|
||||||
|
|
||||||
result = PrivateV1(
|
result = PrivateV1(
|
||||||
|
ds: ds,
|
||||||
sdsClient: rm,
|
sdsClient: rm,
|
||||||
owner: owner,
|
owner: owner,
|
||||||
topic: derive_topic(participants, discriminator),
|
topic: derive_topic(participants, discriminator),
|
||||||
@ -152,13 +153,13 @@ proc initPrivateV1*(owner: Identity, participant: PublicKey, seedKey: array[32,
|
|||||||
raise newException(ValueError, "bad sds channel")
|
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 =
|
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 =
|
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,
|
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
|
notice "Got Placeholder", text = frame.placeholder.counter
|
||||||
|
|
||||||
|
|
||||||
method sendMessage*(convo: PrivateV1, ds: WakuClient,
|
method sendMessage*(convo: PrivateV1, content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
||||||
content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
let frame = PrivateV1Frame(sender: @(convo.owner.getPubkey().bytes()),
|
let frame = PrivateV1Frame(sender: @(convo.owner.getPubkey().bytes()),
|
||||||
timestamp: getCurrentTimestamp(), content: content_frame)
|
timestamp: getCurrentTimestamp(), content: content_frame)
|
||||||
|
|
||||||
result = await convo.sendFrame(ds, frame)
|
result = await convo.sendFrame(convo.ds, frame)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error "Unknown error in PrivateV1:SendMessage"
|
error "Unknown error in PrivateV1:SendMessage"
|
||||||
|
|
||||||
|
|||||||
@ -81,7 +81,7 @@ proc createPrivateV1FromInvite*[T: ConversationStore](client: T,
|
|||||||
var key : array[32, byte]
|
var key : array[32, byte]
|
||||||
key[2]=2
|
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(),
|
notice "Creating PrivateV1 conversation", client = client.getId(),
|
||||||
topic = convo.getConvoId()
|
topic = convo.getConvoId()
|
||||||
client.addConversation(convo)
|
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
|
notice "Receive Note", client = client.getId(), text = frame.note.text
|
||||||
|
|
||||||
|
|
||||||
method sendMessage*(convo: Inbox, ds: WakuClient,
|
method sendMessage*(convo: Inbox, content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
||||||
content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
|
||||||
warn "Cannot send message to Inbox"
|
warn "Cannot send message to Inbox"
|
||||||
result = "program_error"
|
result = "program_error"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user