@@ -126,39 +126,80 @@ async function getDiscussionUrl(
126126) : Promise < string >  { 
127127  let  url  =  `${ notification . repository . html_url }  /discussions` ; 
128128
129+   const  discussion  =  await  fetchDiscussion ( notification ,  token ,  true ) ; 
130+ 
131+   if  ( discussion )  { 
132+     url  =  discussion . url ; 
133+ 
134+     let  comments  =  discussion . comments . nodes ; 
135+ 
136+     let  latestCommentId : string  |  number ; 
137+ 
138+     if  ( comments ?. length )  { 
139+       latestCommentId  =  getLatestDiscussionCommentId ( comments ) ; 
140+       url  +=  `#discussioncomment-${ latestCommentId }  ` ; 
141+     } 
142+   } 
143+ 
144+   return  url ; 
145+ } 
146+ 
147+ export  async  function  fetchDiscussion ( 
148+   notification : Notification , 
149+   token : string , 
150+   includeComments : boolean , 
151+ ) : Promise < DiscussionSearchResultNode  |  null >  { 
129152  const  response : GraphQLSearch < DiscussionSearchResultNode >  = 
130153    await  apiRequestAuth ( `https://api.github.com/graphql` ,  'POST' ,  token ,  { 
131-       query : `{ 
132-         search(query:"${ formatSearchQueryString (  
133-           notification . repository . full_name ,  
134-           notification . subject . title ,  
135-           notification . updated_at ,  
136-         ) }  ", type: DISCUSSION, first: 10) {
137-           nodes { 
138-             ... on Discussion { 
139-               viewerSubscription 
140-               title 
141-               url 
142-               comments(last: 100) { 
143-                 nodes { 
144-                   databaseId 
145-                   createdAt 
146-                   replies(last: 1) { 
147-                     nodes { 
148-                       databaseId 
149-                       createdAt 
154+       query : `query fetchDiscussions( 
155+           $includeComments: Boolean!, 
156+           $queryStatement: String!, 
157+           $type: SearchType!, 
158+           $firstDiscussions: Int, 
159+           $lastComments: Int, 
160+           $firstReplies: Int 
161+         ) { 
162+           search(query:$queryStatement, type: $type, first: $firstDiscussions) { 
163+             nodes { 
164+               ... on Discussion { 
165+                 viewerSubscription 
166+                 title 
167+                 stateReason 
168+                 isAnswered 
169+                 url 
170+                 comments(last: $lastComments) @include(if: $includeComments){ 
171+                   nodes { 
172+                     databaseId 
173+                     createdAt 
174+                     replies(last: $firstReplies) { 
175+                       nodes { 
176+                         databaseId 
177+                         createdAt 
178+                       } 
150179                    } 
151180                  } 
152181                } 
153182              } 
154183            } 
155184          } 
156185        } 
157-       }` , 
186+       ` , 
187+       variables : { 
188+         queryStatement : formatSearchQueryString ( 
189+           notification . repository . full_name , 
190+           notification . subject . title , 
191+           notification . updated_at , 
192+         ) , 
193+         type : 'DISCUSSION' , 
194+         firstDiscussions : 10 , 
195+         lastComments : 100 , 
196+         firstReplies : 1 , 
197+         includeComments : includeComments , 
198+       } , 
158199    } ) ; 
159200
160201  let  discussions  = 
161-     response ?. data ?. data ? .search ? .nodes ? .filter ( 
202+     response ?. data ?. data . search . nodes . filter ( 
162203      ( discussion )  =>  discussion . title  ===  notification . subject . title , 
163204    )  ||  [ ] ; 
164205
@@ -167,29 +208,17 @@ async function getDiscussionUrl(
167208      ( discussion )  =>  discussion . viewerSubscription  ===  'SUBSCRIBED' , 
168209    ) ; 
169210
170-   if  ( discussions [ 0 ] )  { 
171-     const  discussion  =  discussions [ 0 ] ; 
172-     url  =  discussion . url ; 
173- 
174-     let  comments  =  discussion . comments . nodes ; 
175- 
176-     let  latestCommentId : string  |  number ; 
177-     if  ( comments ?. length )  { 
178-       latestCommentId  =  getLatestDiscussionCommentId ( comments ) ; 
179-       url  +=  `#discussioncomment-${ latestCommentId }  ` ; 
180-     } 
181-   } 
182- 
183-   return  url ; 
211+   return  discussions [ 0 ] ; 
184212} 
185213
186- export  const  getLatestDiscussionCommentId   =   ( 
214+ export  function  getLatestDiscussionCommentId ( 
187215  comments : DiscussionCommentNode [ ] , 
188- )  => 
189-   comments 
216+ )  { 
217+   return   comments 
190218    . flatMap ( ( comment )  =>  comment . replies . nodes ) 
191219    . concat ( [ comments . at ( - 1 ) ] ) 
192220    . reduce ( ( a ,  b )  =>  ( a . createdAt  >  b . createdAt  ? a  : b ) ) ?. databaseId ; 
221+ } 
193222
194223export  async  function  generateGitHubWebUrl ( 
195224  notification : Notification , 
0 commit comments