mirror of
https://github.com/logos-messaging/nim-chat-poc.git
synced 2026-01-07 16:43:06 +00:00
refactor: remove useless log
This commit is contained in:
parent
567db393ac
commit
70bd36785c
@ -229,14 +229,14 @@ proc newPrivateConversation*(client: Client,
|
|||||||
|
|
||||||
#################################################
|
#################################################
|
||||||
# Payload Handling
|
# Payload Handling
|
||||||
|
# Receives a incoming payload, decodes it, and processes it.
|
||||||
#################################################
|
#################################################
|
||||||
|
|
||||||
proc parseMessage(client: Client, msg: ChatPayload) {.raises: [ValueError,
|
proc parseMessage(client: Client, msg: ChatPayload) {.raises: [ValueError,
|
||||||
SerializationError].} =
|
SerializationError].} =
|
||||||
## Receives a incoming payload, decodes it, and processes it.
|
|
||||||
let envelopeRes = decode(msg.bytes, WapEnvelopeV1)
|
let envelopeRes = decode(msg.bytes, WapEnvelopeV1)
|
||||||
if envelopeRes.isErr:
|
if envelopeRes.isErr:
|
||||||
debug "Failed to decode WapEnvelopeV1", err = envelopeRes.error
|
debug "Failed to decode WapEnvelopeV1", client = client.getId(), err = envelopeRes.error
|
||||||
return
|
return
|
||||||
let envelope = envelopeRes.get()
|
let envelope = envelopeRes.get()
|
||||||
|
|
||||||
@ -268,6 +268,11 @@ proc messageQueueConsumer(client: Client) {.async.} =
|
|||||||
while client.isRunning:
|
while client.isRunning:
|
||||||
let message = await client.inboundQueue.queue.get()
|
let message = await client.inboundQueue.queue.get()
|
||||||
|
|
||||||
|
let topicRes = inbox.parseTopic(message.contentTopic).or(private_v1.parseTopic(message.contentTopic))
|
||||||
|
if topicRes.isErr:
|
||||||
|
debug "Invalid content topic", client = client.getId(), err = topicRes.error, contentTopic = message.contentTopic
|
||||||
|
continue
|
||||||
|
|
||||||
notice "Inbound Message Received", client = client.getId(),
|
notice "Inbound Message Received", client = client.getId(),
|
||||||
contentTopic = message.contentTopic, len = message.bytes.len()
|
contentTopic = message.contentTopic, len = message.bytes.len()
|
||||||
try:
|
try:
|
||||||
|
|||||||
@ -42,6 +42,9 @@ type
|
|||||||
discriminator: string
|
discriminator: string
|
||||||
doubleratchet: naxolotl.Doubleratchet
|
doubleratchet: naxolotl.Doubleratchet
|
||||||
|
|
||||||
|
const
|
||||||
|
TopicPrefixPrivateV1 = "/convo/private/"
|
||||||
|
|
||||||
proc getTopic*(self: PrivateV1): string =
|
proc getTopic*(self: PrivateV1): string =
|
||||||
## Returns the topic for the PrivateV1 conversation.
|
## Returns the topic for the PrivateV1 conversation.
|
||||||
return self.topic
|
return self.topic
|
||||||
@ -63,7 +66,18 @@ proc getConvoId*(self: PrivateV1): string =
|
|||||||
|
|
||||||
proc derive_topic(participants: seq[PublicKey], discriminator: string): string =
|
proc derive_topic(participants: seq[PublicKey], discriminator: string): string =
|
||||||
## Derives a topic from the participants' public keys.
|
## Derives a topic from the participants' public keys.
|
||||||
return "/convo/private/" & getConvoIdRaw(participants, discriminator)
|
return TopicPrefixPrivateV1 & getConvoIdRaw(participants, discriminator)
|
||||||
|
|
||||||
|
## Parses the topic to extract the conversation ID.
|
||||||
|
proc parseTopic*(topic: string): Result[string, ChatError] =
|
||||||
|
if not topic.startsWith(TopicPrefixPrivateV1):
|
||||||
|
return err(ChatError(code: errTopic, context: "Invalid topic prefix"))
|
||||||
|
|
||||||
|
let id = topic.split('/')[^1]
|
||||||
|
if id == "":
|
||||||
|
return err(ChatError(code: errTopic, context: "Empty conversation ID"))
|
||||||
|
|
||||||
|
return ok(id)
|
||||||
|
|
||||||
proc calcMsgId(self: PrivateV1, msgBytes: seq[byte]): string =
|
proc calcMsgId(self: PrivateV1, msgBytes: seq[byte]): string =
|
||||||
let s = fmt"{self.getConvoId()}|{msgBytes}"
|
let s = fmt"{self.getConvoId()}|{msgBytes}"
|
||||||
|
|||||||
@ -8,6 +8,7 @@ type
|
|||||||
ErrorCode* = enum
|
ErrorCode* = enum
|
||||||
errTypeError
|
errTypeError
|
||||||
errWrapped
|
errWrapped
|
||||||
|
errTopic
|
||||||
|
|
||||||
proc `$`*(x: ChatError): string =
|
proc `$`*(x: ChatError): string =
|
||||||
fmt"ChatError(code={$x.code}, context: {x.context})"
|
fmt"ChatError(code={$x.code}, context: {x.context})"
|
||||||
|
|||||||
@ -1,3 +1,5 @@
|
|||||||
|
import std/[strutils]
|
||||||
|
|
||||||
import
|
import
|
||||||
chronicles,
|
chronicles,
|
||||||
chronos,
|
chronos,
|
||||||
@ -10,6 +12,7 @@ import
|
|||||||
conversation_store,
|
conversation_store,
|
||||||
crypto,
|
crypto,
|
||||||
delivery/waku_client,
|
delivery/waku_client,
|
||||||
|
errors,
|
||||||
proto_types,
|
proto_types,
|
||||||
types
|
types
|
||||||
|
|
||||||
@ -21,6 +24,8 @@ type
|
|||||||
pubkey: PublicKey
|
pubkey: PublicKey
|
||||||
inbox_addr: string
|
inbox_addr: string
|
||||||
|
|
||||||
|
const
|
||||||
|
TopicPrefixInbox = "/inbox/"
|
||||||
|
|
||||||
proc `$`*(conv: Inbox): string =
|
proc `$`*(conv: Inbox): string =
|
||||||
fmt"Inbox: addr->{conv.inbox_addr}"
|
fmt"Inbox: addr->{conv.inbox_addr}"
|
||||||
@ -56,7 +61,17 @@ proc conversation_id_for*(pubkey: PublicKey): string =
|
|||||||
|
|
||||||
# TODO derive this from instance of Inbox
|
# TODO derive this from instance of Inbox
|
||||||
proc topic_inbox*(client_addr: string): string =
|
proc topic_inbox*(client_addr: string): string =
|
||||||
return "/inbox/" & client_addr
|
return TopicPrefixInbox & client_addr
|
||||||
|
|
||||||
|
proc parseTopic*(topic: string): Result[string, ChatError] =
|
||||||
|
if not topic.startsWith(TopicPrefixInbox):
|
||||||
|
return err(ChatError(code: errTopic, context: "Invalid inbox topic prefix"))
|
||||||
|
|
||||||
|
let id = topic.split('/')[^1]
|
||||||
|
if id == "":
|
||||||
|
return err(ChatError(code: errTopic, context: "Empty inbox id"))
|
||||||
|
|
||||||
|
return ok(id)
|
||||||
|
|
||||||
method id*(convo: Inbox): string =
|
method id*(convo: Inbox): string =
|
||||||
return conversation_id_for(convo.pubkey)
|
return conversation_id_for(convo.pubkey)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user