From e8a8cc5e12201531443112da135cf593fbc24779 Mon Sep 17 00:00:00 2001 From: Felicio Mununga Date: Wed, 8 Jun 2022 17:09:36 +0200 Subject: [PATCH] use pub key to gen chat message id --- .../community/delete_handle-channel-chat-message.ts | 11 +++++++---- .../client/community/handle-channel-chat-message.ts | 11 ++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/status-js/src/client/community/delete_handle-channel-chat-message.ts b/packages/status-js/src/client/community/delete_handle-channel-chat-message.ts index f67da8c3..262a64e0 100644 --- a/packages/status-js/src/client/community/delete_handle-channel-chat-message.ts +++ b/packages/status-js/src/client/community/delete_handle-channel-chat-message.ts @@ -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 }) diff --git a/packages/status-js/src/client/community/handle-channel-chat-message.ts b/packages/status-js/src/client/community/handle-channel-chat-message.ts index fb014e0b..49c2b07b 100644 --- a/packages/status-js/src/client/community/handle-channel-chat-message.ts +++ b/packages/status-js/src/client/community/handle-channel-chat-message.ts @@ -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] || []