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