From 6a149e266b3ec7de04229f0f74a3681260691757 Mon Sep 17 00:00:00 2001 From: Jazz Turner-Baggs <473256+jazzz@users.noreply.github.com> Date: Wed, 15 Oct 2025 15:35:49 -0700 Subject: [PATCH] Add ReceivedMessage type for cleaner api --- examples/pingpong.nim | 8 ++++---- src/chat_sdk.nim | 3 +-- src/chat_sdk/client.nim | 8 +++----- src/chat_sdk/conversation_store.nim | 6 ++---- src/chat_sdk/conversations.nim | 4 ++-- src/chat_sdk/conversations/message.nim | 12 ++++++++++++ src/chat_sdk/conversations/private_v1.nim | 13 ++++++++++--- src/chat_sdk/message_info.nim | 13 ------------- 8 files changed, 34 insertions(+), 33 deletions(-) create mode 100644 src/chat_sdk/conversations/message.nim delete mode 100644 src/chat_sdk/message_info.nim diff --git a/examples/pingpong.nim b/examples/pingpong.nim index 4625d3d..75c8cf9 100644 --- a/examples/pingpong.nim +++ b/examples/pingpong.nim @@ -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) diff --git a/src/chat_sdk.nim b/src/chat_sdk.nim index c3f32f7..0487404 100644 --- a/src/chat_sdk.nim +++ b/src/chat_sdk.nim @@ -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 diff --git a/src/chat_sdk/client.nim b/src/chat_sdk/client.nim index e45806e..bfdd6bd 100644 --- a/src/chat_sdk/client.nim +++ b/src/chat_sdk/client.nim @@ -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) diff --git a/src/chat_sdk/conversation_store.nim b/src/chat_sdk/conversation_store.nim index 70d2543..ce55efa 100644 --- a/src/chat_sdk/conversation_store.nim +++ b/src/chat_sdk/conversation_store.nim @@ -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) diff --git a/src/chat_sdk/conversations.nim b/src/chat_sdk/conversations.nim index 31409c1..eb426a7 100644 --- a/src/chat_sdk/conversations.nim +++ b/src/chat_sdk/conversations.nim @@ -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 diff --git a/src/chat_sdk/conversations/message.nim b/src/chat_sdk/conversations/message.nim new file mode 100644 index 0000000..0ecc143 --- /dev/null +++ b/src/chat_sdk/conversations/message.nim @@ -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 + + diff --git a/src/chat_sdk/conversations/private_v1.nim b/src/chat_sdk/conversations/private_v1.nim index 8605ff3..543704e 100644 --- a/src/chat_sdk/conversations/private_v1.nim +++ b/src/chat_sdk/conversations/private_v1.nim @@ -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 diff --git a/src/chat_sdk/message_info.nim b/src/chat_sdk/message_info.nim deleted file mode 100644 index af6bead..0000000 --- a/src/chat_sdk/message_info.nim +++ /dev/null @@ -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] \ No newline at end of file