Skip to content

Commit

Permalink
Add getEncryptedEntries method to channel store
Browse files Browse the repository at this point in the history
  • Loading branch information
islathehut committed Feb 10, 2025
1 parent aa6d84a commit 9a4427a
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions packages/backend/src/nest/storage/channels/channel.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ export class ChannelStore extends EventStoreBase<EncryptedMessage, ConsumedChann
}

/**
* Read a list of entries on the OrbitDB event store
* Read a list of entries on the OrbitDB event store and decrypt
*
* @param ids Optional list of message IDs to filter by
* @returns All matching entries on the event store
Expand All @@ -244,8 +244,6 @@ export class ChannelStore extends EventStoreBase<EncryptedMessage, ConsumedChann

for await (const x of this.getStore().iterator()) {
if (ids == null || ids?.includes(x.value.id)) {
// NOTE: we skipped the verification process when reading many messages in the previous version
// so I'm skipping it here - is that really the correct behavior?
const decryptedMessage = await this.messagesService.onConsume(x.value)
if (decryptedMessage == null) {
continue
Expand All @@ -257,6 +255,27 @@ export class ChannelStore extends EventStoreBase<EncryptedMessage, ConsumedChann
return messages
}

/**
* Read a list of entries on the OrbitDB event store without decrypting
*
* @param ids Optional list of message IDs to filter by
* @returns All matching entries on the event store
*/
public async getEncryptedEntries(): Promise<EncryptedMessage[]>
public async getEncryptedEntries(ids: string[] | undefined): Promise<EncryptedMessage[]>
public async getEncryptedEntries(ids?: string[] | undefined): Promise<EncryptedMessage[]> {
this.logger.info(`Getting all encrypted messages for channel`, this.channelData.id, this.channelData.name)
const messages: EncryptedMessage[] = []

for await (const x of this.getStore().iterator()) {
if (ids == null || ids?.includes(x.value.id)) {
messages.push(x.value)
}
}

return messages
}

// Close Logic

/**
Expand Down

0 comments on commit 9a4427a

Please sign in to comment.