From e671826e71d7e7630f189ec4bbf200814d71515d Mon Sep 17 00:00:00 2001 From: Bryce McMath Date: Tue, 29 Aug 2023 16:32:00 -0700 Subject: [PATCH 1/2] feat: enable notifications hook to include basic messages Signed-off-by: Bryce McMath --- app/src/hooks/notifications.ts | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/app/src/hooks/notifications.ts b/app/src/hooks/notifications.ts index 75fc6ace3..7512a6835 100644 --- a/app/src/hooks/notifications.ts +++ b/app/src/hooks/notifications.ts @@ -1,13 +1,19 @@ import { AnonCredsCredentialMetadataKey } from '@aries-framework/anoncreds/build/utils/metadata' import { + BasicMessageRecord, CredentialExchangeRecord as CredentialRecord, CredentialState, ProofExchangeRecord, ProofState, } from '@aries-framework/core' -import { useCredentialByState, useProofByState } from '@aries-framework/react-hooks' +import { useCredentialByState, useProofByState, useBasicMessages } from '@aries-framework/react-hooks' import { useStore } from 'aries-bifold' -import { CredentialMetadata, customMetadata } from 'aries-bifold/App/types/metadata' +import { + BasicMessageMetadata, + CredentialMetadata, + basicMessageCustomMetadata, + credentialCustomMetadata, +} from 'aries-bifold/App/types/metadata' import { ProofCustomMetadata, ProofMetadata } from 'aries-bifold/verifier' import { getInvitationCredentialDate, showBCIDSelector } from '../helpers/BCIDHelper' @@ -20,13 +26,28 @@ interface CustomNotification { interface Notifications { total: number - notifications: Array + notifications: Array } export const useNotifications = (): Notifications => { const [store] = useStore() const offers = useCredentialByState(CredentialState.OfferReceived) const proofsRequested = useProofByState(ProofState.RequestReceived) + const { records: basicMessages } = useBasicMessages() + // get all unseen messages + const unseenMessages: BasicMessageRecord[] = basicMessages.filter((msg) => { + const meta = msg.metadata.get(BasicMessageMetadata.customMetadata) as basicMessageCustomMetadata + return !meta?.seen + }) + // add one unseen message per contact to notifications + const contactsWithUnseenMessages: string[] = [] + const messagesToShow: BasicMessageRecord[] = [] + unseenMessages.forEach((msg) => { + if (!contactsWithUnseenMessages.includes(msg.connectionId)) { + contactsWithUnseenMessages.push(msg.connectionId) + messagesToShow.push(msg) + } + }) const proofsDone = useProofByState([ProofState.Done, ProofState.PresentationReceived]).filter( (proof: ProofExchangeRecord) => { if (proof.isVerified === undefined) return false @@ -37,7 +58,7 @@ export const useNotifications = (): Notifications => { ) const revoked = useCredentialByState(CredentialState.Done).filter((cred: CredentialRecord) => { // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const metadata = cred!.metadata.get(CredentialMetadata.customMetadata) as customMetadata + const metadata = cred!.metadata.get(CredentialMetadata.customMetadata) as credentialCustomMetadata if (cred?.revocationNotification && metadata?.revoked_seen == undefined) { return cred } @@ -58,7 +79,8 @@ export const useNotifications = (): Notifications => { ? [{ type: 'CustomNotification', createdAt: invitationDate, id: 'custom' }] : [] - let notifications: (CredentialRecord | ProofExchangeRecord | CustomNotification)[] = [ + let notifications: (BasicMessageRecord | CredentialRecord | ProofExchangeRecord | CustomNotification)[] = [ + ...messagesToShow, ...offers, ...proofsRequested, ...proofsDone, From 5c794a0e94e9e342fd71aa80733bc5596db3a005 Mon Sep 17 00:00:00 2001 From: Bryce McMath Date: Wed, 30 Aug 2023 11:19:02 -0700 Subject: [PATCH 2/2] chore: update submodule Signed-off-by: Bryce McMath --- bifold | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bifold b/bifold index a8bb8ae26..2a844a609 160000 --- a/bifold +++ b/bifold @@ -1 +1 @@ -Subproject commit a8bb8ae261176c4b2b70988171c5894111c8e341 +Subproject commit 2a844a6092ae56cd02e0cbddcfc3a203da607c82