@devvit/reddit 0.11.17-next-2025-05-28-417d95f5a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +26 -0
- package/README.md +5 -0
- package/RedditClient.d.ts +1155 -0
- package/RedditClient.d.ts.map +1 -0
- package/RedditClient.js +1417 -0
- package/common.d.ts +10 -0
- package/common.d.ts.map +1 -0
- package/common.js +5 -0
- package/getReddit.d.ts +3 -0
- package/getReddit.d.ts.map +1 -0
- package/getReddit.js +8 -0
- package/getRedditApiPlugins.d.ts +23 -0
- package/getRedditApiPlugins.d.ts.map +1 -0
- package/getRedditApiPlugins.js +25 -0
- package/getUserActionsPlugin.d.ts +6 -0
- package/getUserActionsPlugin.d.ts.map +1 -0
- package/getUserActionsPlugin.js +12 -0
- package/graphql/GraphQL.d.ts +10 -0
- package/graphql/GraphQL.d.ts.map +1 -0
- package/graphql/GraphQL.js +27 -0
- package/helpers/makeGettersEnumerable.d.ts +2 -0
- package/helpers/makeGettersEnumerable.d.ts.map +1 -0
- package/helpers/makeGettersEnumerable.js +19 -0
- package/helpers/permissions.d.ts +6 -0
- package/helpers/permissions.d.ts.map +1 -0
- package/helpers/permissions.js +24 -0
- package/helpers/richtextToString.d.ts +3 -0
- package/helpers/richtextToString.d.ts.map +1 -0
- package/helpers/richtextToString.js +14 -0
- package/helpers/textFallbackToRichtext.d.ts +4 -0
- package/helpers/textFallbackToRichtext.d.ts.map +1 -0
- package/helpers/textFallbackToRichtext.js +14 -0
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -0
- package/index.js +1 -0
- package/models/Comment.d.ts +138 -0
- package/models/Comment.d.ts.map +1 -0
- package/models/Comment.js +597 -0
- package/models/Flair.d.ts +171 -0
- package/models/Flair.d.ts.map +1 -0
- package/models/Flair.js +293 -0
- package/models/Listing.d.ts +53 -0
- package/models/Listing.d.ts.map +1 -0
- package/models/Listing.js +101 -0
- package/models/ModAction.d.ts +32 -0
- package/models/ModAction.d.ts.map +1 -0
- package/models/ModAction.js +70 -0
- package/models/ModMail.d.ts +655 -0
- package/models/ModMail.d.ts.map +1 -0
- package/models/ModMail.js +723 -0
- package/models/ModNote.d.ts +57 -0
- package/models/ModNote.d.ts.map +1 -0
- package/models/ModNote.js +103 -0
- package/models/Post.d.ts +491 -0
- package/models/Post.d.ts.map +1 -0
- package/models/Post.js +1022 -0
- package/models/PrivateMessage.d.ts +52 -0
- package/models/PrivateMessage.d.ts.map +1 -0
- package/models/PrivateMessage.js +126 -0
- package/models/Subreddit.d.ts +606 -0
- package/models/Subreddit.d.ts.map +1 -0
- package/models/Subreddit.js +750 -0
- package/models/User.d.ts +238 -0
- package/models/User.d.ts.map +1 -0
- package/models/User.js +458 -0
- package/models/Vault.d.ts +32 -0
- package/models/Vault.d.ts.map +1 -0
- package/models/Vault.js +25 -0
- package/models/Widget.d.ts +133 -0
- package/models/Widget.d.ts.map +1 -0
- package/models/Widget.js +467 -0
- package/models/WikiPage.d.ts +137 -0
- package/models/WikiPage.d.ts.map +1 -0
- package/models/WikiPage.js +329 -0
- package/models/index.d.ts +14 -0
- package/models/index.d.ts.map +1 -0
- package/models/index.js +13 -0
- package/package.json +46 -0
- package/tests/comment.api.test.d.ts.map +1 -0
- package/tests/flair.api.test.d.ts.map +1 -0
- package/tests/modmail.api.test.d.ts.map +1 -0
- package/tests/modnote.api.test.d.ts.map +1 -0
- package/tests/post.api.test.d.ts.map +1 -0
- package/tests/subreddit.api.test.d.ts.map +1 -0
- package/tests/user.api.test.d.ts.map +1 -0
- package/tests/utils/createTestPreview.d.ts +2 -0
- package/tests/utils/createTestPreview.d.ts.map +1 -0
- package/tests/utils/createTestPreview.js +5 -0
- package/tests/utils/redditApiPluginsMock.d.ts +203 -0
- package/tests/utils/redditApiPluginsMock.d.ts.map +1 -0
- package/tests/utils/redditApiPluginsMock.js +202 -0
- package/tests/utils/runWithTestContext.d.ts +4 -0
- package/tests/utils/runWithTestContext.d.ts.map +1 -0
- package/tests/utils/runWithTestContext.js +12 -0
- package/tests/utils/userActionsPluginMock.d.ts +6 -0
- package/tests/utils/userActionsPluginMock.d.ts.map +1 -0
- package/tests/utils/userActionsPluginMock.js +5 -0
package/models/Post.js
ADDED
|
@@ -0,0 +1,1022 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _a, _Post_id, _Post_authorId, _Post_authorName, _Post_createdAt, _Post_subredditId, _Post_subredditName, _Post_permalink, _Post_title, _Post_body, _Post_bodyHtml, _Post_url, _Post_score, _Post_numberOfComments, _Post_numberOfReports, _Post_thumbnail, _Post_approved, _Post_approvedAtUtc, _Post_bannedAtUtc, _Post_spam, _Post_stickied, _Post_removed, _Post_removedBy, _Post_removedByCategory, _Post_archived, _Post_edited, _Post_locked, _Post_nsfw, _Post_quarantined, _Post_spoiler, _Post_hidden, _Post_ignoringReports, _Post_distinguishedBy, _Post_flair, _Post_secureMedia, _Post_modReportReasons, _Post_userReportReasons, _Post_gallery, _Post_metadata_get;
|
|
13
|
+
import { Block, UIResponse } from '@devvit/protos';
|
|
14
|
+
import { BlocksReconciler } from '@devvit/public-api/devvit/internals/blocks/BlocksReconciler.js';
|
|
15
|
+
import { BlocksHandler } from '@devvit/public-api/devvit/internals/blocks/handler/BlocksHandler.js';
|
|
16
|
+
import { getContext } from '@devvit/server';
|
|
17
|
+
import { assertNonNull } from '@devvit/shared-types/NonNull.js';
|
|
18
|
+
import { RichTextBuilder } from '@devvit/shared-types/richtext/RichTextBuilder.js';
|
|
19
|
+
import { asT2ID, asT3ID, asT5ID, isT3ID } from '@devvit/shared-types/tid.js';
|
|
20
|
+
import { RunAs } from '../common.js';
|
|
21
|
+
import { getRedditApiPlugins } from '../getRedditApiPlugins.js';
|
|
22
|
+
import { getUserActionsPlugin } from '../getUserActionsPlugin.js';
|
|
23
|
+
import { GraphQL } from '../graphql/GraphQL.js';
|
|
24
|
+
import { makeGettersEnumerable } from '../helpers/makeGettersEnumerable.js';
|
|
25
|
+
import { richtextToString } from '../helpers/richtextToString.js';
|
|
26
|
+
import { getCustomPostRichTextFallback } from '../helpers/textFallbackToRichtext.js';
|
|
27
|
+
import { Comment } from './Comment.js';
|
|
28
|
+
import { Listing } from './Listing.js';
|
|
29
|
+
import { ModNote } from './ModNote.js';
|
|
30
|
+
import { User } from './User.js';
|
|
31
|
+
const SetCustomPostPreviewRequestBodyType = {
|
|
32
|
+
NONE: 0,
|
|
33
|
+
BLOCKS: 1,
|
|
34
|
+
UNRECOGNIZED: -1,
|
|
35
|
+
};
|
|
36
|
+
export const GalleryMediaStatus = {
|
|
37
|
+
UNKNOWN: 0,
|
|
38
|
+
VALID: 1,
|
|
39
|
+
FAILED: 2,
|
|
40
|
+
};
|
|
41
|
+
export class Post {
|
|
42
|
+
/**
|
|
43
|
+
* @internal
|
|
44
|
+
*/
|
|
45
|
+
constructor(data) {
|
|
46
|
+
_Post_id.set(this, void 0);
|
|
47
|
+
_Post_authorId.set(this, void 0);
|
|
48
|
+
_Post_authorName.set(this, void 0);
|
|
49
|
+
_Post_createdAt.set(this, void 0);
|
|
50
|
+
_Post_subredditId.set(this, void 0);
|
|
51
|
+
_Post_subredditName.set(this, void 0);
|
|
52
|
+
_Post_permalink.set(this, void 0);
|
|
53
|
+
_Post_title.set(this, void 0);
|
|
54
|
+
_Post_body.set(this, void 0);
|
|
55
|
+
_Post_bodyHtml.set(this, void 0);
|
|
56
|
+
_Post_url.set(this, void 0);
|
|
57
|
+
_Post_score.set(this, void 0);
|
|
58
|
+
_Post_numberOfComments.set(this, void 0);
|
|
59
|
+
_Post_numberOfReports.set(this, void 0);
|
|
60
|
+
_Post_thumbnail.set(this, void 0);
|
|
61
|
+
_Post_approved.set(this, void 0);
|
|
62
|
+
_Post_approvedAtUtc.set(this, void 0);
|
|
63
|
+
_Post_bannedAtUtc.set(this, void 0);
|
|
64
|
+
_Post_spam.set(this, void 0);
|
|
65
|
+
_Post_stickied.set(this, void 0);
|
|
66
|
+
_Post_removed.set(this, void 0);
|
|
67
|
+
_Post_removedBy.set(this, void 0);
|
|
68
|
+
_Post_removedByCategory.set(this, void 0);
|
|
69
|
+
_Post_archived.set(this, void 0);
|
|
70
|
+
_Post_edited.set(this, void 0);
|
|
71
|
+
_Post_locked.set(this, void 0);
|
|
72
|
+
_Post_nsfw.set(this, void 0);
|
|
73
|
+
_Post_quarantined.set(this, void 0);
|
|
74
|
+
_Post_spoiler.set(this, void 0);
|
|
75
|
+
_Post_hidden.set(this, void 0);
|
|
76
|
+
_Post_ignoringReports.set(this, void 0);
|
|
77
|
+
_Post_distinguishedBy.set(this, void 0);
|
|
78
|
+
_Post_flair.set(this, void 0);
|
|
79
|
+
_Post_secureMedia.set(this, void 0);
|
|
80
|
+
_Post_modReportReasons.set(this, void 0);
|
|
81
|
+
_Post_userReportReasons.set(this, void 0);
|
|
82
|
+
_Post_gallery.set(this, void 0);
|
|
83
|
+
makeGettersEnumerable(this);
|
|
84
|
+
assertNonNull(data.id, 'Post is missing id');
|
|
85
|
+
assertNonNull(data.title, 'Post is missing title');
|
|
86
|
+
assertNonNull(data.createdUtc, 'Post is missing created date');
|
|
87
|
+
assertNonNull(data.author, 'Post is missing author name');
|
|
88
|
+
assertNonNull(data.subreddit, 'Post is missing subreddit name');
|
|
89
|
+
assertNonNull(data.subredditId, 'Post is missing subreddit id');
|
|
90
|
+
assertNonNull(data.url, 'Post is missing url');
|
|
91
|
+
assertNonNull(data.permalink, 'Post is missing permalink');
|
|
92
|
+
__classPrivateFieldSet(this, _Post_id, asT3ID(`t3_${data.id}`), "f");
|
|
93
|
+
__classPrivateFieldSet(this, _Post_authorName, data.author, "f");
|
|
94
|
+
__classPrivateFieldSet(this, _Post_authorId, data.authorFullname ? asT2ID(data.authorFullname) : undefined, "f");
|
|
95
|
+
__classPrivateFieldSet(this, _Post_subredditId, asT5ID(data.subredditId), "f");
|
|
96
|
+
__classPrivateFieldSet(this, _Post_subredditName, data.subreddit, "f");
|
|
97
|
+
__classPrivateFieldSet(this, _Post_score, data.score ?? 0, "f");
|
|
98
|
+
__classPrivateFieldSet(this, _Post_numberOfComments, data.numComments ?? 0, "f");
|
|
99
|
+
__classPrivateFieldSet(this, _Post_numberOfReports, data.numReports ?? 0, "f");
|
|
100
|
+
const createdAt = new Date(0);
|
|
101
|
+
createdAt.setUTCSeconds(data.createdUtc);
|
|
102
|
+
__classPrivateFieldSet(this, _Post_createdAt, createdAt, "f");
|
|
103
|
+
__classPrivateFieldSet(this, _Post_title, data.title, "f");
|
|
104
|
+
__classPrivateFieldSet(this, _Post_body, data.selftext, "f");
|
|
105
|
+
__classPrivateFieldSet(this, _Post_bodyHtml, data.selftextHtml, "f");
|
|
106
|
+
__classPrivateFieldSet(this, _Post_url, data.url, "f");
|
|
107
|
+
__classPrivateFieldSet(this, _Post_permalink, data.permalink, "f");
|
|
108
|
+
if (data.thumbnail &&
|
|
109
|
+
data.thumbnail !== 'self' &&
|
|
110
|
+
data.thumbnail !== 'nsfw' &&
|
|
111
|
+
data.thumbnailHeight != null &&
|
|
112
|
+
data.thumbnailWidth != null) {
|
|
113
|
+
__classPrivateFieldSet(this, _Post_thumbnail, {
|
|
114
|
+
url: data.thumbnail,
|
|
115
|
+
height: data.thumbnailHeight,
|
|
116
|
+
width: data.thumbnailWidth,
|
|
117
|
+
}, "f");
|
|
118
|
+
}
|
|
119
|
+
__classPrivateFieldSet(this, _Post_approved, data.approved ?? false, "f");
|
|
120
|
+
__classPrivateFieldSet(this, _Post_approvedAtUtc, data.approvedAtUtc ?? 0, "f");
|
|
121
|
+
__classPrivateFieldSet(this, _Post_bannedAtUtc, data.bannedAtUtc ?? 0, "f");
|
|
122
|
+
__classPrivateFieldSet(this, _Post_removed, data.removed ?? false, "f");
|
|
123
|
+
__classPrivateFieldSet(this, _Post_removedBy, data.removedBy, "f");
|
|
124
|
+
__classPrivateFieldSet(this, _Post_removedByCategory, data.removedByCategory, "f");
|
|
125
|
+
__classPrivateFieldSet(this, _Post_spam, data.spam ?? false, "f");
|
|
126
|
+
__classPrivateFieldSet(this, _Post_stickied, data.stickied ?? false, "f");
|
|
127
|
+
__classPrivateFieldSet(this, _Post_archived, data.archived ?? false, "f");
|
|
128
|
+
__classPrivateFieldSet(this, _Post_edited, data.edited ?? false, "f");
|
|
129
|
+
__classPrivateFieldSet(this, _Post_locked, data.locked ?? false, "f");
|
|
130
|
+
__classPrivateFieldSet(this, _Post_nsfw, data.over18 ?? false, "f");
|
|
131
|
+
__classPrivateFieldSet(this, _Post_quarantined, data.quarantine ?? false, "f");
|
|
132
|
+
__classPrivateFieldSet(this, _Post_spoiler, data.spoiler, "f");
|
|
133
|
+
__classPrivateFieldSet(this, _Post_hidden, data.hidden ?? false, "f");
|
|
134
|
+
__classPrivateFieldSet(this, _Post_ignoringReports, data.ignoreReports ?? false, "f");
|
|
135
|
+
__classPrivateFieldSet(this, _Post_distinguishedBy, data.distinguished, "f");
|
|
136
|
+
__classPrivateFieldSet(this, _Post_secureMedia, data.secureMedia, "f");
|
|
137
|
+
__classPrivateFieldSet(this, _Post_modReportReasons, (data.modReports ?? []).map(([reason]) => reason), "f");
|
|
138
|
+
__classPrivateFieldSet(this, _Post_userReportReasons, (data.userReports ?? []).map(([reason]) => reason), "f");
|
|
139
|
+
if (data.linkFlairBackgroundColor ||
|
|
140
|
+
data.linkFlairCssClass ||
|
|
141
|
+
data.linkFlairText ||
|
|
142
|
+
data.linkFlairType ||
|
|
143
|
+
data.linkFlairTemplateId ||
|
|
144
|
+
data.linkFlairRichtext ||
|
|
145
|
+
data.linkFlairTextColor) {
|
|
146
|
+
__classPrivateFieldSet(this, _Post_flair, {
|
|
147
|
+
backgroundColor: data.linkFlairBackgroundColor,
|
|
148
|
+
cssClass: data.linkFlairCssClass,
|
|
149
|
+
text: data.linkFlairText,
|
|
150
|
+
type: data.linkFlairType,
|
|
151
|
+
templateId: data.linkFlairTemplateId,
|
|
152
|
+
// Map linkFlairRichtext[] into the objects with more user-friendly property names
|
|
153
|
+
richtext: (data.linkFlairRichtext ?? []).map(({ e, t, a, u }) => ({
|
|
154
|
+
elementType: e,
|
|
155
|
+
text: t,
|
|
156
|
+
emojiRef: a,
|
|
157
|
+
url: u,
|
|
158
|
+
})),
|
|
159
|
+
textColor: data.linkFlairTextColor,
|
|
160
|
+
}, "f");
|
|
161
|
+
}
|
|
162
|
+
if (data.gallery) {
|
|
163
|
+
__classPrivateFieldSet(this, _Post_gallery, data.gallery.map((item) => ({
|
|
164
|
+
status: item.status,
|
|
165
|
+
url: item.url,
|
|
166
|
+
height: item.height,
|
|
167
|
+
width: item.width,
|
|
168
|
+
})), "f");
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
__classPrivateFieldSet(this, _Post_gallery, [], "f");
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
get id() {
|
|
175
|
+
return __classPrivateFieldGet(this, _Post_id, "f");
|
|
176
|
+
}
|
|
177
|
+
get authorId() {
|
|
178
|
+
return __classPrivateFieldGet(this, _Post_authorId, "f");
|
|
179
|
+
}
|
|
180
|
+
get authorName() {
|
|
181
|
+
return __classPrivateFieldGet(this, _Post_authorName, "f");
|
|
182
|
+
}
|
|
183
|
+
get subredditId() {
|
|
184
|
+
return __classPrivateFieldGet(this, _Post_subredditId, "f");
|
|
185
|
+
}
|
|
186
|
+
get subredditName() {
|
|
187
|
+
return __classPrivateFieldGet(this, _Post_subredditName, "f");
|
|
188
|
+
}
|
|
189
|
+
get permalink() {
|
|
190
|
+
return __classPrivateFieldGet(this, _Post_permalink, "f");
|
|
191
|
+
}
|
|
192
|
+
get title() {
|
|
193
|
+
return __classPrivateFieldGet(this, _Post_title, "f");
|
|
194
|
+
}
|
|
195
|
+
get body() {
|
|
196
|
+
return __classPrivateFieldGet(this, _Post_body, "f");
|
|
197
|
+
}
|
|
198
|
+
get bodyHtml() {
|
|
199
|
+
return __classPrivateFieldGet(this, _Post_bodyHtml, "f");
|
|
200
|
+
}
|
|
201
|
+
get url() {
|
|
202
|
+
return __classPrivateFieldGet(this, _Post_url, "f");
|
|
203
|
+
}
|
|
204
|
+
get thumbnail() {
|
|
205
|
+
return __classPrivateFieldGet(this, _Post_thumbnail, "f");
|
|
206
|
+
}
|
|
207
|
+
get createdAt() {
|
|
208
|
+
return __classPrivateFieldGet(this, _Post_createdAt, "f");
|
|
209
|
+
}
|
|
210
|
+
get score() {
|
|
211
|
+
return __classPrivateFieldGet(this, _Post_score, "f");
|
|
212
|
+
}
|
|
213
|
+
get numberOfComments() {
|
|
214
|
+
return __classPrivateFieldGet(this, _Post_numberOfComments, "f");
|
|
215
|
+
}
|
|
216
|
+
get numberOfReports() {
|
|
217
|
+
return __classPrivateFieldGet(this, _Post_numberOfReports, "f");
|
|
218
|
+
}
|
|
219
|
+
get approved() {
|
|
220
|
+
return __classPrivateFieldGet(this, _Post_approved, "f");
|
|
221
|
+
}
|
|
222
|
+
get approvedAtUtc() {
|
|
223
|
+
return __classPrivateFieldGet(this, _Post_approvedAtUtc, "f");
|
|
224
|
+
}
|
|
225
|
+
get bannedAtUtc() {
|
|
226
|
+
return __classPrivateFieldGet(this, _Post_bannedAtUtc, "f");
|
|
227
|
+
}
|
|
228
|
+
get spam() {
|
|
229
|
+
return __classPrivateFieldGet(this, _Post_spam, "f");
|
|
230
|
+
}
|
|
231
|
+
get stickied() {
|
|
232
|
+
return __classPrivateFieldGet(this, _Post_stickied, "f");
|
|
233
|
+
}
|
|
234
|
+
get removed() {
|
|
235
|
+
return __classPrivateFieldGet(this, _Post_removed, "f");
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Who removed this object (username)
|
|
239
|
+
*/
|
|
240
|
+
get removedBy() {
|
|
241
|
+
return __classPrivateFieldGet(this, _Post_removedBy, "f");
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* who/what removed this object. It will return one of the following:
|
|
245
|
+
* - "anti_evil_ops": object is removed by a aeops member
|
|
246
|
+
* - "author": object is removed by author of the post
|
|
247
|
+
* - "automod_filtered": object is filtered by automod
|
|
248
|
+
* - "community_ops": object is removed by a community team member
|
|
249
|
+
* - "content_takedown": object is removed due to content violation
|
|
250
|
+
* - "copyright_takedown": object is removed due to copyright violation
|
|
251
|
+
* - "deleted": object is deleted
|
|
252
|
+
* - "moderator": object is removed by a mod of the sub
|
|
253
|
+
* - "reddit": object is removed by anyone else
|
|
254
|
+
* - undefined: object is not removed
|
|
255
|
+
*/
|
|
256
|
+
get removedByCategory() {
|
|
257
|
+
return __classPrivateFieldGet(this, _Post_removedByCategory, "f");
|
|
258
|
+
}
|
|
259
|
+
get archived() {
|
|
260
|
+
return __classPrivateFieldGet(this, _Post_archived, "f");
|
|
261
|
+
}
|
|
262
|
+
get edited() {
|
|
263
|
+
return __classPrivateFieldGet(this, _Post_edited, "f");
|
|
264
|
+
}
|
|
265
|
+
get locked() {
|
|
266
|
+
return __classPrivateFieldGet(this, _Post_locked, "f");
|
|
267
|
+
}
|
|
268
|
+
get nsfw() {
|
|
269
|
+
return __classPrivateFieldGet(this, _Post_nsfw, "f");
|
|
270
|
+
}
|
|
271
|
+
get quarantined() {
|
|
272
|
+
return __classPrivateFieldGet(this, _Post_quarantined, "f");
|
|
273
|
+
}
|
|
274
|
+
get spoiler() {
|
|
275
|
+
return __classPrivateFieldGet(this, _Post_spoiler, "f");
|
|
276
|
+
}
|
|
277
|
+
get hidden() {
|
|
278
|
+
return __classPrivateFieldGet(this, _Post_hidden, "f");
|
|
279
|
+
}
|
|
280
|
+
get ignoringReports() {
|
|
281
|
+
return __classPrivateFieldGet(this, _Post_ignoringReports, "f");
|
|
282
|
+
}
|
|
283
|
+
get distinguishedBy() {
|
|
284
|
+
return __classPrivateFieldGet(this, _Post_distinguishedBy, "f");
|
|
285
|
+
}
|
|
286
|
+
get comments() {
|
|
287
|
+
return Comment.getComments({
|
|
288
|
+
postId: this.id,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
get flair() {
|
|
292
|
+
return __classPrivateFieldGet(this, _Post_flair, "f");
|
|
293
|
+
}
|
|
294
|
+
get secureMedia() {
|
|
295
|
+
return __classPrivateFieldGet(this, _Post_secureMedia, "f");
|
|
296
|
+
}
|
|
297
|
+
get userReportReasons() {
|
|
298
|
+
return __classPrivateFieldGet(this, _Post_userReportReasons, "f");
|
|
299
|
+
}
|
|
300
|
+
get modReportReasons() {
|
|
301
|
+
return __classPrivateFieldGet(this, _Post_modReportReasons, "f");
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Get the media in the post. Empty if the post doesn't have any media.
|
|
305
|
+
*/
|
|
306
|
+
get gallery() {
|
|
307
|
+
return __classPrivateFieldGet(this, _Post_gallery, "f");
|
|
308
|
+
}
|
|
309
|
+
toJSON() {
|
|
310
|
+
return {
|
|
311
|
+
id: this.id,
|
|
312
|
+
authorId: this.authorId,
|
|
313
|
+
authorName: this.authorName,
|
|
314
|
+
subredditId: this.subredditId,
|
|
315
|
+
subredditName: this.subredditName,
|
|
316
|
+
permalink: this.permalink,
|
|
317
|
+
title: this.title,
|
|
318
|
+
body: this.body,
|
|
319
|
+
bodyHtml: this.bodyHtml,
|
|
320
|
+
url: this.url,
|
|
321
|
+
thumbnail: this.thumbnail,
|
|
322
|
+
score: this.score,
|
|
323
|
+
numberOfComments: this.numberOfComments,
|
|
324
|
+
numberOfReports: this.numberOfReports,
|
|
325
|
+
createdAt: this.createdAt,
|
|
326
|
+
approved: this.approved,
|
|
327
|
+
spam: this.spam,
|
|
328
|
+
stickied: this.stickied,
|
|
329
|
+
removed: this.removed,
|
|
330
|
+
removedBy: __classPrivateFieldGet(this, _Post_removedBy, "f"),
|
|
331
|
+
removedByCategory: __classPrivateFieldGet(this, _Post_removedByCategory, "f"),
|
|
332
|
+
archived: this.archived,
|
|
333
|
+
edited: this.edited,
|
|
334
|
+
locked: this.locked,
|
|
335
|
+
nsfw: this.nsfw,
|
|
336
|
+
quarantined: this.quarantined,
|
|
337
|
+
spoiler: this.spoiler,
|
|
338
|
+
hidden: this.hidden,
|
|
339
|
+
ignoringReports: this.ignoringReports,
|
|
340
|
+
distinguishedBy: this.distinguishedBy,
|
|
341
|
+
flair: this.flair,
|
|
342
|
+
secureMedia: this.secureMedia,
|
|
343
|
+
modReportReasons: __classPrivateFieldGet(this, _Post_modReportReasons, "f"),
|
|
344
|
+
userReportReasons: __classPrivateFieldGet(this, _Post_userReportReasons, "f"),
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
isApproved() {
|
|
348
|
+
return __classPrivateFieldGet(this, _Post_approved, "f");
|
|
349
|
+
}
|
|
350
|
+
isSpam() {
|
|
351
|
+
return __classPrivateFieldGet(this, _Post_spam, "f");
|
|
352
|
+
}
|
|
353
|
+
isStickied() {
|
|
354
|
+
return __classPrivateFieldGet(this, _Post_stickied, "f");
|
|
355
|
+
}
|
|
356
|
+
isRemoved() {
|
|
357
|
+
return __classPrivateFieldGet(this, _Post_removed, "f");
|
|
358
|
+
}
|
|
359
|
+
isArchived() {
|
|
360
|
+
return __classPrivateFieldGet(this, _Post_archived, "f");
|
|
361
|
+
}
|
|
362
|
+
isEdited() {
|
|
363
|
+
return __classPrivateFieldGet(this, _Post_edited, "f");
|
|
364
|
+
}
|
|
365
|
+
isLocked() {
|
|
366
|
+
return __classPrivateFieldGet(this, _Post_locked, "f");
|
|
367
|
+
}
|
|
368
|
+
isNsfw() {
|
|
369
|
+
return __classPrivateFieldGet(this, _Post_nsfw, "f");
|
|
370
|
+
}
|
|
371
|
+
isQuarantined() {
|
|
372
|
+
return __classPrivateFieldGet(this, _Post_quarantined, "f");
|
|
373
|
+
}
|
|
374
|
+
isSpoiler() {
|
|
375
|
+
return __classPrivateFieldGet(this, _Post_spoiler, "f");
|
|
376
|
+
}
|
|
377
|
+
isHidden() {
|
|
378
|
+
return __classPrivateFieldGet(this, _Post_hidden, "f");
|
|
379
|
+
}
|
|
380
|
+
isIgnoringReports() {
|
|
381
|
+
return __classPrivateFieldGet(this, _Post_ignoringReports, "f");
|
|
382
|
+
}
|
|
383
|
+
isDistinguishedBy() {
|
|
384
|
+
return __classPrivateFieldGet(this, _Post_distinguishedBy, "f");
|
|
385
|
+
}
|
|
386
|
+
async edit(options) {
|
|
387
|
+
const newPost = await _a.edit({
|
|
388
|
+
id: this.id,
|
|
389
|
+
...options,
|
|
390
|
+
});
|
|
391
|
+
__classPrivateFieldSet(this, _Post_body, newPost.body, "f");
|
|
392
|
+
__classPrivateFieldSet(this, _Post_edited, newPost.edited, "f");
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Set the suggested sort for comments on a Post.
|
|
396
|
+
*
|
|
397
|
+
* @throws {Error} Throws an error if the suggested sort could not be set.
|
|
398
|
+
* @example
|
|
399
|
+
* ```ts
|
|
400
|
+
* const post = await reddit.getPostById(context.postId);
|
|
401
|
+
* await post.setSuggestedCommentSort("NEW");
|
|
402
|
+
* ```
|
|
403
|
+
*/
|
|
404
|
+
async setSuggestedCommentSort(suggestedSort) {
|
|
405
|
+
await _a.setSuggestedCommentSort({
|
|
406
|
+
id: this.id,
|
|
407
|
+
subredditId: __classPrivateFieldGet(this, _Post_subredditId, "f"),
|
|
408
|
+
suggestedSort,
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Set a lightweight UI that shows while the custom post renders
|
|
413
|
+
*
|
|
414
|
+
* @param {JSX.ComponentFunction} ui - A JSX component function that returns a simple ui to be rendered.
|
|
415
|
+
* @throws {Error} Throws an error if the preview could not be set.
|
|
416
|
+
* @example
|
|
417
|
+
* ```ts
|
|
418
|
+
* const preview = (
|
|
419
|
+
* <vstack height="100%" width="100%" alignment="middle center">
|
|
420
|
+
* <text size="large">An updated preview!</text>
|
|
421
|
+
* </vstack>
|
|
422
|
+
* );
|
|
423
|
+
* const post = await reddit.getPostById(context.postId);
|
|
424
|
+
* await post.setCustomPostPreview(() => preview);
|
|
425
|
+
* ```
|
|
426
|
+
*/
|
|
427
|
+
async setCustomPostPreview(ui) {
|
|
428
|
+
await _a.setCustomPostPreview({
|
|
429
|
+
id: this.id,
|
|
430
|
+
ui,
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Set a text fallback for the custom post
|
|
435
|
+
*
|
|
436
|
+
* @param {CustomPostTextFallbackOptions} options - A text or a richtext to render in a fallback
|
|
437
|
+
* @throws {Error} Throws an error if the fallback could not be set.
|
|
438
|
+
* @example
|
|
439
|
+
* ```ts
|
|
440
|
+
* // from a menu action, form, scheduler, trigger, custom post click event, etc
|
|
441
|
+
* const newTextFallback = { text: 'This is an updated text fallback' };
|
|
442
|
+
* const post = await context.reddit.getPostById(context.postId);
|
|
443
|
+
* await post.setTextFallback(newTextFallback);
|
|
444
|
+
* ```
|
|
445
|
+
*/
|
|
446
|
+
async setTextFallback(options) {
|
|
447
|
+
const newPost = await _a.setTextFallback(options, this.id);
|
|
448
|
+
__classPrivateFieldSet(this, _Post_body, newPost.body, "f");
|
|
449
|
+
__classPrivateFieldSet(this, _Post_edited, newPost.edited, "f");
|
|
450
|
+
}
|
|
451
|
+
async addComment(options) {
|
|
452
|
+
return Comment.submit({
|
|
453
|
+
id: this.id,
|
|
454
|
+
...options,
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
async delete() {
|
|
458
|
+
const appUsername = getContext().appName;
|
|
459
|
+
if (appUsername !== __classPrivateFieldGet(this, _Post_authorName, "f")) {
|
|
460
|
+
throw new Error(`App '${appUsername}' is not the author of Post ${this.id}, delete not allowed.`);
|
|
461
|
+
}
|
|
462
|
+
return _a.delete(this.id);
|
|
463
|
+
}
|
|
464
|
+
async approve() {
|
|
465
|
+
await _a.approve(this.id);
|
|
466
|
+
__classPrivateFieldSet(this, _Post_approved, true, "f");
|
|
467
|
+
__classPrivateFieldSet(this, _Post_removed, false, "f");
|
|
468
|
+
}
|
|
469
|
+
async remove(isSpam = false) {
|
|
470
|
+
await _a.remove(this.id, isSpam);
|
|
471
|
+
__classPrivateFieldSet(this, _Post_removed, true, "f");
|
|
472
|
+
__classPrivateFieldSet(this, _Post_spam, isSpam, "f");
|
|
473
|
+
__classPrivateFieldSet(this, _Post_approved, false, "f");
|
|
474
|
+
}
|
|
475
|
+
async lock() {
|
|
476
|
+
await _a.lock(this.id);
|
|
477
|
+
__classPrivateFieldSet(this, _Post_locked, true, "f");
|
|
478
|
+
}
|
|
479
|
+
async unlock() {
|
|
480
|
+
await _a.unlock(this.id);
|
|
481
|
+
__classPrivateFieldSet(this, _Post_locked, false, "f");
|
|
482
|
+
}
|
|
483
|
+
async hide() {
|
|
484
|
+
await _a.hide(this.id);
|
|
485
|
+
__classPrivateFieldSet(this, _Post_hidden, true, "f");
|
|
486
|
+
}
|
|
487
|
+
async unhide() {
|
|
488
|
+
await _a.unhide(this.id);
|
|
489
|
+
__classPrivateFieldSet(this, _Post_hidden, false, "f");
|
|
490
|
+
}
|
|
491
|
+
async markAsNsfw() {
|
|
492
|
+
await _a.markAsNsfw(this.id);
|
|
493
|
+
__classPrivateFieldSet(this, _Post_nsfw, true, "f");
|
|
494
|
+
}
|
|
495
|
+
async unmarkAsNsfw() {
|
|
496
|
+
await _a.unmarkAsNsfw(this.id);
|
|
497
|
+
__classPrivateFieldSet(this, _Post_nsfw, false, "f");
|
|
498
|
+
}
|
|
499
|
+
async markAsSpoiler() {
|
|
500
|
+
await _a.markAsSpoiler(this.id);
|
|
501
|
+
__classPrivateFieldSet(this, _Post_spoiler, true, "f");
|
|
502
|
+
}
|
|
503
|
+
async unmarkAsSpoiler() {
|
|
504
|
+
await _a.unmarkAsSpoiler(this.id);
|
|
505
|
+
__classPrivateFieldSet(this, _Post_spoiler, false, "f");
|
|
506
|
+
}
|
|
507
|
+
async sticky(position) {
|
|
508
|
+
await _a.sticky(this.id, position);
|
|
509
|
+
}
|
|
510
|
+
async unsticky() {
|
|
511
|
+
await _a.unsticky(this.id);
|
|
512
|
+
}
|
|
513
|
+
async distinguish() {
|
|
514
|
+
const { distinguishedBy } = await _a.distinguish(this.id, false);
|
|
515
|
+
__classPrivateFieldSet(this, _Post_distinguishedBy, distinguishedBy, "f");
|
|
516
|
+
}
|
|
517
|
+
async distinguishAsAdmin() {
|
|
518
|
+
const { distinguishedBy } = await _a.distinguish(this.id, true);
|
|
519
|
+
__classPrivateFieldSet(this, _Post_distinguishedBy, distinguishedBy, "f");
|
|
520
|
+
}
|
|
521
|
+
async undistinguish() {
|
|
522
|
+
const { distinguishedBy } = await _a.undistinguish(this.id);
|
|
523
|
+
__classPrivateFieldSet(this, _Post_distinguishedBy, distinguishedBy, "f");
|
|
524
|
+
}
|
|
525
|
+
async ignoreReports() {
|
|
526
|
+
await _a.ignoreReports(this.id);
|
|
527
|
+
__classPrivateFieldSet(this, _Post_ignoringReports, true, "f");
|
|
528
|
+
}
|
|
529
|
+
async unignoreReports() {
|
|
530
|
+
await _a.unignoreReports(this.id);
|
|
531
|
+
__classPrivateFieldSet(this, _Post_ignoringReports, false, "f");
|
|
532
|
+
}
|
|
533
|
+
async getAuthor() {
|
|
534
|
+
return User.getByUsername(__classPrivateFieldGet(this, _Post_authorName, "f"));
|
|
535
|
+
}
|
|
536
|
+
async crosspost(options) {
|
|
537
|
+
return _a.crosspost({
|
|
538
|
+
...options,
|
|
539
|
+
postId: this.id,
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/**
|
|
543
|
+
* Add a mod note for why the post was removed
|
|
544
|
+
*
|
|
545
|
+
* @param options.reasonId id of a Removal Reason - you can leave this as an empty string if you don't have one
|
|
546
|
+
* @param options.modNote the reason for removal (maximum 100 characters) (optional)
|
|
547
|
+
* @returns
|
|
548
|
+
*/
|
|
549
|
+
addRemovalNote(options) {
|
|
550
|
+
return ModNote.addRemovalNote({ itemIds: [__classPrivateFieldGet(this, _Post_id, "f")], ...options });
|
|
551
|
+
}
|
|
552
|
+
/**
|
|
553
|
+
* Get a thumbnail that contains a preview image and also contains a blurred preview for
|
|
554
|
+
* NSFW images. The thumbnail returned has higher resolution than Post.thumbnail.
|
|
555
|
+
* Returns undefined if the post doesn't have a thumbnail
|
|
556
|
+
*
|
|
557
|
+
* @returns {EnrichedThumbnail | undefined}
|
|
558
|
+
* @throws {Error} Throws an error if the thumbnail could not be fetched
|
|
559
|
+
* @example
|
|
560
|
+
* ```ts
|
|
561
|
+
* // from a menu action, form, scheduler, trigger, custom post click event, etc
|
|
562
|
+
* const post = await context.reddit.getPostById(context.postId);
|
|
563
|
+
* const enrichedThumbnail = await post.getEnrichedThumbnail();
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
async getEnrichedThumbnail() {
|
|
567
|
+
return getThumbnailV2({ id: this.id });
|
|
568
|
+
}
|
|
569
|
+
// TODO: flair methods
|
|
570
|
+
/** @internal */
|
|
571
|
+
static async getById(id) {
|
|
572
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
573
|
+
const postId = isT3ID(id) ? id : `t3_${id}`;
|
|
574
|
+
const response = await client.Info({
|
|
575
|
+
subreddits: [],
|
|
576
|
+
thingIds: [postId],
|
|
577
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
578
|
+
if (!response.data?.children?.length) {
|
|
579
|
+
throw new Error('could not find post');
|
|
580
|
+
}
|
|
581
|
+
const postData = response.data.children[0];
|
|
582
|
+
if (!postData?.data) {
|
|
583
|
+
throw new Error('could not find post');
|
|
584
|
+
}
|
|
585
|
+
return new _a(postData.data);
|
|
586
|
+
}
|
|
587
|
+
/** @internal */
|
|
588
|
+
static async submit(options) {
|
|
589
|
+
const { runAs = 'APP' } = options;
|
|
590
|
+
const runAsType = RunAs[runAs];
|
|
591
|
+
const client = runAsType === RunAs.USER ? getUserActionsPlugin() : getRedditApiPlugins().LinksAndComments;
|
|
592
|
+
let response;
|
|
593
|
+
if ('preview' in options) {
|
|
594
|
+
if (runAsType === RunAs.USER) {
|
|
595
|
+
assertNonNull(options.userGeneratedContent, 'userGeneratedContent must be set in `SubmitPostOptions` when RunAs=USER for experience posts');
|
|
596
|
+
}
|
|
597
|
+
const reconciler = new BlocksReconciler(() => options.preview, undefined, {}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get), undefined);
|
|
598
|
+
const previewBlock = await reconciler.buildBlocksUI();
|
|
599
|
+
const encodedCached = Block.encode(previewBlock).finish();
|
|
600
|
+
const { textFallback, ...sanitizedOptions } = options;
|
|
601
|
+
const richtextFallback = textFallback ? getCustomPostRichTextFallback(textFallback) : '';
|
|
602
|
+
const userGeneratedContent = options.userGeneratedContent
|
|
603
|
+
? {
|
|
604
|
+
text: options.userGeneratedContent.text ?? '',
|
|
605
|
+
imageUrls: options.userGeneratedContent.imageUrls ?? [],
|
|
606
|
+
}
|
|
607
|
+
: undefined;
|
|
608
|
+
const submitRequest = {
|
|
609
|
+
kind: 'custom',
|
|
610
|
+
sr: options.subredditName,
|
|
611
|
+
richtextJson: Buffer.from(encodedCached).toString('base64'),
|
|
612
|
+
richtextFallback,
|
|
613
|
+
...sanitizedOptions,
|
|
614
|
+
userGeneratedContent,
|
|
615
|
+
runAs: runAsType,
|
|
616
|
+
};
|
|
617
|
+
response = await client.SubmitCustomPost(submitRequest, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
618
|
+
}
|
|
619
|
+
else {
|
|
620
|
+
response = await client.Submit({
|
|
621
|
+
kind: 'kind' in options ? options.kind : 'url' in options ? 'link' : 'self',
|
|
622
|
+
sr: options.subredditName,
|
|
623
|
+
richtextJson: 'richtext' in options ? richtextToString(options.richtext) : undefined,
|
|
624
|
+
...options,
|
|
625
|
+
runAs: runAsType,
|
|
626
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
627
|
+
}
|
|
628
|
+
// Post Id might not be present as image/video post creation can happen asynchronously
|
|
629
|
+
const isAllowedMediaType = 'kind' in options && ['image', 'video', 'videogif'].includes(options.kind);
|
|
630
|
+
if (isAllowedMediaType && !response.json?.data?.id) {
|
|
631
|
+
if (options.kind === 'image' && 'imageUrls' in options) {
|
|
632
|
+
throw new Error(`Image post type with ${options.imageUrls} is being created asynchronously and should be updated in the subreddit soon.`);
|
|
633
|
+
}
|
|
634
|
+
else if ('videoPosterUrl' in options) {
|
|
635
|
+
throw new Error(`Post of ${options.kind} type with ${options.videoPosterUrl} is being created asynchronously and should be updated in the subreddit soon.`);
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
if (!response.json?.data?.id || response.json?.errors?.length) {
|
|
639
|
+
throw new Error(`failed to submit post - either post ID is empty or request failed with errors: ${response.json?.errors}`);
|
|
640
|
+
}
|
|
641
|
+
return _a.getById(`t3_${response.json.data.id}`);
|
|
642
|
+
}
|
|
643
|
+
/** @internal */
|
|
644
|
+
static async crosspost(options) {
|
|
645
|
+
const { runAs = 'APP' } = options;
|
|
646
|
+
const runAsType = RunAs[runAs];
|
|
647
|
+
const client = runAsType === RunAs.USER ? getUserActionsPlugin() : getRedditApiPlugins().LinksAndComments;
|
|
648
|
+
const { postId, subredditName, ...rest } = options;
|
|
649
|
+
const response = await client.Submit({
|
|
650
|
+
kind: 'crosspost',
|
|
651
|
+
sr: subredditName,
|
|
652
|
+
crosspostFullname: asT3ID(postId),
|
|
653
|
+
...rest,
|
|
654
|
+
runAs: runAsType,
|
|
655
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
656
|
+
if (!response.json?.data?.id || response.json?.errors?.length) {
|
|
657
|
+
throw new Error('failed to crosspost post');
|
|
658
|
+
}
|
|
659
|
+
return _a.getById(`t3_${response.json.data.id}`);
|
|
660
|
+
}
|
|
661
|
+
/** @internal */
|
|
662
|
+
static async edit(options) {
|
|
663
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
664
|
+
const { id } = options;
|
|
665
|
+
let richtextString;
|
|
666
|
+
if ('richtext' in options) {
|
|
667
|
+
richtextString = richtextToString(options.richtext);
|
|
668
|
+
}
|
|
669
|
+
const response = await client.EditUserText({
|
|
670
|
+
thingId: id,
|
|
671
|
+
text: 'text' in options ? options.text : '',
|
|
672
|
+
richtextJson: richtextString,
|
|
673
|
+
runAs: RunAs.APP,
|
|
674
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
675
|
+
if (response.json?.errors?.length) {
|
|
676
|
+
throw new Error('Failed to edit post');
|
|
677
|
+
}
|
|
678
|
+
// The LinksAndComments.EditUserText response is wrong and assumes that
|
|
679
|
+
// the API is only used to for comments so we fetch the new post here.
|
|
680
|
+
return _a.getById(id);
|
|
681
|
+
}
|
|
682
|
+
/** @internal */
|
|
683
|
+
static async setSuggestedCommentSort(options) {
|
|
684
|
+
const operationName = 'SetSuggestedSort';
|
|
685
|
+
const persistedQueryHash = 'cf6052acc7fefaa65b710625b81dba8041f258313aafe9730e2a3dc855e5d10d';
|
|
686
|
+
const response = await GraphQL.query(operationName, persistedQueryHash, {
|
|
687
|
+
input: {
|
|
688
|
+
subredditId: options.subredditId,
|
|
689
|
+
postId: options.id,
|
|
690
|
+
sort: options.suggestedSort,
|
|
691
|
+
},
|
|
692
|
+
});
|
|
693
|
+
if (!response.data?.setSuggestedSort?.ok) {
|
|
694
|
+
throw new Error('Failed to set suggested sort');
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
/** @internal */
|
|
698
|
+
static async setCustomPostPreview(options) {
|
|
699
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
700
|
+
const handler = new BlocksHandler(options.ui);
|
|
701
|
+
const handlerResponse = UIResponse.fromJSON(await handler.handle({ events: [] }, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get)));
|
|
702
|
+
const block = handlerResponse.blocks;
|
|
703
|
+
const blocksRenderContent = Buffer.from(Block.encode(block).finish()).toString('base64');
|
|
704
|
+
await client.SetCustomPostPreview({
|
|
705
|
+
thingId: options.id,
|
|
706
|
+
bodyType: SetCustomPostPreviewRequestBodyType.BLOCKS,
|
|
707
|
+
blocksRenderContent,
|
|
708
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
709
|
+
}
|
|
710
|
+
/** @internal */
|
|
711
|
+
static async setTextFallback(options, postId) {
|
|
712
|
+
if (!('text' in options) && !('richtext' in options)) {
|
|
713
|
+
throw new Error(`No text fallback provided for post ${postId}.`);
|
|
714
|
+
}
|
|
715
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
716
|
+
const richtextFallback = getCustomPostRichTextFallback(options);
|
|
717
|
+
const response = await client.EditCustomPost({
|
|
718
|
+
thingId: postId,
|
|
719
|
+
richtextFallback,
|
|
720
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
721
|
+
if (response.json?.errors?.length) {
|
|
722
|
+
throw new Error('Failed to set post text fallback');
|
|
723
|
+
}
|
|
724
|
+
return _a.getById(postId);
|
|
725
|
+
}
|
|
726
|
+
/** @internal */
|
|
727
|
+
static async delete(id) {
|
|
728
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
729
|
+
await client.Del({
|
|
730
|
+
id,
|
|
731
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
732
|
+
}
|
|
733
|
+
/** @internal */
|
|
734
|
+
static async approve(id) {
|
|
735
|
+
const client = getRedditApiPlugins().Moderation;
|
|
736
|
+
await client.Approve({
|
|
737
|
+
id,
|
|
738
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
739
|
+
}
|
|
740
|
+
/** @internal */
|
|
741
|
+
static async remove(id, isSpam = false) {
|
|
742
|
+
const client = getRedditApiPlugins().Moderation;
|
|
743
|
+
await client.Remove({
|
|
744
|
+
id,
|
|
745
|
+
spam: isSpam,
|
|
746
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
747
|
+
}
|
|
748
|
+
/** @internal */
|
|
749
|
+
static async hide(id) {
|
|
750
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
751
|
+
await client.Hide({
|
|
752
|
+
id,
|
|
753
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
754
|
+
}
|
|
755
|
+
/** @internal */
|
|
756
|
+
static async unhide(id) {
|
|
757
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
758
|
+
await client.Unhide({
|
|
759
|
+
id,
|
|
760
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
761
|
+
}
|
|
762
|
+
/** @internal */
|
|
763
|
+
static async markAsNsfw(id) {
|
|
764
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
765
|
+
await client.MarkNSFW({
|
|
766
|
+
id,
|
|
767
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
768
|
+
}
|
|
769
|
+
/** @internal */
|
|
770
|
+
static async unmarkAsNsfw(id) {
|
|
771
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
772
|
+
await client.UnmarkNSFW({
|
|
773
|
+
id,
|
|
774
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
775
|
+
}
|
|
776
|
+
/** @internal */
|
|
777
|
+
static async markAsSpoiler(id) {
|
|
778
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
779
|
+
await client.Spoiler({
|
|
780
|
+
id,
|
|
781
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
782
|
+
}
|
|
783
|
+
/** @internal */
|
|
784
|
+
static async unmarkAsSpoiler(id) {
|
|
785
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
786
|
+
await client.Unspoiler({
|
|
787
|
+
id,
|
|
788
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
789
|
+
}
|
|
790
|
+
/** @internal */
|
|
791
|
+
static async sticky(id, position) {
|
|
792
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
793
|
+
await client.SetSubredditSticky({
|
|
794
|
+
id,
|
|
795
|
+
state: true,
|
|
796
|
+
num: position,
|
|
797
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
798
|
+
}
|
|
799
|
+
/** @internal */
|
|
800
|
+
static async unsticky(id) {
|
|
801
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
802
|
+
await client.SetSubredditSticky({
|
|
803
|
+
id,
|
|
804
|
+
state: false,
|
|
805
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
806
|
+
}
|
|
807
|
+
/** @internal */
|
|
808
|
+
static async lock(id) {
|
|
809
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
810
|
+
await client.Lock({
|
|
811
|
+
id,
|
|
812
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
813
|
+
}
|
|
814
|
+
/** @internal */
|
|
815
|
+
static async unlock(id) {
|
|
816
|
+
const client = getRedditApiPlugins().LinksAndComments;
|
|
817
|
+
await client.Unlock({
|
|
818
|
+
id,
|
|
819
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
820
|
+
}
|
|
821
|
+
/** @internal */
|
|
822
|
+
static async distinguish(id, asAdmin) {
|
|
823
|
+
const client = getRedditApiPlugins().Moderation;
|
|
824
|
+
const response = await client.Distinguish({
|
|
825
|
+
id,
|
|
826
|
+
how: asAdmin ? 'admin' : 'yes',
|
|
827
|
+
sticky: false,
|
|
828
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
829
|
+
const post = response.json?.data?.things?.[0]?.data;
|
|
830
|
+
assertNonNull(post);
|
|
831
|
+
return {
|
|
832
|
+
distinguishedBy: post.distinguished,
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/** @internal */
|
|
836
|
+
static async undistinguish(id) {
|
|
837
|
+
const client = getRedditApiPlugins().Moderation;
|
|
838
|
+
const response = await client.Distinguish({
|
|
839
|
+
id,
|
|
840
|
+
how: 'no',
|
|
841
|
+
sticky: false,
|
|
842
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
843
|
+
const post = response.json?.data?.things?.[0]?.data;
|
|
844
|
+
assertNonNull(post);
|
|
845
|
+
return {
|
|
846
|
+
distinguishedBy: post.distinguished,
|
|
847
|
+
};
|
|
848
|
+
}
|
|
849
|
+
/** @internal */
|
|
850
|
+
static async ignoreReports(id) {
|
|
851
|
+
const client = getRedditApiPlugins().Moderation;
|
|
852
|
+
await client.IgnoreReports({
|
|
853
|
+
id,
|
|
854
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
855
|
+
}
|
|
856
|
+
/** @internal */
|
|
857
|
+
static async unignoreReports(id) {
|
|
858
|
+
const client = getRedditApiPlugins().Moderation;
|
|
859
|
+
await client.UnignoreReports({
|
|
860
|
+
id,
|
|
861
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
862
|
+
}
|
|
863
|
+
/** @internal */
|
|
864
|
+
static getControversialPosts(options = {}) {
|
|
865
|
+
return this.getSortedPosts({
|
|
866
|
+
...options,
|
|
867
|
+
sort: 'controversial',
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
/** @internal */
|
|
871
|
+
static getTopPosts(options = {}) {
|
|
872
|
+
return this.getSortedPosts({
|
|
873
|
+
...options,
|
|
874
|
+
sort: 'top',
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
/** @internal */
|
|
878
|
+
static getSortedPosts(options) {
|
|
879
|
+
const client = getRedditApiPlugins().Listings;
|
|
880
|
+
return new Listing({
|
|
881
|
+
hasMore: true,
|
|
882
|
+
before: options.before,
|
|
883
|
+
after: options.after,
|
|
884
|
+
pageSize: options.pageSize,
|
|
885
|
+
limit: options.limit,
|
|
886
|
+
fetch: async (fetchOptions) => {
|
|
887
|
+
const response = await client.Sort({
|
|
888
|
+
show: 'all',
|
|
889
|
+
sort: options.sort,
|
|
890
|
+
t: options.timeframe,
|
|
891
|
+
subreddit: options.subredditName,
|
|
892
|
+
...fetchOptions,
|
|
893
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
894
|
+
return listingProtosToPosts(response);
|
|
895
|
+
},
|
|
896
|
+
});
|
|
897
|
+
}
|
|
898
|
+
/** @internal */
|
|
899
|
+
static getHotPosts(options = {
|
|
900
|
+
location: 'GLOBAL',
|
|
901
|
+
}) {
|
|
902
|
+
const client = getRedditApiPlugins().Listings;
|
|
903
|
+
return new Listing({
|
|
904
|
+
hasMore: true,
|
|
905
|
+
before: options.before,
|
|
906
|
+
after: options.after,
|
|
907
|
+
pageSize: options.pageSize,
|
|
908
|
+
limit: options.limit,
|
|
909
|
+
fetch: async (fetchOptions) => {
|
|
910
|
+
const response = await client.Hot({
|
|
911
|
+
g: options.location,
|
|
912
|
+
show: 'all',
|
|
913
|
+
subreddit: options.subredditName,
|
|
914
|
+
...fetchOptions,
|
|
915
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
916
|
+
return listingProtosToPosts(response);
|
|
917
|
+
},
|
|
918
|
+
});
|
|
919
|
+
}
|
|
920
|
+
/** @internal */
|
|
921
|
+
static getNewPosts(options) {
|
|
922
|
+
const client = getRedditApiPlugins().Listings;
|
|
923
|
+
return new Listing({
|
|
924
|
+
hasMore: true,
|
|
925
|
+
before: options.before,
|
|
926
|
+
after: options.after,
|
|
927
|
+
pageSize: options.pageSize,
|
|
928
|
+
limit: options.limit,
|
|
929
|
+
fetch: async (fetchOptions) => {
|
|
930
|
+
const response = await client.New({
|
|
931
|
+
show: 'all',
|
|
932
|
+
subreddit: options.subredditName,
|
|
933
|
+
...fetchOptions,
|
|
934
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
935
|
+
return listingProtosToPosts(response);
|
|
936
|
+
},
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
/** @internal */
|
|
940
|
+
static getRisingPosts(options) {
|
|
941
|
+
const client = getRedditApiPlugins().Listings;
|
|
942
|
+
return new Listing({
|
|
943
|
+
hasMore: true,
|
|
944
|
+
before: options.before,
|
|
945
|
+
after: options.after,
|
|
946
|
+
pageSize: options.pageSize,
|
|
947
|
+
limit: options.limit,
|
|
948
|
+
fetch: async (fetchOptions) => {
|
|
949
|
+
const response = await client.Rising({
|
|
950
|
+
show: 'all',
|
|
951
|
+
subreddit: options.subredditName,
|
|
952
|
+
...fetchOptions,
|
|
953
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
954
|
+
return listingProtosToPosts(response);
|
|
955
|
+
},
|
|
956
|
+
});
|
|
957
|
+
}
|
|
958
|
+
/** @internal */
|
|
959
|
+
static getPostsByUser(options) {
|
|
960
|
+
const client = getRedditApiPlugins().Users;
|
|
961
|
+
return new Listing({
|
|
962
|
+
hasMore: true,
|
|
963
|
+
before: options.before,
|
|
964
|
+
after: options.after,
|
|
965
|
+
pageSize: options.pageSize,
|
|
966
|
+
limit: options.limit,
|
|
967
|
+
fetch: async (fetchOptions) => {
|
|
968
|
+
const response = await client.UserWhere({
|
|
969
|
+
username: options.username,
|
|
970
|
+
where: 'submitted',
|
|
971
|
+
...fetchOptions,
|
|
972
|
+
}, __classPrivateFieldGet(this, _a, "a", _Post_metadata_get));
|
|
973
|
+
return listingProtosToPosts(response);
|
|
974
|
+
},
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
}
|
|
978
|
+
_a = Post, _Post_id = new WeakMap(), _Post_authorId = new WeakMap(), _Post_authorName = new WeakMap(), _Post_createdAt = new WeakMap(), _Post_subredditId = new WeakMap(), _Post_subredditName = new WeakMap(), _Post_permalink = new WeakMap(), _Post_title = new WeakMap(), _Post_body = new WeakMap(), _Post_bodyHtml = new WeakMap(), _Post_url = new WeakMap(), _Post_score = new WeakMap(), _Post_numberOfComments = new WeakMap(), _Post_numberOfReports = new WeakMap(), _Post_thumbnail = new WeakMap(), _Post_approved = new WeakMap(), _Post_approvedAtUtc = new WeakMap(), _Post_bannedAtUtc = new WeakMap(), _Post_spam = new WeakMap(), _Post_stickied = new WeakMap(), _Post_removed = new WeakMap(), _Post_removedBy = new WeakMap(), _Post_removedByCategory = new WeakMap(), _Post_archived = new WeakMap(), _Post_edited = new WeakMap(), _Post_locked = new WeakMap(), _Post_nsfw = new WeakMap(), _Post_quarantined = new WeakMap(), _Post_spoiler = new WeakMap(), _Post_hidden = new WeakMap(), _Post_ignoringReports = new WeakMap(), _Post_distinguishedBy = new WeakMap(), _Post_flair = new WeakMap(), _Post_secureMedia = new WeakMap(), _Post_modReportReasons = new WeakMap(), _Post_userReportReasons = new WeakMap(), _Post_gallery = new WeakMap(), _Post_metadata_get = function _Post_metadata_get() {
|
|
979
|
+
return getContext().debug.metadata;
|
|
980
|
+
};
|
|
981
|
+
function listingProtosToPosts(listingProto) {
|
|
982
|
+
if (!listingProto.data?.children) {
|
|
983
|
+
throw new Error('Listing response is missing children');
|
|
984
|
+
}
|
|
985
|
+
const children = listingProto.data.children.map((child) => new Post(child.data));
|
|
986
|
+
return {
|
|
987
|
+
children,
|
|
988
|
+
before: listingProto.data.before,
|
|
989
|
+
after: listingProto.data.after,
|
|
990
|
+
};
|
|
991
|
+
}
|
|
992
|
+
/** @internal */
|
|
993
|
+
async function getThumbnailV2(options) {
|
|
994
|
+
const operationName = 'GetThumbnailV2';
|
|
995
|
+
const persistedQueryHash = '81580ce4e23d748c5a59a1618489b559bf4518b6a73af41f345d8d074c8b2ce9';
|
|
996
|
+
const response = await GraphQL.query(operationName, persistedQueryHash, {
|
|
997
|
+
id: options.id,
|
|
998
|
+
});
|
|
999
|
+
const thumbnail = response.data?.postInfoById?.thumbnailV2;
|
|
1000
|
+
if (!thumbnail) {
|
|
1001
|
+
throw new Error('Failed to get thumbnail');
|
|
1002
|
+
}
|
|
1003
|
+
else if (!thumbnail.image) {
|
|
1004
|
+
return undefined;
|
|
1005
|
+
}
|
|
1006
|
+
return {
|
|
1007
|
+
attribution: thumbnail.attribution,
|
|
1008
|
+
image: {
|
|
1009
|
+
url: thumbnail.image.url,
|
|
1010
|
+
width: thumbnail.image.dimensions.width,
|
|
1011
|
+
height: thumbnail.image.dimensions.height,
|
|
1012
|
+
},
|
|
1013
|
+
isObfuscatedDefault: thumbnail.isObfuscatedDefault,
|
|
1014
|
+
...(thumbnail.obfuscatedImage && {
|
|
1015
|
+
obfuscatedImage: {
|
|
1016
|
+
url: thumbnail.obfuscatedImage.url,
|
|
1017
|
+
width: thumbnail.obfuscatedImage.dimensions.width,
|
|
1018
|
+
height: thumbnail.obfuscatedImage.dimensions.height,
|
|
1019
|
+
},
|
|
1020
|
+
}),
|
|
1021
|
+
};
|
|
1022
|
+
}
|