try protocol layer first
This commit is contained in:
parent
260d4a4001
commit
d6f4726f72
|
@ -1,4 +1,3 @@
|
||||||
// todo: try protocol layer; then application data layer
|
|
||||||
// todo: replies; normalize messages (e.g. replies) prior returning
|
// todo: replies; normalize messages (e.g. replies) prior returning
|
||||||
// todo: tests
|
// todo: tests
|
||||||
|
|
||||||
|
|
|
@ -19,26 +19,34 @@ export function handleChannelChatMessage(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedProtocol = ProtocolMessage.decode(wakuMessage.payload)
|
let messageToDecode = wakuMessage.payload
|
||||||
|
let decodedProtocol
|
||||||
|
try {
|
||||||
|
decodedProtocol = ProtocolMessage.decode(messageToDecode)
|
||||||
|
if (decodedProtocol) {
|
||||||
|
messageToDecode = decodedProtocol.publicMessage
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
// fixme!: remove after replacing payloadToId
|
||||||
if (!decodedProtocol) {
|
if (!decodedProtocol) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedMetadata = ApplicationMetadataMessage.decode(
|
const decodedMetadata = ApplicationMetadataMessage.decode(messageToDecode)
|
||||||
decodedProtocol.publicMessage
|
|
||||||
)
|
|
||||||
if (!decodedMetadata.payload) {
|
if (!decodedMetadata.payload) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
messageToDecode = decodedMetadata.payload
|
||||||
|
|
||||||
// todo?: process other types of messages
|
// todo: merge and process other types of messages
|
||||||
if (
|
if (
|
||||||
decodedMetadata.type !== ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE
|
decodedMetadata.type !== ApplicationMetadataMessage.Type.TYPE_CHAT_MESSAGE
|
||||||
) {
|
) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedPayload = ChatMessage.decode(decodedMetadata.payload)
|
const decodedPayload = ChatMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = payloadToId(
|
const messageId = payloadToId(
|
||||||
decodedProtocol.publicMessage,
|
decodedProtocol.publicMessage,
|
||||||
|
|
|
@ -35,28 +35,37 @@ export function handleChannelChatMessage(
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedProtocol = ProtocolMessage.decode(wakuMessage.payload)
|
let messageToDecode = wakuMessage.payload
|
||||||
|
let decodedProtocol
|
||||||
|
|
||||||
|
try {
|
||||||
|
decodedProtocol = ProtocolMessage.decode(wakuMessage.payload)
|
||||||
|
if (decodedProtocol) {
|
||||||
|
messageToDecode = decodedProtocol.publicMessage
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
// fixme!: remove after replacing payloadToId
|
||||||
if (!decodedProtocol) {
|
if (!decodedProtocol) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedMetadata = ApplicationMetadataMessage.decode(
|
const decodedMetadata = ApplicationMetadataMessage.decode(messageToDecode)
|
||||||
decodedProtocol.publicMessage
|
|
||||||
)
|
|
||||||
|
|
||||||
if (!decodedMetadata.payload) {
|
if (!decodedMetadata.payload) {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
messageToDecode = decodedMetadata.payload
|
||||||
|
|
||||||
// todo?:
|
// todo?:
|
||||||
// if (!decodedMetadata.identity) {
|
// if (!decodedMetadata.identity) {
|
||||||
// break
|
// break
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
// 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(decodedMetadata.payload)
|
const decodedPayload = ChatMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = payloadToId(
|
const messageId = payloadToId(
|
||||||
decodedProtocol.publicMessage,
|
decodedProtocol.publicMessage,
|
||||||
|
@ -99,7 +108,7 @@ export function handleChannelChatMessage(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ApplicationMetadataMessage.Type.TYPE_EDIT_MESSAGE: {
|
case ApplicationMetadataMessage.Type.TYPE_EDIT_MESSAGE: {
|
||||||
const decodedPayload = EditMessage.decode(decodedMetadata.payload)
|
const decodedPayload = EditMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = decodedPayload.messageId
|
const messageId = decodedPayload.messageId
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
@ -139,7 +148,7 @@ export function handleChannelChatMessage(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ApplicationMetadataMessage.Type.TYPE_DELETE_MESSAGE: {
|
case ApplicationMetadataMessage.Type.TYPE_DELETE_MESSAGE: {
|
||||||
const decodedPayload = DeleteMessage.decode(decodedMetadata.payload)
|
const decodedPayload = DeleteMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = decodedPayload.messageId
|
const messageId = decodedPayload.messageId
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
@ -168,7 +177,7 @@ export function handleChannelChatMessage(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ApplicationMetadataMessage.Type.TYPE_PIN_MESSAGE: {
|
case ApplicationMetadataMessage.Type.TYPE_PIN_MESSAGE: {
|
||||||
const decodedPayload = PinMessage.decode(decodedMetadata.payload)
|
const decodedPayload = PinMessage.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = decodedPayload.messageId
|
const messageId = decodedPayload.messageId
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
@ -196,7 +205,7 @@ export function handleChannelChatMessage(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
case ApplicationMetadataMessage.Type.TYPE_EMOJI_REACTION: {
|
case ApplicationMetadataMessage.Type.TYPE_EMOJI_REACTION: {
|
||||||
const decodedPayload = EmojiReaction.decode(decodedMetadata.payload)
|
const decodedPayload = EmojiReaction.decode(messageToDecode)
|
||||||
|
|
||||||
const messageId = decodedPayload.messageId
|
const messageId = decodedPayload.messageId
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
||||||
|
import { ProtocolMessage } from '../../../protos/protocol-message'
|
||||||
import { CommunityDescription } from '../../wire/community_description'
|
import { CommunityDescription } from '../../wire/community_description'
|
||||||
|
|
||||||
import type { CommunityMetadataType } from './community'
|
import type { CommunityMetadataType } from './community'
|
||||||
|
@ -11,12 +12,34 @@ export function handleCommunity(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedMetadata = ApplicationMetadataMessage.decode(wakuMessage.payload)
|
if (!wakuMessage.signaturePublicKey) {
|
||||||
if (!decodedMetadata.payload) {
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
const decodedPayload = CommunityDescription.decode(decodedMetadata.payload)
|
let messageToDecode = wakuMessage.payload
|
||||||
|
|
||||||
|
try {
|
||||||
|
const decodedProtocol = ProtocolMessage.decode(messageToDecode)
|
||||||
|
if (decodedProtocol) {
|
||||||
|
messageToDecode = decodedProtocol.publicMessage
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
|
|
||||||
|
const decodedMetadata = ApplicationMetadataMessage.decode(messageToDecode)
|
||||||
|
if (!decodedMetadata.payload) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
messageToDecode = decodedMetadata.payload
|
||||||
|
|
||||||
|
// todo: merge and process other types of messages
|
||||||
|
if (
|
||||||
|
decodedMetadata.type !==
|
||||||
|
ApplicationMetadataMessage.Type.TYPE_COMMUNITY_DESCRIPTION
|
||||||
|
) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const decodedPayload = CommunityDescription.decode(messageToDecode)
|
||||||
// todo!: explain
|
// todo!: explain
|
||||||
if (!decodedPayload.identity) {
|
if (!decodedPayload.identity) {
|
||||||
return
|
return
|
||||||
|
|
|
@ -13,7 +13,7 @@ const CHANNEL_ID =
|
||||||
|
|
||||||
await client.createAccount()
|
await client.createAccount()
|
||||||
|
|
||||||
const communityMetadata = client.community.fetchCommunity()
|
const communityMetadata = await client.community.fetchCommunity()
|
||||||
|
|
||||||
const fetchChannelMessages =
|
const fetchChannelMessages =
|
||||||
await client.community.createFetchChannelMessages(CHANNEL_ID, messages =>
|
await client.community.createFetchChannelMessages(CHANNEL_ID, messages =>
|
||||||
|
|
Loading…
Reference in New Issue