remove comments
This commit is contained in:
parent
020f20e801
commit
25943d29a5
|
@ -1,10 +1,7 @@
|
||||||
import React, { StrictMode } from 'react'
|
import React, { StrictMode } from 'react'
|
||||||
import { render } from 'react-dom'
|
import { render } from 'react-dom'
|
||||||
|
|
||||||
// FIXME!: fixme from; Unable to resolve path to module '@status-im/react'
|
|
||||||
import { Community } from '@status-im/react'
|
import { Community } from '@status-im/react'
|
||||||
// TODO?: import/rename Chats, Messages, Messenger
|
|
||||||
// TODO?: import/rename CommunityAndMessenger, or Status even
|
|
||||||
|
|
||||||
const App = () => {
|
const App = () => {
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -2,24 +2,6 @@
|
||||||
* @see https://specs.status.im/spec/1
|
* @see https://specs.status.im/spec/1
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// todo: write class for channels/chat
|
|
||||||
// todo: use Map
|
|
||||||
|
|
||||||
// todo: use single proto runtime
|
|
||||||
|
|
||||||
// todo: tests
|
|
||||||
|
|
||||||
// todo: handle disconnections; no messages after sleep; libp2p;
|
|
||||||
// todo: identities/members?
|
|
||||||
// todo?: observe channels
|
|
||||||
// todo?: rename channels to chats
|
|
||||||
// todo?: multiple communityCallback
|
|
||||||
// todo?: call onChannel* separately
|
|
||||||
// todo?: ignore messages of not yet approved users
|
|
||||||
// todo?: ignore messages with invalid signature
|
|
||||||
// todo?: handle encrypted waku messages
|
|
||||||
// todo?: handle waku messages/events without identity
|
|
||||||
|
|
||||||
import { hexToBytes } from 'ethereum-cryptography/utils'
|
import { hexToBytes } from 'ethereum-cryptography/utils'
|
||||||
import { Waku, WakuMessage } from 'js-waku'
|
import { Waku, WakuMessage } from 'js-waku'
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import type { Waku } from 'js-waku'
|
||||||
|
|
||||||
export type CommunityMetadataType = CommunityDescription['proto']
|
export type CommunityMetadataType = CommunityDescription['proto']
|
||||||
|
|
||||||
// todo?: rename to ChatMessageType
|
|
||||||
export type MessageType = ChatMessage & {
|
export type MessageType = ChatMessage & {
|
||||||
messageId: string
|
messageId: string
|
||||||
pinned: boolean
|
pinned: boolean
|
||||||
|
@ -31,7 +30,6 @@ export class Community {
|
||||||
private client: Client
|
private client: Client
|
||||||
private waku: Waku
|
private waku: Waku
|
||||||
public communityPublicKey: string
|
public communityPublicKey: string
|
||||||
// fixme!
|
|
||||||
private communityContentTopic!: string
|
private communityContentTopic!: string
|
||||||
private communityDecryptionKey!: Uint8Array
|
private communityDecryptionKey!: Uint8Array
|
||||||
public communityMetadata!: CommunityMetadataType // state
|
public communityMetadata!: CommunityMetadataType // state
|
||||||
|
@ -102,14 +100,12 @@ export class Community {
|
||||||
return communityMetadata
|
return communityMetadata
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo?: rename and implement as "fetch history" (e.g. emojis, however, would arrive first and not match)
|
|
||||||
public createFetchChannelMessages = async (
|
public createFetchChannelMessages = async (
|
||||||
channelId: string,
|
channelId: string,
|
||||||
callback: (messages: MessageType[]) => void
|
callback: (messages: MessageType[]) => void
|
||||||
) => {
|
) => {
|
||||||
const id = `${this.communityPublicKey}${channelId}`
|
const id = `${this.communityPublicKey}${channelId}`
|
||||||
const channelContentTopic = idToContentTopic(id)
|
const channelContentTopic = idToContentTopic(id)
|
||||||
// todo?: keep in state instead and replace the factory
|
|
||||||
const symKey = await createSymKeyFromPassword(id)
|
const symKey = await createSymKeyFromPassword(id)
|
||||||
|
|
||||||
return async (options: { start: Date }) => {
|
return async (options: { start: Date }) => {
|
||||||
|
@ -176,7 +172,6 @@ export class Community {
|
||||||
|
|
||||||
const symKey = await createSymKeyFromPassword(id)
|
const symKey = await createSymKeyFromPassword(id)
|
||||||
|
|
||||||
// todo?: request waku feature to be passed as param
|
|
||||||
this.waku.relay.addDecryptionKey(symKey, {
|
this.waku.relay.addDecryptionKey(symKey, {
|
||||||
method: waku_message.DecryptionMethod.Symmetric,
|
method: waku_message.DecryptionMethod.Symmetric,
|
||||||
contentTopics: [channelContentTopic],
|
contentTopics: [channelContentTopic],
|
||||||
|
@ -226,7 +221,6 @@ export class Community {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Community
|
// Community
|
||||||
// fixme!: set only if updated
|
|
||||||
this.communityMetadata = communityMetadata
|
this.communityMetadata = communityMetadata
|
||||||
this.communityCallback?.(communityMetadata)
|
this.communityCallback?.(communityMetadata)
|
||||||
}
|
}
|
||||||
|
@ -283,7 +277,6 @@ export class Community {
|
||||||
this.channelMessages[channelId] = _messages
|
this.channelMessages[channelId] = _messages
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
// todo!: review use of ! why not just use messages defined above?
|
|
||||||
this.channelMessagesCallbacks[channelId]?.(this.channelMessages[channelId]!)
|
this.channelMessagesCallbacks[channelId]?.(this.channelMessages[channelId]!)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,3 @@
|
||||||
// todo: move file
|
|
||||||
// fixme: relative paths
|
|
||||||
|
|
||||||
import { bytesToHex } from 'ethereum-cryptography/utils'
|
import { bytesToHex } from 'ethereum-cryptography/utils'
|
||||||
|
|
||||||
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
import { ApplicationMetadataMessage } from '../../../protos/application-metadata-message'
|
||||||
|
@ -24,17 +21,6 @@ import type { Client } from '../../client'
|
||||||
import type { Community /*, MessageType*/ } from './community'
|
import type { Community /*, MessageType*/ } from './community'
|
||||||
import type { WakuMessage } from 'js-waku'
|
import type { WakuMessage } from 'js-waku'
|
||||||
|
|
||||||
// todo?: return decoded, possibly mapped, event but do not update state and call callback
|
|
||||||
// todo?: return void
|
|
||||||
// todo?: return success (e.g. if this handler should be used in Community's init)
|
|
||||||
// fixme:
|
|
||||||
/**
|
|
||||||
* Argument of type '(wakuMessage: WakuMessage, community: Community) => boolean'
|
|
||||||
* is not assignable to parameter of type '(message: WakuMessage) => void'.ts(2345)
|
|
||||||
*/
|
|
||||||
// type HandlerResult = boolean
|
|
||||||
// type HandlerResult = CommunityDescription | MessageType | undefined
|
|
||||||
|
|
||||||
export function handleWakuMessage(
|
export function handleWakuMessage(
|
||||||
wakuMessage: WakuMessage,
|
wakuMessage: WakuMessage,
|
||||||
// state
|
// state
|
||||||
|
@ -47,7 +33,6 @@ export function handleWakuMessage(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: explain
|
|
||||||
if (!wakuMessage.signaturePublicKey) {
|
if (!wakuMessage.signaturePublicKey) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,7 +57,6 @@ export function handleWakuMessage(
|
||||||
decodedMetadata.payload
|
decodedMetadata.payload
|
||||||
)
|
)
|
||||||
|
|
||||||
// fixme?: handle decodedProtocol.encryptedMessage
|
|
||||||
const wakuMessageId = payloadToId(
|
const wakuMessageId = payloadToId(
|
||||||
decodedProtocol?.publicMessage || decodedMetadata.payload,
|
decodedProtocol?.publicMessage || decodedMetadata.payload,
|
||||||
publicKey
|
publicKey
|
||||||
|
@ -91,7 +75,6 @@ export function handleWakuMessage(
|
||||||
// decode
|
// decode
|
||||||
const decodedPayload = CommunityDescription.decode(messageToDecode)
|
const decodedPayload = CommunityDescription.decode(messageToDecode)
|
||||||
|
|
||||||
// todo?: don't use class method
|
|
||||||
// handle (state and callback)
|
// handle (state and callback)
|
||||||
community.handleCommunityMetadataEvent(decodedPayload)
|
community.handleCommunityMetadataEvent(decodedPayload)
|
||||||
|
|
||||||
|
@ -107,7 +90,6 @@ export function handleWakuMessage(
|
||||||
// TODO?: ignore community.channelMessages which are messageType !== COMMUNITY_CHAT
|
// TODO?: ignore community.channelMessages which are messageType !== COMMUNITY_CHAT
|
||||||
|
|
||||||
// map
|
// map
|
||||||
// todo?: use full chatId (incl. pub key) instead
|
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
|
||||||
const chatMessage = mapChatMessage(decodedPayload, {
|
const chatMessage = mapChatMessage(decodedPayload, {
|
||||||
|
@ -129,7 +111,6 @@ export function handleWakuMessage(
|
||||||
const messageId = decodedPayload.messageId
|
const messageId = decodedPayload.messageId
|
||||||
const channelId = getChannelId(decodedPayload.chatId)
|
const channelId = getChannelId(decodedPayload.chatId)
|
||||||
|
|
||||||
// todo?: move to class method (e.g. handleChannelChatMessageEditEvent)
|
|
||||||
const _messages = community.channelMessages[channelId] || []
|
const _messages = community.channelMessages[channelId] || []
|
||||||
|
|
||||||
let index = _messages.length
|
let index = _messages.length
|
||||||
|
@ -148,10 +129,8 @@ export function handleWakuMessage(
|
||||||
|
|
||||||
const _message = _messages[index]
|
const _message = _messages[index]
|
||||||
|
|
||||||
// todo?: use mapChatMessage
|
|
||||||
const message = {
|
const message = {
|
||||||
..._message,
|
..._message,
|
||||||
// fixme?: other fields that user can edit
|
|
||||||
text: decodedPayload.text,
|
text: decodedPayload.text,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +171,6 @@ export function handleWakuMessage(
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo?: use delete; set to null
|
|
||||||
_messages.splice(index, 1)
|
_messages.splice(index, 1)
|
||||||
|
|
||||||
// state
|
// state
|
||||||
|
@ -236,7 +214,6 @@ export function handleWakuMessage(
|
||||||
community.channelMessages[channelId] = _messages
|
community.channelMessages[channelId] = _messages
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
// todo!: review use of !
|
|
||||||
community.channelMessagesCallbacks[channelId]?.(
|
community.channelMessagesCallbacks[channelId]?.(
|
||||||
community.channelMessages[channelId]!
|
community.channelMessages[channelId]!
|
||||||
)
|
)
|
||||||
|
@ -272,7 +249,6 @@ export function handleWakuMessage(
|
||||||
const isMe =
|
const isMe =
|
||||||
account?.publicKey === `0x${bytesToHex(wakuMessage.signaturePublicKey)}`
|
account?.publicKey === `0x${bytesToHex(wakuMessage.signaturePublicKey)}`
|
||||||
|
|
||||||
// fixme!
|
|
||||||
_messages[index].reactions = getReactions(
|
_messages[index].reactions = getReactions(
|
||||||
decodedPayload,
|
decodedPayload,
|
||||||
_message.reactions,
|
_message.reactions,
|
||||||
|
|
|
@ -23,7 +23,6 @@ describe('Messenger', () => {
|
||||||
identityAlice = Identity.generate()
|
identityAlice = Identity.generate()
|
||||||
identityBob = Identity.generate()
|
identityBob = Identity.generate()
|
||||||
|
|
||||||
// todo: mock/provide WakuMock
|
|
||||||
dbg('Create messengers')
|
dbg('Create messengers')
|
||||||
;[messengerAlice, messengerBob] = await Promise.all([
|
;[messengerAlice, messengerBob] = await Promise.all([
|
||||||
Messenger.create(identityAlice, { bootstrap: {} }),
|
Messenger.create(identityAlice, { bootstrap: {} }),
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import debug from 'debug'
|
import debug from 'debug'
|
||||||
import { waku_message, WakuMessage } from 'js-waku'
|
import { Waku, waku_message, WakuMessage } from 'js-waku'
|
||||||
|
|
||||||
import { Chat } from './chat'
|
import { Chat } from './chat'
|
||||||
import { ApplicationMetadataMessage_Type } from './proto/status/v1/application_metadata_message'
|
import { ApplicationMetadataMessage_Type } from './proto/status/v1/application_metadata_message'
|
||||||
|
@ -9,11 +9,10 @@ import { ChatMessage } from './wire/chat_message'
|
||||||
|
|
||||||
import type { Identity } from './identity'
|
import type { Identity } from './identity'
|
||||||
import type { Content } from './wire/chat_message'
|
import type { Content } from './wire/chat_message'
|
||||||
import type { Waku } from 'js-waku'
|
import type { waku } from 'js-waku'
|
||||||
|
|
||||||
const dbg = debug('communities:messenger')
|
const dbg = debug('communities:messenger')
|
||||||
|
|
||||||
// TODO: pass waku client
|
|
||||||
export class Messenger {
|
export class Messenger {
|
||||||
waku: Waku
|
waku: Waku
|
||||||
chatsById: Map<string, Chat>
|
chatsById: Map<string, Chat>
|
||||||
|
@ -37,8 +36,6 @@ export class Messenger {
|
||||||
|
|
||||||
public static async create(
|
public static async create(
|
||||||
identity: Identity | undefined,
|
identity: Identity | undefined,
|
||||||
// wakuOptions?: waku.CreateOptions
|
|
||||||
// TODO: pass waku as client
|
|
||||||
wakuOptions?: waku.CreateOptions
|
wakuOptions?: waku.CreateOptions
|
||||||
): Promise<Messenger> {
|
): Promise<Messenger> {
|
||||||
const _wakuOptions = Object.assign(
|
const _wakuOptions = Object.assign(
|
||||||
|
|
|
@ -42,7 +42,6 @@ export class CommunityDescription {
|
||||||
|
|
||||||
const callback = (messages: WakuMessage[]): void => {
|
const callback = (messages: WakuMessage[]): void => {
|
||||||
// Value found, stop processing
|
// Value found, stop processing
|
||||||
// FIXME?: return true/false
|
|
||||||
if (communityDescription) return
|
if (communityDescription) return
|
||||||
|
|
||||||
// Process most recent message first
|
// Process most recent message first
|
||||||
|
@ -67,8 +66,6 @@ export class CommunityDescription {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// FIXME?: return true/false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const symKey = await createSymKeyFromPassword(hexCommunityPublicKey)
|
const symKey = await createSymKeyFromPassword(hexCommunityPublicKey)
|
||||||
|
|
Loading…
Reference in New Issue