Add ReceivedMessage type for cleaner api

This commit is contained in:
Jazz Turner-Baggs 2025-10-15 15:35:49 -07:00
parent 627e6c8dd9
commit e76556dc39
8 changed files with 34 additions and 33 deletions

View File

@ -36,8 +36,8 @@ proc main() {.async.} =
var ri = 0
# Wire Callbacks
saro.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} =
echo " Saro <------ :: " & getContent(msg)
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
echo " Saro <------ :: " & getContent(msg.content)
await sleepAsync(5000)
discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame())
@ -50,8 +50,8 @@ proc main() {.async.} =
raya.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} =
echo fmt" ------> Raya :: from:{msgInfo.sender.value} " & getContent(msg)
raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} =
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
await sleepAsync(500)
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
await sleepAsync(800)

View File

@ -4,12 +4,11 @@ import chat_sdk/[
delivery/waku_client,
identity,
links,
message_info,
proto_types,
types
]
export client, conversations, identity, links, message_info, waku_client
export client, conversations, identity, links, waku_client
#export specific frames need by applications
export ContentFrame, MessageId

View File

@ -24,7 +24,6 @@ import #local
errors,
identity,
inbox,
message_info,
proto_types,
types,
utils
@ -38,7 +37,7 @@ logScope:
#################################################
type
MessageCallback* = proc(conversation: Conversation, msgInfo: MessageInfo, msg: ContentFrame): Future[void] {.async.}
MessageCallback* = proc(conversation: Conversation, msg: ReceivedMessage): Future[void] {.async.}
NewConvoCallback* = proc(conversation: Conversation): Future[void] {.async.}
DeliveryAckCallback* = proc(conversation: Conversation,
msgId: MessageId): Future[void] {.async.}
@ -126,10 +125,9 @@ proc listConversations*(client: Client): seq[Conversation] =
proc onNewMessage*(client: Client, callback: MessageCallback) =
client.newMessageCallbacks.add(callback)
proc notifyNewMessage*(client: Client, convo: Conversation, msgInfo: MessageInfo,
content: ContentFrame) =
proc notifyNewMessage*(client: Client, convo: Conversation, msg: ReceivedMessage) =
for cb in client.newMessageCallbacks:
discard cb(convo, msgInfo, content)
discard cb(convo, msg)
proc onNewConversation*(client: Client, callback: NewConvoCallback) =
client.newConvoCallbacks.add(callback)

View File

@ -1,11 +1,10 @@
import std/[options, times]
import ./conversations/convo_type
import ./conversations/[convo_type, message]
import crypto
import identity
import proto_types
import types
import message_info
type ConvoId = string
@ -16,7 +15,6 @@ type
proc identity(self: Self): Identity
proc getId(self: Self): string
proc notifyNewMessage(self: Self, convo: Conversation, msgInfo: MessageInfo,
content: ContentFrame)
proc notifyNewMessage(self: Self, convo: Conversation, msg: ReceivedMessage)
proc notifyDeliveryAck(self: Self, convo: Conversation,
msgId: MessageId)

View File

@ -1,5 +1,5 @@
import
./conversations/[convo_type, private_v1]
./conversations/[convo_type, private_v1, message]
export private_v1, convo_type
export private_v1, convo_type, message

View File

@ -0,0 +1,12 @@
import ../crypto
import ../proto_types
# How to surface different verifability of properties across conversation types
type ReceivedMessage* = ref object of RootObj
sender*: PublicKey
timestamp*: int64
content*: ContentFrame

View File

@ -20,11 +20,18 @@ import ../[
utils
]
import convo_type
import ../message_info
import message
import ../../naxolotl as nax
type
ReceivedPrivateV1Message* = ref object of ReceivedMessage
proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFrame) : ReceivedPrivateV1Message =
ReceivedPrivateV1Message(sender:sender, timestamp:timestamp, content:content)
type
PrivateV1* = ref object of Conversation
# Placeholder for PrivateV1 conversation type
@ -203,8 +210,8 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
case frame.getKind():
of typeContentFrame:
# TODO: Using client.getId() results in an error in this context
client.notifyNewMessage(convo, MessageInfo(sender: Property[PublicKey](value: convo.participant, verifiability: Unverified)), frame.content)
client.notifyNewMessage(convo, initReceivedMessage(convo.participant, frame.timestamp, frame.content))
of typePlaceholder:
notice "Got Placeholder", text = frame.placeholder.counter

View File

@ -1,13 +0,0 @@
import crypto
type
VerifabilityProp* = enum
Verified, Unverified
type Property*[T] = object
value*: T
verifiability*: VerifabilityProp
type MessageInfo* = object
sender*: Property[PublicKey]
timestamp*: Property[uint64]