@@ -33,6 +33,7 @@ import Share.IDs qualified as IDs
3333import Share.JWT (JWTParam (.. ))
3434import Share.JWT qualified as JWT
3535import Share.Metrics qualified as Metrics
36+ import Share.Notifications.Ops qualified as NotOps
3637import Share.Notifications.Queries qualified as NQ
3738import Share.Notifications.Types
3839import Share.Notifications.Webhooks.Secrets (WebhookConfig (.. ), WebhookSecretError )
@@ -138,7 +139,7 @@ data WebhookEventPayload jwt = WebhookEventPayload
138139 -- | The topic of the notification event.
139140 topic :: NotificationTopic ,
140141 -- | The data associated with the notification event.
141- data_ :: HydratedEventPayload ,
142+ data_ :: HydratedEvent ,
142143 -- | A signed token containing all of the same data.
143144 jwt :: jwt
144145 }
@@ -175,7 +176,7 @@ instance FromJSON (WebhookEventPayload ()) where
175176 <*> pure ()
176177
177178tryWebhook ::
178- NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload ->
179+ NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEvent ->
179180 NotificationWebhookId ->
180181 Background (Maybe WebhookSendFailure )
181182tryWebhook event webhookId = UnliftIO. handleAny (\ someException -> pure $ Just $ InvalidRequest event. eventId webhookId someException) do
@@ -206,7 +207,7 @@ tryWebhook event webhookId = UnliftIO.handleAny (\someException -> pure $ Just $
206207 | status >= 400 -> throwError $ ReceiverError event. eventId webhookId httpStatus $ HTTPClient. responseBody resp
207208 | otherwise -> pure ()
208209
209- buildWebhookRequest :: NotificationWebhookId -> URI -> NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload -> WebhookEventPayload JWTParam -> Background (Either WebhookSendFailure HTTPClient. Request )
210+ buildWebhookRequest :: NotificationWebhookId -> URI -> NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEvent -> WebhookEventPayload JWTParam -> Background (Either WebhookSendFailure HTTPClient. Request )
210211buildWebhookRequest webhookId uri event defaultPayload = do
211212 if
212213 | isSlackWebhook uri -> buildChatAppPayload (Proxy @ ChatApps. Slack ) uri
@@ -246,18 +247,18 @@ buildWebhookRequest webhookId uri event defaultPayload = do
246247 actorAuthor = maybe " " (<> " " ) actorName <> actorHandle
247248 actorAvatarUrl = event. eventActor ^. DisplayInfo. avatarUrl_
248249 actorLink <- Links. userProfilePage (event. eventActor ^. DisplayInfo. handle_)
249- messageContent :: ChatApps. MessageContent provider <- case event. eventData of
250+ let mainLink = Just event. eventData. hydratedEventLink
251+ messageContent :: ChatApps. MessageContent provider <- case event. eventData. hydratedEventPayload of
250252 HydratedProjectBranchUpdatedPayload payload -> do
251253 let pbShorthand = (projectBranchShortHandFromParts payload. projectInfo. projectShortHand payload. branchInfo. branchShortHand)
252254 title = " Branch " <> IDs. toText pbShorthand <> " was just updated."
253255 preText = title
254- link <- Links. notificationLink event. eventData
255256 pure $
256257 ChatApps. MessageContent
257258 { preText = preText,
258259 content = " Branch updated" ,
259260 title = title,
260- mainLink = Just link ,
261+ mainLink,
261262 author =
262263 Author
263264 { authorName = Just actorAuthor,
@@ -272,13 +273,12 @@ buildWebhookRequest webhookId uri event defaultPayload = do
272273 title = payload. contributionInfo. contributionTitle
273274 description = fromMaybe " " $ payload. contributionInfo. contributionDescription
274275 preText = " New Contribution in " <> IDs. toText pbShorthand
275- link <- Links. notificationLink event. eventData
276276 pure $
277277 ChatApps. MessageContent
278278 { preText = preText,
279279 content = description,
280280 title = title,
281- mainLink = Just link ,
281+ mainLink,
282282 author =
283283 Author
284284 { authorName = Just actorAuthor,
@@ -302,13 +302,14 @@ buildWebhookRequest webhookId uri event defaultPayload = do
302302
303303attemptWebhookSend ::
304304 AuthZ. AuthZReceipt ->
305- (NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload -> NotificationWebhookId -> IO (Maybe WebhookSendFailure )) ->
305+ (NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEvent -> NotificationWebhookId -> IO (Maybe WebhookSendFailure )) ->
306306 NotificationEventId ->
307307 NotificationWebhookId ->
308308 PG. Transaction e (Maybe WebhookSendFailure )
309309attemptWebhookSend _authZReceipt tryWebhookIO eventId webhookId = do
310310 event <- NQ. expectEvent eventId
311- hydratedEvent <- forOf eventData_ event NQ. hydrateEventData
311+ hydratedEventPayload <- forOf eventData_ event NQ. hydrateEventPayload
312+ hydratedEvent <- for hydratedEventPayload NotOps. hydrateEvent
312313 populatedEvent <- hydratedEvent & DisplayInfoQ. unifiedDisplayInfoForUserOf eventUserInfo_
313314 PG. transactionUnsafeIO (tryWebhookIO populatedEvent webhookId) >>= \ case
314315 Just err -> do
0 commit comments