diff --git a/examples/pingpong.nim b/examples/pingpong.nim index 723ef7e..4625d3d 100644 --- a/examples/pingpong.nim +++ b/examples/pingpong.nim @@ -36,7 +36,7 @@ proc main() {.async.} = var ri = 0 # Wire Callbacks - saro.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = + saro.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} = echo " Saro <------ :: " & getContent(msg) await sleepAsync(5000) discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame()) @@ -50,8 +50,8 @@ proc main() {.async.} = - raya.onNewMessage(proc(convo: Conversation, msg: ContentFrame) {.async.} = - echo " ------> Raya :: " & getContent(msg) + raya.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} = + echo fmt" ------> Raya :: from:{msgInfo.sender.value} " & getContent(msg) 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 957117e..c3f32f7 100644 --- a/src/chat_sdk.nim +++ b/src/chat_sdk.nim @@ -4,12 +4,12 @@ import chat_sdk/[ delivery/waku_client, identity, links, + message_info, proto_types, types - ] -export client, conversations, waku_client, identity, links +export client, conversations, identity, links, message_info, 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 6d53c4d..e45806e 100644 --- a/src/chat_sdk/client.nim +++ b/src/chat_sdk/client.nim @@ -24,6 +24,7 @@ import #local errors, identity, inbox, + message_info, proto_types, types, utils @@ -37,7 +38,7 @@ logScope: ################################################# type - MessageCallback*[T] = proc(conversation: Conversation, msg: T): Future[void] {.async.} + MessageCallback* = proc(conversation: Conversation, msgInfo: MessageInfo, msg: ContentFrame): Future[void] {.async.} NewConvoCallback* = proc(conversation: Conversation): Future[void] {.async.} DeliveryAckCallback* = proc(conversation: Conversation, msgId: MessageId): Future[void] {.async.} @@ -56,7 +57,7 @@ type Client* = ref object inboundQueue: QueueRef isRunning: bool - newMessageCallbacks: seq[MessageCallback[ContentFrame]] + newMessageCallbacks: seq[MessageCallback] newConvoCallbacks: seq[NewConvoCallback] deliveryAckCallbacks: seq[DeliveryAckCallback] @@ -122,13 +123,13 @@ proc listConversations*(client: Client): seq[Conversation] = # Callback Handling ################################################# -proc onNewMessage*(client: Client, callback: MessageCallback[ContentFrame]) = +proc onNewMessage*(client: Client, callback: MessageCallback) = client.newMessageCallbacks.add(callback) -proc notifyNewMessage(client: Client, convo: Conversation, +proc notifyNewMessage*(client: Client, convo: Conversation, msgInfo: MessageInfo, content: ContentFrame) = for cb in client.newMessageCallbacks: - discard cb(convo, content) + discard cb(convo, msgInfo, content) 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 ce89a0a..70d2543 100644 --- a/src/chat_sdk/conversation_store.nim +++ b/src/chat_sdk/conversation_store.nim @@ -5,6 +5,7 @@ import crypto import identity import proto_types import types +import message_info type ConvoId = string @@ -15,7 +16,7 @@ type proc identity(self: Self): Identity proc getId(self: Self): string - proc notifyNewMessage(self: Self, convo: Conversation, + proc notifyNewMessage(self: Self, convo: Conversation, msgInfo: MessageInfo, content: ContentFrame) proc notifyDeliveryAck(self: Self, convo: Conversation, msgId: MessageId) diff --git a/src/chat_sdk/conversations/private_v1.nim b/src/chat_sdk/conversations/private_v1.nim index f0d6615..8605ff3 100644 --- a/src/chat_sdk/conversations/private_v1.nim +++ b/src/chat_sdk/conversations/private_v1.nim @@ -20,6 +20,7 @@ import ../[ utils ] import convo_type +import ../message_info import ../../naxolotl as nax @@ -202,7 +203,7 @@ 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, frame.content) + client.notifyNewMessage(convo, MessageInfo(sender: Property[PublicKey](value: convo.participant, verifiability: Unverified)), 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 new file mode 100644 index 0000000..af6bead --- /dev/null +++ b/src/chat_sdk/message_info.nim @@ -0,0 +1,13 @@ +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