@@ -123,6 +123,24 @@ export const getFileSigners = (file: FileLike): SignerLike[] => {
123123 return [ ]
124124}
125125
126+ export const getCurrentUserSignRequestIds = ( document : DocumentLike ) : number [ ] => {
127+ const signRequestIds = new Set < number > ( )
128+ const addSignRequestId = ( signer : SignerLike | null | undefined ) => {
129+ if ( ! isCurrentUserSigner ( signer ) || signer . signRequestId === undefined ) {
130+ return
131+ }
132+ signRequestIds . add ( signer . signRequestId )
133+ }
134+
135+ const signers = Array . isArray ( document ?. signers ) ? document . signers : [ ]
136+ signers . forEach ( addSignRequestId )
137+
138+ const files = Array . isArray ( document ?. files ) ? document . files : [ ]
139+ files . flatMap ( ( file ) => getFileSigners ( file ) ) . forEach ( addSignRequestId )
140+
141+ return Array . from ( signRequestIds )
142+ }
143+
126144export const getVisibleElementsFromDocument = ( document : DocumentLike ) : VisibleElementRecord [ ] => {
127145 const topLevel = Array . isArray ( document ?. visibleElements ) ? document . visibleElements : [ ]
128146 const signers = Array . isArray ( document ?. signers ) ? document . signers : [ ]
@@ -131,6 +149,16 @@ export const getVisibleElementsFromDocument = (document: DocumentLike): VisibleE
131149 return deduplicateVisibleElements ( [ ...topLevel , ...nested , ...files ] )
132150}
133151
152+ export const hasVisibleElementsForCurrentUser = ( document : DocumentLike ) : boolean => {
153+ const signRequestIds = new Set ( getCurrentUserSignRequestIds ( document ) )
154+ if ( signRequestIds . size === 0 ) {
155+ return false
156+ }
157+
158+ return getVisibleElementsFromDocument ( document )
159+ . some ( ( element ) => element . signRequestId !== undefined && signRequestIds . has ( element . signRequestId ) )
160+ }
161+
134162export const getVisibleElementsFromFile = ( file : FileLike ) : VisibleElementRecord [ ] => {
135163 const topLevel = Array . isArray ( file ?. visibleElements ) ? file . visibleElements : [ ]
136164 const nested = collectSignerVisibleElements ( getFileSigners ( file ) )
0 commit comments