replace new Promise in observer

This commit is contained in:
Felicio Mununga 2022-06-08 11:52:55 +02:00
parent 54fadb0cd2
commit 260d4a4001
No known key found for this signature in database
GPG Key ID: 0EB8D75C775AB6F1
1 changed files with 11 additions and 18 deletions

View File

@ -102,7 +102,7 @@ export class Community {
) => { ) => {
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 // todo?: keep in state instead and replace the factory
const symKey = await createSymKeyFromPassword(id) const symKey = await createSymKeyFromPassword(id)
return async (options: { start: Date; end?: Date }) => { return async (options: { start: Date; end?: Date }) => {
@ -134,21 +134,19 @@ export class Community {
} }
private observeChannelMessages = async (chatsIds: string[]) => { private observeChannelMessages = async (chatsIds: string[]) => {
const symKeyPromises = chatsIds.map((chatId: string) => { const symKeyPromises = chatsIds.map(async (chatId: string) => {
return new Promise<string>(resolve => {
const id = `${this.communityPublicKey}${chatId}` const id = `${this.communityPublicKey}${chatId}`
const channelContentTopic = idToContentTopic(id) const channelContentTopic = idToContentTopic(id)
createSymKeyFromPassword(id).then(symKey => { const symKey = await createSymKeyFromPassword(id)
// todo: request waku feature to be passed as param
// 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],
}) })
resolve(channelContentTopic) return channelContentTopic
})
})
}) })
const contentTopics = await Promise.all(symKeyPromises) const contentTopics = await Promise.all(symKeyPromises)
@ -207,11 +205,6 @@ export class Community {
// state // state
const channelId = messages[0].channelId const channelId = messages[0].channelId
// todo: don't use; insert in-place
// const sortedMessages = sortBy(messages, ['timestamp'])
// todo: don't use; check prior insert
// const uniqueChannelMessages = uniqBy(sortedMessages, 'messageId')
// todo?: remove undefined left after deletion
this.channelMessages[channelId] = messages this.channelMessages[channelId] = messages
// callback // callback