Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/Common/Infrastructure/Filters/FilterCriteria.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,13 +582,23 @@ export interface ActivityState {
* * If string or list of strings then color is matched, case-insensitive, without #. String may also be a regular expression enclosed in forward slashes.
* */
authorFlairBackgroundColor?: boolean | string | string[]

// submission => num_comments
// comment => replies[]
// but on comments this is only initially hydrated if comments were parsed from a submission
// otherwise its EMPTY and we need to make an API call to get them
//replies?: CompareValue
}

/**
* Different attributes a `Submission` can be in. Only include a property if you want to check it.
* @examples [{"over_18": true, "removed": false}]
* */
export interface SubmissionState extends ActivityState {

// num_comments property
replies?: CompareValue

pinned?: boolean
spoiler?: boolean
/**
Expand Down
6 changes: 6 additions & 0 deletions src/Common/Infrastructure/Reddit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,9 @@ export interface RedditRemovalMessageOptions {
title?: string
lock?: boolean
}

export interface ListingMore {
count: number
children: string[]
depth: number
}
14 changes: 14 additions & 0 deletions src/Subreddit/SubredditResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
activityIsFiltered,
activityIsRemoved,
getAuthorHistoryAPIOptions,
getNumberOfReplies,
renderContent,
TemplateContext
} from "../Utils/SnoowrapUtils";
Expand Down Expand Up @@ -2312,6 +2313,19 @@ export class SubredditResources {
propResultsMap.depth!.found = depth;
propResultsMap.depth!.passed = criteriaPassWithIncludeBehavior(comparisonTextOp(depth, depthCompare.operator, depthCompare.value), include);
break;
case 'replies':
if(asComment(item)) {
const repliesError = `Testing for number of replies on a Comment is not currently implemented`;
log.debug(repliesError);
propResultsMap.replies!.passed = false;
propResultsMap.replies!.reason = repliesError;
break;
}
const repliesCompare = parseGenericValueComparison(itemOptVal as string);
const replies = getNumberOfReplies(item);
propResultsMap.replies!.found = replies;
propResultsMap.replies!.passed = criteriaPassWithIncludeBehavior(comparisonTextOp(replies, repliesCompare.operator, repliesCompare.value), include);
break;
case 'upvoteRatio':
if(asSubmission(item)) {

Expand Down
21 changes: 21 additions & 0 deletions src/Utils/SnoowrapUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {StrongSubredditCriteria, SubredditCriteria} from "../Common/Infrastructu
import {DurationVal, GenericContentTemplateData} from "../Common/Infrastructure/Atomic";
import {ActivityWindowCriteria} from "../Common/Infrastructure/ActivityWindow";
import {
ListingMore,
SnoowrapActivity,
SubredditActivityAbsoluteBreakdown,
SubredditActivityBreakdown, SubredditActivityBreakdownByType
Expand Down Expand Up @@ -566,3 +567,23 @@ export const formatSubredditBreakdownAsMarkdownList = (data: SubredditActivityBr

return `${bd}\n`;
}

export const getListingMoreObj = <T>(list: Listing<T>): ListingMore | undefined => {
// @ts-ignore
if(list._more === null) {
return undefined;
}
// @ts-ignore
return (list._more as ListingMore);
}

export const getNumberOfReplies = (activity: SnoowrapActivity): number => {
if(asSubmission(activity)) {
return activity.num_comments;
}
const more = getListingMoreObj(activity.replies);
if(more === undefined) {
return activity.replies.length;
}
return activity.replies.length + more.children.length;
}
6 changes: 6 additions & 0 deletions tests/itemCriteria.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,12 @@ describe('Item Criteria', function () {
}, snoowrap, false), {depth: '> 1'}, NoopLogger, true)).passed);
});

it('Should detect number of replies on Submission', async function () {
assert.isTrue((await resource.isItem(new Submission({
num_comments: 3,
}, snoowrap, false), {depth: '> 1'}, NoopLogger, true)).passed);
});

it('Should detect upvote ratio on submission', async function () {
assert.isTrue((await resource.isItem(new Submission({
upvote_ratio: 0.55,
Expand Down