mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-02 14:13:10 +00:00
Remove contentFrame from Client
This commit is contained in:
parent
629b1b73b9
commit
4eaa05d60b
@ -12,9 +12,16 @@ import ../src/chat/crypto
|
||||
proc getContent(content: ContentFrame): string =
|
||||
# Skip type checks and assume its a TextFrame
|
||||
let m = decode(content.bytes, TextFrame).valueOr:
|
||||
raise newException(ValueError, fmt"Badly formed Content")
|
||||
raise newException(ValueError, fmt"Badly formed ContentType")
|
||||
return fmt"{m}"
|
||||
|
||||
proc toBytes(content: ContentFrame): seq[byte] =
|
||||
encode(content)
|
||||
|
||||
proc fromBytes(bytes: seq[byte]): ContentFrame =
|
||||
decode(bytes, ContentFrame).valueOr:
|
||||
raise newException(ValueError, fmt"Badly formed Content")
|
||||
|
||||
proc main() {.async.} =
|
||||
|
||||
# Create Configurations
|
||||
@ -33,9 +40,10 @@ proc main() {.async.} =
|
||||
var ri = 0
|
||||
# Wire Callbacks
|
||||
saro.onNewMessage(proc(convo: Conversation, msg: ReceivedMessage) {.async.} =
|
||||
echo " Saro <------ :: " & getContent(msg.content)
|
||||
let contentFrame = msg.content.fromBytes()
|
||||
echo " Saro <------ :: " & getContent(contentFrame)
|
||||
await sleepAsync(5000.milliseconds)
|
||||
discard await convo.sendMessage(initTextFrame("Ping").toContentFrame())
|
||||
discard await convo.sendMessage(initTextFrame("Ping").toContentFrame().toBytes())
|
||||
|
||||
)
|
||||
|
||||
@ -47,19 +55,20 @@ proc main() {.async.} =
|
||||
|
||||
|
||||
raya.onNewMessage(proc(convo: Conversation,msg: ReceivedMessage) {.async.} =
|
||||
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(msg.content)
|
||||
let contentFrame = msg.content.fromBytes()
|
||||
echo fmt" ------> Raya :: from:{msg.sender} " & getContent(contentFrame)
|
||||
await sleepAsync(500.milliseconds)
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame().toBytes())
|
||||
await sleepAsync(800.milliseconds)
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame().toBytes())
|
||||
await sleepAsync(500.milliseconds)
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame())
|
||||
discard await convo.sendMessage(initTextFrame("Pong" & $ri).toContentFrame().toBytes())
|
||||
inc ri
|
||||
)
|
||||
|
||||
raya.onNewConversation(proc(convo: Conversation) {.async.} =
|
||||
echo " ------> Raya :: New Conversation: " & convo.id()
|
||||
discard await convo.sendMessage(initTextFrame("Hello").toContentFrame())
|
||||
discard await convo.sendMessage(initTextFrame("Hello").toContentFrame().toBytes())
|
||||
)
|
||||
raya.onDeliveryAck(proc(convo: Conversation, msgId: string) {.async.} =
|
||||
echo " raya -- Read Receipt for " & msgId
|
||||
|
||||
@ -2,10 +2,6 @@ syntax = "proto3";
|
||||
|
||||
package wap.convos.private_v1;
|
||||
|
||||
import "common_frames.proto";
|
||||
|
||||
|
||||
|
||||
|
||||
message Placeholder {
|
||||
uint32 counter = 1;
|
||||
@ -16,7 +12,7 @@ message PrivateV1Frame {
|
||||
bytes sender = 2;
|
||||
int64 timestamp = 3; // Sender reported timestamp
|
||||
oneof frame_type {
|
||||
common_frames.ContentFrame content = 10;
|
||||
bytes content = 10;
|
||||
Placeholder placeholder = 11;
|
||||
// ....
|
||||
}
|
||||
|
||||
@ -5,13 +5,12 @@ import chat/[
|
||||
delivery/waku_client,
|
||||
identity,
|
||||
links,
|
||||
proto_types,
|
||||
types
|
||||
]
|
||||
|
||||
export client, conversations, identity, links, waku_client
|
||||
|
||||
#export specific frames need by applications
|
||||
export ContentFrame, MessageId
|
||||
export MessageId
|
||||
|
||||
export toHex
|
||||
|
||||
@ -24,6 +24,6 @@ method id*(self: Conversation): string {.raises: [Defect, ValueError].} =
|
||||
# TODO: make this a compile time check
|
||||
panic("ProgramError: Missing concrete implementation")
|
||||
|
||||
method sendMessage*(convo: Conversation, content_frame: ContentFrame) : Future[MessageId] {.async, base, gcsafe.} =
|
||||
method sendMessage*(convo: Conversation, content_frame: Content) : Future[MessageId] {.async, base, gcsafe.} =
|
||||
# TODO: make this a compile time check
|
||||
panic("ProgramError: Missing concrete implementation")
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import ../crypto
|
||||
import ../proto_types
|
||||
|
||||
# How to surface different verifability of properties across conversation types
|
||||
|
||||
@ -7,6 +6,6 @@ import ../proto_types
|
||||
type ReceivedMessage* = ref object of RootObj
|
||||
sender*: PublicKey
|
||||
timestamp*: int64
|
||||
content*: ContentFrame
|
||||
content*: seq[byte]
|
||||
|
||||
|
||||
|
||||
@ -28,7 +28,7 @@ import ../../naxolotl as nax
|
||||
type
|
||||
ReceivedPrivateV1Message* = ref object of ReceivedMessage
|
||||
|
||||
proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: ContentFrame) : ReceivedPrivateV1Message =
|
||||
proc initReceivedMessage(sender: PublicKey, timestamp: int64, content: Content) : ReceivedPrivateV1Message =
|
||||
ReceivedPrivateV1Message(sender:sender, timestamp:timestamp, content:content)
|
||||
|
||||
|
||||
@ -227,7 +227,7 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
|
||||
return
|
||||
|
||||
case frame.getKind():
|
||||
of typeContentFrame:
|
||||
of typeContent:
|
||||
# TODO: Using client.getId() results in an error in this context
|
||||
client.notifyNewMessage(convo, initReceivedMessage(convo.participant, frame.timestamp, frame.content))
|
||||
|
||||
@ -235,7 +235,7 @@ proc handleFrame*[T: ConversationStore](convo: PrivateV1, client: T,
|
||||
notice "Got Placeholder", text = frame.placeholder.counter
|
||||
|
||||
|
||||
method sendMessage*(convo: PrivateV1, content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
||||
method sendMessage*(convo: PrivateV1, content_frame: Content) : Future[MessageId] {.async.} =
|
||||
|
||||
try:
|
||||
let frame = PrivateV1Frame(sender: @(convo.owner.getPubkey().bytes()),
|
||||
|
||||
@ -11,7 +11,6 @@ import
|
||||
conversations,
|
||||
conversation_store,
|
||||
crypto,
|
||||
delivery/waku_client,
|
||||
errors,
|
||||
proto_types,
|
||||
types
|
||||
@ -122,6 +121,6 @@ proc handleFrame*[T: ConversationStore](convo: Inbox, client: T, bytes: seq[
|
||||
notice "Receive Note", client = client.getId(), text = frame.note.text
|
||||
|
||||
|
||||
method sendMessage*(convo: Inbox, content_frame: ContentFrame) : Future[MessageId] {.async.} =
|
||||
method sendMessage*(convo: Inbox, content_frame: Content) : Future[MessageId] {.async.} =
|
||||
warn "Cannot send message to Inbox"
|
||||
result = "program_error"
|
||||
|
||||
@ -12,13 +12,11 @@ import_proto3 "../../protos/inbox.proto"
|
||||
# import_proto3 "../protos/invite.proto" // Import3 follows protobuf includes so this will result in a redefinition error
|
||||
import_proto3 "../../protos/encryption.proto"
|
||||
import_proto3 "../../protos/envelope.proto"
|
||||
# import_proto3 "../protos/common_frames.proto"
|
||||
|
||||
import_proto3 "../../protos/private_v1.proto"
|
||||
|
||||
type EncryptableTypes = InboxV1Frame | EncryptedPayload
|
||||
|
||||
export ContentFrame
|
||||
export EncryptedPayload
|
||||
export InboxV1Frame
|
||||
export PrivateV1Frame
|
||||
@ -94,12 +92,12 @@ proc getKind*(obj: InboxV1Frame): InboxV1FrameType =
|
||||
|
||||
type
|
||||
PrivateV1FrameType* = enum
|
||||
type_ContentFrame, type_Placeholder
|
||||
type_Content, type_Placeholder
|
||||
|
||||
proc getKind*(obj: PrivateV1Frame): PrivateV1FrameType =
|
||||
|
||||
if obj.content != ContentFrame():
|
||||
return type_ContentFrame
|
||||
if obj.content != @[]:
|
||||
return type_Content
|
||||
|
||||
if obj.placeholder != Placeholder():
|
||||
return type_Placeholder
|
||||
|
||||
@ -1 +1,2 @@
|
||||
type MessageId* = string
|
||||
type Content* = seq[byte]
|
||||
|
||||
@ -12,7 +12,7 @@ import ../chat/proto_types
|
||||
export protobuf_serialization
|
||||
|
||||
import_proto3 "protos/text_frame.proto"
|
||||
# import_proto3 "../../protos/common_frames.proto"
|
||||
import_proto3 "protos/common_frames.proto"
|
||||
|
||||
export ContentFrame, TextFrame
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user