use pub key to gen chat message id

This commit is contained in:
Felicio Mununga 2022-06-08 17:09:36 +02:00
parent d4c597fa0f
commit 6252736ad2
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
2 changed files with 13 additions and 9 deletions

View File

@ -1,3 +1,5 @@
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
import { ChatMessage } from '../../../protos/chat-message'
import { ProtocolMessage } from '../../../protos/protocol-message'
@ -46,12 +48,13 @@ export function handleChannelChatMessage(
return
}
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
const decodedPayload = ChatMessage.decode(messageToDecode)
const messageId = payloadToId(
decodedProtocol.publicMessage,
wakuMessage.signaturePublicKey
)
// fixme?: handle decodedProtocol.encryptedMessage
const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
const channelId = getChannelId(decodedPayload.chatId)
const message = mapChatMessage(decodedPayload, { messageId, channelId })

View File

@ -2,6 +2,8 @@
// todo?: rename to handle-message
import { bytesToHex } from 'ethereum-cryptography/utils'
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
import {
ChatMessage,
@ -61,17 +63,16 @@ export function handleChannelChatMessage(
// break
// }
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
// todo: merge and process other types of messages
// TODO?: ignore messages which are messageType !== COMMUNITY_CHAT
switch (decodedMetadata.type) {
case ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE: {
const decodedPayload = ChatMessage.decode(messageToDecode)
const messageId = payloadToId(
decodedProtocol.publicMessage,
// fixme!: replace for recoverPublicKeyFromMetadata
wakuMessage.signaturePublicKey
)
// fixme?: handle decodedProtocol.encryptedMessage
const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
const channelId = getChannelId(decodedPayload.chatId)
const _messages = messages[channelId] || []