Skip to content

Commit 6a149e2

Browse files
committed
Add ReceivedMessage type for cleaner api
1 parent f77d7fe commit 6a149e2

File tree

8 files changed

+34
-33
lines changed

8 files changed

+34
-33
lines changed

examples/pingpong.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ proc main() {.async.} =
3636

3737
var ri = 0
3838
# Wire Callbacks
39-
saro.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} =
40-
echo " Saro <------ :: " & getContent(msg)
39+
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
40+
echo " Saro <------ :: " & getContent(msg.content)
4141
await sleepAsync(5000)
4242
discard await convo.sendMessage(saro.ds, initTextFrame("Ping").toContentFrame())
4343

@@ -50,8 +50,8 @@ proc main() {.async.} =
5050

5151

5252

53-
raya.onNewMessage(proc(convo: Conversation, msgInfo: MessageInfo, msg: ContentFrame) {.async.} =
54-
echo fmt" ------> Raya :: from:{msgInfo.sender.value} " & getContent(msg)
53+
raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} =
54+
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
5555
await sleepAsync(500)
5656
discard await convo.sendMessage(raya.ds, initTextFrame("Pong" & $ri).toContentFrame())
5757
await sleepAsync(800)

src/chat_sdk.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,11 @@ import chat_sdk/[
44
delivery/waku_client,
55
identity,
66
links,
7-
message_info,
87
proto_types,
98
types
109
]
1110

12-
export client, conversations, identity, links, message_info, waku_client
11+
export client, conversations, identity, links, waku_client
1312

1413
#export specific frames need by applications
1514
export ContentFrame, MessageId

src/chat_sdk/client.nim

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import #local
2424
errors,
2525
identity,
2626
inbox,
27-
message_info,
2827
proto_types,
2928
types,
3029
utils
@@ -38,7 +37,7 @@ logScope:
3837
#################################################
3938

4039
type
41-
MessageCallback* = proc(conversation: Conversation, msgInfo: MessageInfo, msg: ContentFrame): Future[void] {.async.}
40+
MessageCallback* = proc(conversation: Conversation, msg: ReceivedMessage): Future[void] {.async.}
4241
NewConvoCallback* = proc(conversation: Conversation): Future[void] {.async.}
4342
DeliveryAckCallback* = proc(conversation: Conversation,
4443
msgId: MessageId): Future[void] {.async.}
@@ -126,10 +125,9 @@ proc listConversations*(client: Client): seq[Conversation] =
126125
proc onNewMessage*(client: Client, callback: MessageCallback) =
127126
client.newMessageCallbacks.add(callback)
128127

129-
proc notifyNewMessage*(client: Client, convo: Conversation, msgInfo: MessageInfo,
130-
content: ContentFrame) =
128+
proc notifyNewMessage*(client: Client, convo: Conversation, msg: ReceivedMessage) =
131129
for cb in client.newMessageCallbacks:
132-
discard cb(convo, msgInfo, content)
130+
discard cb(convo, msg)
133131

134132
proc onNewConversation*(client: Client, callback: NewConvoCallback) =
135133
client.newConvoCallbacks.add(callback)
Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import std/[options, times]
22

3-
import ./conversations/convo_type
3+
import ./conversations/[convo_type, message]
44
import crypto
55
import identity
66
import proto_types
77
import types
8-
import message_info
98

109
type ConvoId = string
1110

@@ -16,7 +15,6 @@ type
1615
proc identity(self: Self): Identity
1716
proc getId(self: Self): string
1817

19-
proc notifyNewMessage(self: Self, convo: Conversation, msgInfo: MessageInfo,
20-
content: ContentFrame)
18+
proc notifyNewMessage(self: Self, convo: Conversation, msg: ReceivedMessage)
2119
proc notifyDeliveryAck(self: Self, convo: Conversation,
2220
msgId: MessageId)

src/chat_sdk/conversations.nim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import
2-
./conversations/[convo_type, private_v1]
2+
./conversations/[convo_type, private_v1, message]
33

44

5-
export private_v1, convo_type
5+
export private_v1, convo_type, message
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ../crypto
2+
import ../proto_types
3+
4+
# How to surface different verifability of properties across conversation types
5+
6+
7+
type ReceivedMessage* = ref object of RootObj
8+
sender*: PublicKey
9+
timestamp*: int64
10+
content*: ContentFrame
11+
12+

src/chat_sdk/conversations/private_v1.nim

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,18 @@ import ../[
2020
utils
2121
]
2222
import convo_type
23-
import ../message_info
23+
import message
2424

2525
import ../../naxolotl as nax
2626

2727

28+
type
29+
ReceivedPrivateV1Message* = ref object of ReceivedMessage
30+
31+
proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFrame) : ReceivedPrivateV1Message =
32+
ReceivedPrivateV1Message(sender:sender, timestamp:timestamp, content:content)
33+
34+
2835
type
2936
PrivateV1* = ref object of Conversation
3037
# Placeholder for PrivateV1 conversation type
@@ -203,8 +210,8 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
203210
case frame.getKind():
204211
of typeContentFrame:
205212
# TODO: Using client.getId() results in an error in this context
206-
client.notifyNewMessage(convo, MessageInfo(sender: Property[PublicKey](value: convo.participant, verifiability: Unverified)), frame.content)
207-
213+
client.notifyNewMessage(convo, initReceivedMessage(convo.participant, frame.timestamp, frame.content))
214+
208215
of typePlaceholder:
209216
notice "Got Placeholder", text = frame.placeholder.counter
210217

src/chat_sdk/message_info.nim

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)