From 6dd936fbe153e857e6c0102e95f3d054b1b7718d Mon Sep 17 00:00:00 2001 From: kim <89579420+NyaaaWhatsUpDoc@users.noreply.github.com> Date: Mon, 16 Sep 2024 11:38:12 +0000 Subject: [PATCH] [bugfix/chore] Always set the status sensitive if media + content-warning present (#3308) * always set the status sensitive flag to true if it has a content-warning with media * whoops use attachment ids instead of mention ids ... :facepalm: --- internal/processing/status/create.go | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/internal/processing/status/create.go b/internal/processing/status/create.go index d5898ffe9..5f2cb8212 100644 --- a/internal/processing/status/create.go +++ b/internal/processing/status/create.go @@ -495,22 +495,16 @@ func (p *Processor) processContent(ctx context.Context, parseMention gtsmodel.Pa } // Gather all the database IDs from each of the gathered status mentions, tags, and emojis. - status.MentionIDs = gatherIDs(status.Mentions, func(mention *gtsmodel.Mention) string { return mention.ID }) - status.TagIDs = gatherIDs(status.Tags, func(tag *gtsmodel.Tag) string { return tag.ID }) - status.EmojiIDs = gatherIDs(status.Emojis, func(emoji *gtsmodel.Emoji) string { return emoji.ID }) + status.MentionIDs = util.Gather(nil, status.Mentions, func(mention *gtsmodel.Mention) string { return mention.ID }) + status.TagIDs = util.Gather(nil, status.Tags, func(tag *gtsmodel.Tag) string { return tag.ID }) + status.EmojiIDs = util.Gather(nil, status.Emojis, func(emoji *gtsmodel.Emoji) string { return emoji.ID }) + + if status.ContentWarning != "" && len(status.AttachmentIDs) > 0 { + // If a content-warning is set, and + // the status contains media, always + // set the status sensitive flag. + status.Sensitive = util.Ptr(true) + } return nil } - -// gatherIDs is a small utility function to gather IDs from a slice of type T. -func gatherIDs[T any](in []T, getID func(T) string) []string { - if getID == nil { - // move nil check out loop. - panic("nil getID function") - } - ids := make([]string, len(in)) - for i, t := range in { - ids[i] = getID(t) - } - return ids -}