reddit-rss icon indicating copy to clipboard operation
reddit-rss copied to clipboard

Exclude flair

Open woj-tek opened this issue 2 years ago • 3 comments

It would be awesome to be able to see all entries except certain flairs.

woj-tek avatar Feb 19 '23 19:02 woj-tek

Do you know a sub that uses a lot of flares I can use to test this feature?

trashhalo avatar Feb 19 '23 21:02 trashhalo

Not sure if it qualifies as "a lot" but https://old.reddit.com/r/polska/ uses them (and AFAIR requires)

woj-tek avatar Feb 20 '23 16:02 woj-tek

I for the life of me couldn't get it to work with multiple values, but this seemed to work for blocking a single flair. @trashhalo maybe this could work?

var flair string
flairStr, hasFlair := r.URL.Query()["flair"]
if hasFlair {
	flair = flairStr[0]
}

var blockflair string
blockflairStr, hasblockflair := r.URL.Query()["blockflair"]
if hasblockflair {
	blockflair = blockflairStr[0]
}

loader := articleLoader(client, getArticle)
var thunks []dataloader.Thunk
for _, link := range result.Data.Children {
	if hasSafe && safe && (link.Data.Over18 || strings.ToLower(link.Data.LinkFlairText) == "nsfw") {
		continue
	}

	if scoreLimit && limit > link.Data.Score {
		continue
	}

	if hasFlair && flair != "" && link.Data.LinkFlairText != flair {
		continue
	}

	if hasblockflair && blockflair != "" && link.Data.LinkFlairText == blockflair {
		continue
	}

	thunks = append(thunks, loader.Load(ctx, dataKey(link.Data)))
}

drixtol avatar May 03 '23 03:05 drixtol