mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-01-14 07:57:57 -05:00
Compare commits
1 Commits
streamBuff
...
commentRep
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6350008ec2 |
@@ -582,6 +582,12 @@ 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
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -589,6 +595,10 @@ export interface ActivityState {
|
||||
* @examples [{"over_18": true, "removed": false}]
|
||||
* */
|
||||
export interface SubmissionState extends ActivityState {
|
||||
|
||||
// num_comments property
|
||||
replies?: CompareValue
|
||||
|
||||
pinned?: boolean
|
||||
spoiler?: boolean
|
||||
/**
|
||||
|
||||
@@ -166,3 +166,9 @@ export interface RedditRemovalMessageOptions {
|
||||
title?: string
|
||||
lock?: boolean
|
||||
}
|
||||
|
||||
export interface ListingMore {
|
||||
count: number
|
||||
children: string[]
|
||||
depth: number
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
activityIsFiltered,
|
||||
activityIsRemoved,
|
||||
getAuthorHistoryAPIOptions,
|
||||
getNumberOfReplies,
|
||||
renderContent,
|
||||
TemplateContext
|
||||
} from "../Utils/SnoowrapUtils";
|
||||
@@ -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)) {
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user