mirror of
https://github.com/FoxxMD/context-mod.git
synced 2026-01-14 16:08:02 -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.
|
* * 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[]
|
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}]
|
* @examples [{"over_18": true, "removed": false}]
|
||||||
* */
|
* */
|
||||||
export interface SubmissionState extends ActivityState {
|
export interface SubmissionState extends ActivityState {
|
||||||
|
|
||||||
|
// num_comments property
|
||||||
|
replies?: CompareValue
|
||||||
|
|
||||||
pinned?: boolean
|
pinned?: boolean
|
||||||
spoiler?: boolean
|
spoiler?: boolean
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -166,3 +166,9 @@ export interface RedditRemovalMessageOptions {
|
|||||||
title?: string
|
title?: string
|
||||||
lock?: boolean
|
lock?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ListingMore {
|
||||||
|
count: number
|
||||||
|
children: string[]
|
||||||
|
depth: number
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import {
|
|||||||
activityIsFiltered,
|
activityIsFiltered,
|
||||||
activityIsRemoved,
|
activityIsRemoved,
|
||||||
getAuthorHistoryAPIOptions,
|
getAuthorHistoryAPIOptions,
|
||||||
|
getNumberOfReplies,
|
||||||
renderContent,
|
renderContent,
|
||||||
TemplateContext
|
TemplateContext
|
||||||
} from "../Utils/SnoowrapUtils";
|
} from "../Utils/SnoowrapUtils";
|
||||||
@@ -2312,6 +2313,19 @@ export class SubredditResources {
|
|||||||
propResultsMap.depth!.found = depth;
|
propResultsMap.depth!.found = depth;
|
||||||
propResultsMap.depth!.passed = criteriaPassWithIncludeBehavior(comparisonTextOp(depth, depthCompare.operator, depthCompare.value), include);
|
propResultsMap.depth!.passed = criteriaPassWithIncludeBehavior(comparisonTextOp(depth, depthCompare.operator, depthCompare.value), include);
|
||||||
break;
|
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':
|
case 'upvoteRatio':
|
||||||
if(asSubmission(item)) {
|
if(asSubmission(item)) {
|
||||||
|
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ import {StrongSubredditCriteria, SubredditCriteria} from "../Common/Infrastructu
|
|||||||
import {DurationVal, GenericContentTemplateData} from "../Common/Infrastructure/Atomic";
|
import {DurationVal, GenericContentTemplateData} from "../Common/Infrastructure/Atomic";
|
||||||
import {ActivityWindowCriteria} from "../Common/Infrastructure/ActivityWindow";
|
import {ActivityWindowCriteria} from "../Common/Infrastructure/ActivityWindow";
|
||||||
import {
|
import {
|
||||||
|
ListingMore,
|
||||||
SnoowrapActivity,
|
SnoowrapActivity,
|
||||||
SubredditActivityAbsoluteBreakdown,
|
SubredditActivityAbsoluteBreakdown,
|
||||||
SubredditActivityBreakdown, SubredditActivityBreakdownByType
|
SubredditActivityBreakdown, SubredditActivityBreakdownByType
|
||||||
@@ -566,3 +567,23 @@ export const formatSubredditBreakdownAsMarkdownList = (data: SubredditActivityBr
|
|||||||
|
|
||||||
return `${bd}\n`;
|
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);
|
}, 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 () {
|
it('Should detect upvote ratio on submission', async function () {
|
||||||
assert.isTrue((await resource.isItem(new Submission({
|
assert.isTrue((await resource.isItem(new Submission({
|
||||||
upvote_ratio: 0.55,
|
upvote_ratio: 0.55,
|
||||||
|
|||||||
Reference in New Issue
Block a user