handle only MessageType.COMMUNITY_CHAT (#281)

This commit is contained in:
Felicio Mununga 2022-06-21 09:17:15 +02:00 committed by GitHub
parent 5d65d4d95e
commit cb88ee7a62
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 83 additions and 32 deletions

View File

@ -5,6 +5,7 @@ import {
ChatMessage, ChatMessage,
DeleteMessage, DeleteMessage,
EditMessage, EditMessage,
MessageType,
} from '../../../protos/chat-message' } from '../../../protos/chat-message'
import { EmojiReaction } from '../../../protos/emoji-reaction' import { EmojiReaction } from '../../../protos/emoji-reaction'
import { PinMessage } from '../../../protos/pin-message' import { PinMessage } from '../../../protos/pin-message'
@ -68,8 +69,8 @@ export function handleWakuMessage(
client.wakuMessages.add(messageId) client.wakuMessages.add(messageId)
// decode, map and handle (events)
try { try {
// decode, map and handle (events)
switch (decodedMetadata.type) { switch (decodedMetadata.type) {
case ApplicationMetadataMessage.Type.TYPE_COMMUNITY_DESCRIPTION: { case ApplicationMetadataMessage.Type.TYPE_COMMUNITY_DESCRIPTION: {
// decode // decode
@ -85,7 +86,8 @@ export function handleWakuMessage(
// decode // decode
const decodedPayload = ChatMessage.decode(messageToDecode) const decodedPayload = ChatMessage.decode(messageToDecode)
// TODO?: ignore community.channelMessages which are messageType !== COMMUNITY_CHAT switch (decodedPayload.messageType) {
case MessageType.COMMUNITY_CHAT: {
const chatUuid = getChatUuid(decodedPayload.chatId) const chatUuid = getChatUuid(decodedPayload.chatId)
// map // map
@ -100,9 +102,19 @@ export function handleWakuMessage(
break break
} }
default: {
break
}
}
break
}
case ApplicationMetadataMessage.Type.TYPE_EDIT_MESSAGE: { case ApplicationMetadataMessage.Type.TYPE_EDIT_MESSAGE: {
const decodedPayload = EditMessage.decode(messageToDecode) const decodedPayload = EditMessage.decode(messageToDecode)
switch (decodedPayload.messageType) {
case MessageType.COMMUNITY_CHAT: {
const messageId = decodedPayload.messageId const messageId = decodedPayload.messageId
const chatUuid = getChatUuid(decodedPayload.chatId) const chatUuid = getChatUuid(decodedPayload.chatId)
@ -113,9 +125,19 @@ export function handleWakuMessage(
break break
} }
default: {
break
}
}
break
}
case ApplicationMetadataMessage.Type.TYPE_DELETE_MESSAGE: { case ApplicationMetadataMessage.Type.TYPE_DELETE_MESSAGE: {
const decodedPayload = DeleteMessage.decode(messageToDecode) const decodedPayload = DeleteMessage.decode(messageToDecode)
switch (decodedPayload.messageType) {
case MessageType.COMMUNITY_CHAT: {
const messageId = decodedPayload.messageId const messageId = decodedPayload.messageId
const chatUuid = getChatUuid(decodedPayload.chatId) const chatUuid = getChatUuid(decodedPayload.chatId)
@ -124,9 +146,19 @@ export function handleWakuMessage(
break break
} }
default: {
break
}
}
break
}
case ApplicationMetadataMessage.Type.TYPE_PIN_MESSAGE: { case ApplicationMetadataMessage.Type.TYPE_PIN_MESSAGE: {
const decodedPayload = PinMessage.decode(messageToDecode) const decodedPayload = PinMessage.decode(messageToDecode)
switch (decodedPayload.messageType) {
case MessageType.COMMUNITY_CHAT: {
const messageId = decodedPayload.messageId const messageId = decodedPayload.messageId
const chatUuid = getChatUuid(decodedPayload.chatId) const chatUuid = getChatUuid(decodedPayload.chatId)
@ -137,9 +169,19 @@ export function handleWakuMessage(
break break
} }
default: {
break
}
}
break
}
case ApplicationMetadataMessage.Type.TYPE_EMOJI_REACTION: { case ApplicationMetadataMessage.Type.TYPE_EMOJI_REACTION: {
const decodedPayload = EmojiReaction.decode(messageToDecode) const decodedPayload = EmojiReaction.decode(messageToDecode)
switch (decodedPayload.messageType) {
case MessageType.COMMUNITY_CHAT: {
const messageId = decodedPayload.messageId const messageId = decodedPayload.messageId
const chatUuid = getChatUuid(decodedPayload.chatId) const chatUuid = getChatUuid(decodedPayload.chatId)
@ -154,9 +196,18 @@ export function handleWakuMessage(
break break
} }
default: default: {
break break
} }
}
break
}
default: {
break
}
}
} catch { } catch {
// protons-runtime throws when trying to decode invalid protocol buffers // protons-runtime throws when trying to decode invalid protocol buffers
// eslint-disable-next-line no-empty // eslint-disable-next-line no-empty