mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Add MessageInfo
This commit is contained in:
parent
e3db122dd6
commit
a6d54ab180
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
13
src/chat_sdk/message_info.nim
Normal file
13
src/chat_sdk/message_info.nim
Normal file
@ -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]
|
||||
Loading…
x
Reference in New Issue
Block a user