use pub key to gen chat message id
This commit is contained in:
parent
d4c597fa0f
commit
6252736ad2
|
@ -1,3 +1,5 @@
|
||||||
|
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
|
||||||
|
|
||||||
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
||||||
import { ChatMessage } from '../../../protos/chat-message'
|
import { ChatMessage } from '../../../protos/chat-message'
|
||||||
import { ProtocolMessage } from '../../../protos/protocol-message'
|
import { ProtocolMessage } from '../../../protos/protocol-message'
|
||||||
|
@ -46,12 +48,13 @@ export function handleChannelChatMessage(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
|
||||||
|
|
||||||
const decodedPayload = ChatMessage.decode(messageToDecode)
|
const decodedPayload = ChatMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = payloadToId(
|
// fixme?: handle decodedProtocol.encryptedMessage
|
||||||
decodedProtocol.publicMessage,
|
const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
|
||||||
wakuMessage.signaturePublicKey
|
|
||||||
)
|
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
|
||||||
const message = mapChatMessage(decodedPayload, { messageId, channelId })
|
const message = mapChatMessage(decodedPayload, { messageId, channelId })
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
// todo?: rename to handle-message
|
// todo?: rename to handle-message
|
||||||
import { bytesToHex } from 'ethereum-cryptography/utils'
|
import { bytesToHex } from 'ethereum-cryptography/utils'
|
||||||
|
|
||||||
|
import { recoverPublicKeyFromMetadata } from '~/src/utils/recover-public-key-from-metadata'
|
||||||
|
|
||||||
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
||||||
import {
|
import {
|
||||||
ChatMessage,
|
ChatMessage,
|
||||||
|
@ -61,17 +63,16 @@ export function handleChannelChatMessage(
|
||||||
// break
|
// break
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
const publicKey = recoverPublicKeyFromMetadata(decodedMetadata)
|
||||||
|
|
||||||
// todo: merge and process other types of messages
|
// todo: merge and process other types of messages
|
||||||
// TODO?: ignore messages which are messageType !== COMMUNITY_CHAT
|
// TODO?: ignore messages which are messageType !== COMMUNITY_CHAT
|
||||||
switch (decodedMetadata.type) {
|
switch (decodedMetadata.type) {
|
||||||
case ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE: {
|
case ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE: {
|
||||||
const decodedPayload = ChatMessage.decode(messageToDecode)
|
const decodedPayload = ChatMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = payloadToId(
|
// fixme?: handle decodedProtocol.encryptedMessage
|
||||||
decodedProtocol.publicMessage,
|
const messageId = payloadToId(decodedProtocol.publicMessage, publicKey)
|
||||||
// fixme!: replace for recoverPublicKeyFromMetadata
|
|
||||||
wakuMessage.signaturePublicKey
|
|
||||||
)
|
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
|
||||||
const _messages = messages[channelId] || []
|
const _messages = messages[channelId] || []
|
||||||
|
|
Loading…
Reference in New Issue