Skip to content

Commit 0893126

Browse files
committed
Wire in contribution descriptions
1 parent 8a6ba42 commit 0893126

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

src/Share/BackgroundJobs/Webhooks/Worker.hs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,9 +214,13 @@ data ChatProvider
214214

215215
-- A type to unify slack and discord message types
216216
data MessageContent (provider :: ChatProvider) = MessageContent
217-
{ -- | The content of the primary message.
218-
content :: Text,
217+
{ -- Text of the bot message
218+
preText :: Text,
219+
-- Title of the attachment
219220
title :: Text,
221+
-- Text of the attachment
222+
content :: Text,
223+
-- Title link
220224
mainLink :: URI,
221225
authorName :: Text,
222226
authorLink :: URI,
@@ -227,9 +231,9 @@ data MessageContent (provider :: ChatProvider) = MessageContent
227231
deriving stock (Show, Eq)
228232

229233
instance ToJSON (MessageContent 'Slack) where
230-
toJSON MessageContent {content, title, mainLink, authorName, authorLink, authorAvatarUrl, thumbnailUrl, timestamp} =
234+
toJSON MessageContent {preText, content, title, mainLink, authorName, authorLink, authorAvatarUrl, thumbnailUrl, timestamp} =
231235
Aeson.object
232-
[ "text" .= content,
236+
[ "text" .= preText,
233237
"attachments"
234238
.= [ Aeson.object
235239
[ "title" .= title,
@@ -246,11 +250,11 @@ instance ToJSON (MessageContent 'Slack) where
246250
]
247251

248252
instance ToJSON (MessageContent 'Discord) where
249-
toJSON MessageContent {content, title, mainLink, authorName, authorLink, authorAvatarUrl, thumbnailUrl, timestamp} =
253+
toJSON MessageContent {preText, content, title, mainLink, authorName, authorLink, authorAvatarUrl, thumbnailUrl, timestamp} =
250254
Aeson.object
251255
[ "username" .= ("Share Notification" :: Text),
252256
"avatar_url" .= Links.unisonLogoImage,
253-
"content" .= content,
257+
"content" .= preText,
254258
"embeds"
255259
.= [ Aeson.object
256260
[ "title" .= title,
@@ -266,9 +270,9 @@ instance ToJSON (MessageContent 'Discord) where
266270
buildWebhookRequest :: NotificationWebhookId -> URI -> NotificationEvent NotificationEventId UnifiedDisplayInfo UTCTime HydratedEventPayload -> WebhookEventPayload JWTParam -> Background (Either WebhookSendFailure HTTPClient.Request)
267271
buildWebhookRequest webhookId uri event defaultPayload = do
268272
if
269-
| isSlackWebhook uri -> buildChatAppPayload (Proxy @Slack) uri
270-
| isDiscordWebhook uri -> buildChatAppPayload (Proxy @Discord) uri
271-
| otherwise -> pure $ buildDefaultPayload
273+
| isSlackWebhook uri -> buildChatAppPayload (Proxy @Slack) uri
274+
| isDiscordWebhook uri -> buildChatAppPayload (Proxy @Discord) uri
275+
| otherwise -> pure $ buildDefaultPayload
272276
where
273277
isSlackWebhook :: URI -> Bool
274278
isSlackWebhook uri =
@@ -311,7 +315,8 @@ buildWebhookRequest webhookId uri event defaultPayload = do
311315
link <- Links.notificationLink event.eventData
312316
pure $
313317
MessageContent
314-
{ content = preText,
318+
{ preText = preText,
319+
content = "Branch updated",
315320
title = title,
316321
mainLink = link,
317322
authorName = actorAuthor,
@@ -323,11 +328,13 @@ buildWebhookRequest webhookId uri event defaultPayload = do
323328
HydratedProjectContributionCreatedPayload payload -> do
324329
let pbShorthand = (projectBranchShortHandFromParts payload.projectInfo.projectShortHand payload.contributionInfo.contributionSourceBranch.branchShortHand)
325330
title = payload.contributionInfo.contributionTitle
331+
description = fromMaybe "" $ payload.contributionInfo.contributionDescription
326332
preText = "New Contribution in " <> IDs.toText pbShorthand
327333
link <- Links.notificationLink event.eventData
328334
pure $
329335
MessageContent
330-
{ content = preText,
336+
{ preText = preText,
337+
content = description,
331338
title = title,
332339
mainLink = link,
333340
authorName = actorAuthor,

0 commit comments

Comments
 (0)