Don't require url/asset for snippet creation from discord.
This commit is contained in:
parent
444f43a195
commit
cd36eb44eb
|
@ -834,43 +834,42 @@ func HandleSnippetForInternedMessage(ctx context.Context, dbConn db.ConnOrTx, in
|
||||||
if shouldCreate {
|
if shouldCreate {
|
||||||
// Get an asset ID or URL to make a snippet from
|
// Get an asset ID or URL to make a snippet from
|
||||||
assetId, url, err := getSnippetAssetOrUrl(ctx, tx, &interned.Message)
|
assetId, url, err := getSnippetAssetOrUrl(ctx, tx, &interned.Message)
|
||||||
if assetId != nil || url != nil {
|
|
||||||
contentMarkdown := interned.MessageContent.LastContent
|
|
||||||
contentHTML := parsing.ParseMarkdown(contentMarkdown, parsing.DiscordMarkdown)
|
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
contentMarkdown := interned.MessageContent.LastContent
|
||||||
`
|
contentHTML := parsing.ParseMarkdown(contentMarkdown, parsing.DiscordMarkdown)
|
||||||
INSERT INTO snippet (url, "when", description, _description_html, asset_id, discord_message_id, owner_id)
|
|
||||||
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
|
||||||
`,
|
|
||||||
url,
|
|
||||||
interned.Message.SentAt,
|
|
||||||
contentMarkdown,
|
|
||||||
contentHTML,
|
|
||||||
assetId,
|
|
||||||
interned.Message.ID,
|
|
||||||
interned.HMNUser.ID,
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return oops.New(err, "failed to create snippet from attachment")
|
|
||||||
}
|
|
||||||
|
|
||||||
existingSnippet, err = FetchSnippetForMessage(ctx, tx, interned.Message.ID)
|
_, err = tx.Exec(ctx,
|
||||||
if err != nil {
|
`
|
||||||
return oops.New(err, "failed to fetch newly-created snippet")
|
INSERT INTO snippet (url, "when", description, _description_html, asset_id, discord_message_id, owner_id)
|
||||||
}
|
VALUES ($1, $2, $3, $4, $5, $6, $7)
|
||||||
|
`,
|
||||||
|
url,
|
||||||
|
interned.Message.SentAt,
|
||||||
|
contentMarkdown,
|
||||||
|
contentHTML,
|
||||||
|
assetId,
|
||||||
|
interned.Message.ID,
|
||||||
|
interned.HMNUser.ID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return oops.New(err, "failed to create snippet from attachment")
|
||||||
|
}
|
||||||
|
|
||||||
_, err = tx.Exec(ctx,
|
existingSnippet, err = FetchSnippetForMessage(ctx, tx, interned.Message.ID)
|
||||||
`
|
if err != nil {
|
||||||
UPDATE discord_message
|
return oops.New(err, "failed to fetch newly-created snippet")
|
||||||
SET snippet_created = TRUE
|
}
|
||||||
WHERE id = $1
|
|
||||||
`,
|
_, err = tx.Exec(ctx,
|
||||||
interned.Message.ID,
|
`
|
||||||
)
|
UPDATE discord_message
|
||||||
if err != nil {
|
SET snippet_created = TRUE
|
||||||
return oops.New(err, "failed to mark message as having snippet")
|
WHERE id = $1
|
||||||
}
|
`,
|
||||||
|
interned.Message.ID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return oops.New(err, "failed to mark message as having snippet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue