@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.
Files changed (97) hide show
  1. package/LICENSE +26 -0
  2. package/README.md +5 -0
  3. package/RedditClient.d.ts +1155 -0
  4. package/RedditClient.d.ts.map +1 -0
  5. package/RedditClient.js +1417 -0
  6. package/common.d.ts +10 -0
  7. package/common.d.ts.map +1 -0
  8. package/common.js +5 -0
  9. package/getReddit.d.ts +3 -0
  10. package/getReddit.d.ts.map +1 -0
  11. package/getReddit.js +8 -0
  12. package/getRedditApiPlugins.d.ts +23 -0
  13. package/getRedditApiPlugins.d.ts.map +1 -0
  14. package/getRedditApiPlugins.js +25 -0
  15. package/getUserActionsPlugin.d.ts +6 -0
  16. package/getUserActionsPlugin.d.ts.map +1 -0
  17. package/getUserActionsPlugin.js +12 -0
  18. package/graphql/GraphQL.d.ts +10 -0
  19. package/graphql/GraphQL.d.ts.map +1 -0
  20. package/graphql/GraphQL.js +27 -0
  21. package/helpers/makeGettersEnumerable.d.ts +2 -0
  22. package/helpers/makeGettersEnumerable.d.ts.map +1 -0
  23. package/helpers/makeGettersEnumerable.js +19 -0
  24. package/helpers/permissions.d.ts +6 -0
  25. package/helpers/permissions.d.ts.map +1 -0
  26. package/helpers/permissions.js +24 -0
  27. package/helpers/richtextToString.d.ts +3 -0
  28. package/helpers/richtextToString.d.ts.map +1 -0
  29. package/helpers/richtextToString.js +14 -0
  30. package/helpers/textFallbackToRichtext.d.ts +4 -0
  31. package/helpers/textFallbackToRichtext.d.ts.map +1 -0
  32. package/helpers/textFallbackToRichtext.js +14 -0
  33. package/index.d.ts +3 -0
  34. package/index.d.ts.map +1 -0
  35. package/index.js +1 -0
  36. package/models/Comment.d.ts +138 -0
  37. package/models/Comment.d.ts.map +1 -0
  38. package/models/Comment.js +597 -0
  39. package/models/Flair.d.ts +171 -0
  40. package/models/Flair.d.ts.map +1 -0
  41. package/models/Flair.js +293 -0
  42. package/models/Listing.d.ts +53 -0
  43. package/models/Listing.d.ts.map +1 -0
  44. package/models/Listing.js +101 -0
  45. package/models/ModAction.d.ts +32 -0
  46. package/models/ModAction.d.ts.map +1 -0
  47. package/models/ModAction.js +70 -0
  48. package/models/ModMail.d.ts +655 -0
  49. package/models/ModMail.d.ts.map +1 -0
  50. package/models/ModMail.js +723 -0
  51. package/models/ModNote.d.ts +57 -0
  52. package/models/ModNote.d.ts.map +1 -0
  53. package/models/ModNote.js +103 -0
  54. package/models/Post.d.ts +491 -0
  55. package/models/Post.d.ts.map +1 -0
  56. package/models/Post.js +1022 -0
  57. package/models/PrivateMessage.d.ts +52 -0
  58. package/models/PrivateMessage.d.ts.map +1 -0
  59. package/models/PrivateMessage.js +126 -0
  60. package/models/Subreddit.d.ts +606 -0
  61. package/models/Subreddit.d.ts.map +1 -0
  62. package/models/Subreddit.js +750 -0
  63. package/models/User.d.ts +238 -0
  64. package/models/User.d.ts.map +1 -0
  65. package/models/User.js +458 -0
  66. package/models/Vault.d.ts +32 -0
  67. package/models/Vault.d.ts.map +1 -0
  68. package/models/Vault.js +25 -0
  69. package/models/Widget.d.ts +133 -0
  70. package/models/Widget.d.ts.map +1 -0
  71. package/models/Widget.js +467 -0
  72. package/models/WikiPage.d.ts +137 -0
  73. package/models/WikiPage.d.ts.map +1 -0
  74. package/models/WikiPage.js +329 -0
  75. package/models/index.d.ts +14 -0
  76. package/models/index.d.ts.map +1 -0
  77. package/models/index.js +13 -0
  78. package/package.json +46 -0
  79. package/tests/comment.api.test.d.ts.map +1 -0
  80. package/tests/flair.api.test.d.ts.map +1 -0
  81. package/tests/modmail.api.test.d.ts.map +1 -0
  82. package/tests/modnote.api.test.d.ts.map +1 -0
  83. package/tests/post.api.test.d.ts.map +1 -0
  84. package/tests/subreddit.api.test.d.ts.map +1 -0
  85. package/tests/user.api.test.d.ts.map +1 -0
  86. package/tests/utils/createTestPreview.d.ts +2 -0
  87. package/tests/utils/createTestPreview.d.ts.map +1 -0
  88. package/tests/utils/createTestPreview.js +5 -0
  89. package/tests/utils/redditApiPluginsMock.d.ts +203 -0
  90. package/tests/utils/redditApiPluginsMock.d.ts.map +1 -0
  91. package/tests/utils/redditApiPluginsMock.js +202 -0
  92. package/tests/utils/runWithTestContext.d.ts +4 -0
  93. package/tests/utils/runWithTestContext.d.ts.map +1 -0
  94. package/tests/utils/runWithTestContext.js +12 -0
  95. package/tests/utils/userActionsPluginMock.d.ts +6 -0
  96. package/tests/utils/userActionsPluginMock.d.ts.map +1 -0
  97. package/tests/utils/userActionsPluginMock.js +5 -0
@@ -0,0 +1,723 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ 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");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
6
+ var _ModMailService_instances, _ModMailService_transformConversationData, _ModMailService_getConversationMessages, _ModMailService_getConversationModActions, _ModMailService_metadata_get;
7
+ import {} from '@devvit/protos';
8
+ import { getContext } from '@devvit/server';
9
+ import { asT5ID } from '@devvit/shared-types/tid.js';
10
+ import { getRedditApiPlugins } from '../getRedditApiPlugins.js';
11
+ import { GraphQL } from '../graphql/GraphQL.js';
12
+ export var ModMailConversationState;
13
+ (function (ModMailConversationState) {
14
+ ModMailConversationState["New"] = "New";
15
+ ModMailConversationState["InProgress"] = "InProgress";
16
+ ModMailConversationState["Archived"] = "Archived";
17
+ ModMailConversationState["Appeals"] = "Appeals";
18
+ ModMailConversationState["JoinRequests"] = "JoinRequests";
19
+ ModMailConversationState["Filtered"] = "Filtered";
20
+ })(ModMailConversationState || (ModMailConversationState = {}));
21
+ const R2_TO_MODMAIL_CONVERSATION_STATE = {
22
+ 0: ModMailConversationState.New,
23
+ 1: ModMailConversationState.InProgress,
24
+ 2: ModMailConversationState.Archived,
25
+ 3: ModMailConversationState.Appeals,
26
+ 4: ModMailConversationState.JoinRequests,
27
+ 5: ModMailConversationState.Filtered,
28
+ };
29
+ /**
30
+ * An ActionType describes a particular logged action within a conversation. For example,
31
+ * if a mod highlights a conversation, a ModerationAction record with the type `Highlighted`
32
+ * would be created.
33
+ */
34
+ export var ModMailActionType;
35
+ (function (ModMailActionType) {
36
+ ModMailActionType["Highlighted"] = "Highlighted";
37
+ ModMailActionType["Unhighlighted"] = "Unhighlighted";
38
+ ModMailActionType["Archived"] = "Archived";
39
+ ModMailActionType["Unarchived"] = "Unarchived";
40
+ ModMailActionType["ReportedToAdmins"] = "ReportedToAdmins";
41
+ ModMailActionType["Muted"] = "Muted";
42
+ ModMailActionType["Unmuted"] = "Unmuted";
43
+ ModMailActionType["Banned"] = "Banned";
44
+ ModMailActionType["Unbanned"] = "Unbanned";
45
+ ModMailActionType["Approved"] = "Approved";
46
+ ModMailActionType["Disapproved"] = "Disapproved";
47
+ ModMailActionType["Filtered"] = "Filtered";
48
+ ModMailActionType["Unfiltered"] = "Unfiltered";
49
+ })(ModMailActionType || (ModMailActionType = {}));
50
+ const R2_TO_MOD_ACTION_TYPE = {
51
+ 0: ModMailActionType.Highlighted,
52
+ 1: ModMailActionType.Unhighlighted,
53
+ 2: ModMailActionType.Archived,
54
+ 3: ModMailActionType.Unarchived,
55
+ 4: ModMailActionType.ReportedToAdmins,
56
+ 5: ModMailActionType.Muted,
57
+ 6: ModMailActionType.Unmuted,
58
+ 7: ModMailActionType.Banned,
59
+ 8: ModMailActionType.Unbanned,
60
+ 9: ModMailActionType.Approved,
61
+ 10: ModMailActionType.Disapproved,
62
+ 11: ModMailActionType.Filtered,
63
+ 12: ModMailActionType.Unfiltered,
64
+ };
65
+ /**
66
+ * Class providing the methods for working with Mod Mail
67
+ */
68
+ export class ModMailService {
69
+ /**
70
+ * @internal
71
+ */
72
+ constructor() {
73
+ _ModMailService_instances.add(this);
74
+ this.notificationSubjectPrefix = '[notification]';
75
+ }
76
+ /**
77
+ * Marks all conversations read for a particular conversation state within the passed list of subreddits.
78
+ *
79
+ * @param subreddits Array of subreddit names
80
+ * @param state One of the possible conversation states ('all' to read all conversations)
81
+ *
82
+ * @returns conversationIds
83
+ *
84
+ * @example
85
+ * ```ts
86
+ * const conversationIds = await reddit.modMail.bulkReadConversations(
87
+ * ['askReddit', 'myAwesomeSubreddit'],
88
+ * 'filtered'
89
+ * );
90
+ * ```
91
+ */
92
+ async bulkReadConversations(subreddits, state) {
93
+ const client = getRedditApiPlugins().NewModmail;
94
+ const { conversationIds } = await client.BulkReadConversations({
95
+ entity: subreddits.join(','),
96
+ state,
97
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
98
+ return conversationIds;
99
+ }
100
+ /**
101
+ * Get conversations for a logged in user or subreddits
102
+ *
103
+ * @param params.after id of a modmail
104
+ * @param params.subreddits array of subreddit names
105
+ * @param params.limit an integer between 1 and 100 (default: 25)
106
+ * @param params.sort one of (recent, mod, user, unread)
107
+ * @param params.state One of the possible conversation states ('all' to read all conversations)
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * const {viewerId, conversations} = await reddit.modMail.getConversations({
112
+ * after: 'abcdef',
113
+ * limit: 42
114
+ * });
115
+ *
116
+ * const arrayOfConversations = Object.values(conversations);
117
+ * ```
118
+ */
119
+ async getConversations(params) {
120
+ const client = getRedditApiPlugins().NewModmail;
121
+ const response = await client.GetConversations({
122
+ after: params.after,
123
+ entity: params.subreddits ? params.subreddits.join(',') : undefined,
124
+ limit: params.limit,
125
+ sort: params.sort,
126
+ state: params.state,
127
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
128
+ const conversations = {};
129
+ for (const id in response.conversations) {
130
+ conversations[id] = __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
131
+ protoConversation: response.conversations[id],
132
+ protoMessages: response.messages,
133
+ protoModActions: {},
134
+ });
135
+ }
136
+ return {
137
+ conversations,
138
+ viewerId: response.viewerId,
139
+ conversationIds: response.conversationIds,
140
+ };
141
+ }
142
+ /**
143
+ * Returns all messages, mod actions and conversation metadata for a given conversation id
144
+ *
145
+ * @param params.conversationId id of a modmail conversation
146
+ * @param params.markRead should be marked as read (default: false)
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * const { conversation, messages, modActions, user } = await reddit.modMail.getConversation({ conversationId: 'abcdef', markRead: true });
151
+ * ```
152
+ */
153
+ async getConversation(params) {
154
+ const client = getRedditApiPlugins().NewModmail;
155
+ const response = await client.GetConversation({ ...params, markRead: !!params.markRead }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
156
+ return {
157
+ participantSubreddit: response.participantSubreddit,
158
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
159
+ protoConversation: response.conversation,
160
+ protoMessages: response.messages,
161
+ protoModActions: response.modActions,
162
+ }),
163
+ user: response.user,
164
+ };
165
+ }
166
+ /**
167
+ * Returns a list of Subreddits that the user moderates with mail permission
168
+ *
169
+ * @example
170
+ * ```ts
171
+ * const subredditsData = await reddit.modMail.getSubreddits();
172
+ *
173
+ * for (const subreddit of Object.values(subreddits)) {
174
+ * console.log(subreddit.id);
175
+ * console.log(subreddit.name);
176
+ * }
177
+ * ```
178
+ */
179
+ async getSubreddits() {
180
+ const client = getRedditApiPlugins().NewModmail;
181
+ const { subreddits } = await client.Subreddits({}, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
182
+ return subreddits;
183
+ }
184
+ /**
185
+ * Creates a new conversation for a particular SR.
186
+ *
187
+ * This endpoint will create a ModmailConversation object
188
+ * as well as the first ModmailMessage within the ModmailConversation object.
189
+ *
190
+ * @note
191
+ * Note on {param.to}:
192
+ * The to field for this endpoint is somewhat confusing. It can be:
193
+ * - A User, passed like "username" or "u/username"
194
+ * - A Subreddit, passed like "r/subreddit"
195
+ * - null, meaning an internal moderator discussion
196
+ *
197
+ * In this way to is a bit of a misnomer in modmail conversations.
198
+ * What it really means is the participant of the conversation who is not a mod of the subreddit.
199
+ *
200
+ * If you plan to send a message to the app-account or a moderator of the subreddit, use {@link ModMailService.createModDiscussionConversation}, {@link ModMailService.createModInboxConversation}, or {@link ModMailService.createModNotification} instead.
201
+ * Otherwise, messages sent to the app-account or moderator will automatically be routed to Mod Discussions.
202
+ * @param params.body markdown text
203
+ * @param params.isAuthorHidden is author hidden? (default: false)
204
+ * @param params.subredditName subreddit name
205
+ * @param params.subject subject of the conversation. max 100 characters
206
+ * @param params.to a user (e.g. u/username), a subreddit (e.g. r/subreddit) or null
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * const { conversation, messages, modActions } = await reddit.modMail.createConversation({
211
+ * subredditName: 'askReddit',
212
+ * subject: 'Test conversation',
213
+ * body: 'Lorem ipsum sit amet',
214
+ * to: null,
215
+ * });
216
+ * ```
217
+ */
218
+ async createConversation(params) {
219
+ const client = getRedditApiPlugins().NewModmail;
220
+ const response = await client.CreateConversation({
221
+ body: params.body,
222
+ isAuthorHidden: params.isAuthorHidden ?? false,
223
+ srName: params.subredditName,
224
+ subject: params.subject,
225
+ to: params.to ? params.to : undefined,
226
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
227
+ return {
228
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
229
+ protoConversation: response.conversation,
230
+ protoMessages: response.messages,
231
+ protoModActions: response.modActions,
232
+ }),
233
+ user: response.user,
234
+ };
235
+ }
236
+ /**
237
+ * Creates a conversation in Mod Discussions with the moderators of the given subredditId.
238
+ *
239
+ * Note: The app must be installed in the subreddit in order to create a conversation in Mod Discussions.
240
+ *
241
+ * @param params.subject - The subject of the message.
242
+ * @param params.bodyMarkdown - The body of the message in Markdown format, e.g. `Hello world \n\n **Have a great day**`.
243
+ * @param params.subredditId - The ID (starting with `t5_`) of the subreddit to which to send the message, e.g. `t5_2qjpg`.
244
+ * @returns A Promise that resolves a string representing the conversationId of the message.
245
+ * @example
246
+ * ```ts
247
+ * const conversationId = await reddit.modMail.createModDiscussionConversation({
248
+ * subject: 'Test conversation',
249
+ * bodyMarkdown: '**Hello there** \n\n _Have a great day!_',
250
+ * subredditId: context.subredditId
251
+ * });
252
+ * ```
253
+ */
254
+ async createModDiscussionConversation(params) {
255
+ return createModmailConversation({
256
+ subject: params.subject,
257
+ bodyMarkdown: params.bodyMarkdown,
258
+ subredditId: asT5ID(params.subredditId),
259
+ isInternal: true,
260
+ participantType: 'MODERATOR',
261
+ conversationType: 'INTERNAL',
262
+ });
263
+ }
264
+ /**
265
+ * Creates a conversation in the Modmail Inbox with the moderators of the given subredditId.
266
+ *
267
+ * @param params.subject - The subject of the message.
268
+ * @param params.bodyMarkdown - The body of the message in Markdown format, e.g. `Hello world \n\n **Have a great day**`.
269
+ * @param params.subredditId - The ID (starting with `t5_`) of the subreddit to which to send the message, e.g. `t5_2qjpg`.
270
+ * @returns A Promise that resolves a string representing the conversationId of the message.
271
+ * @example
272
+ * ```ts
273
+ * const conversationId = await reddit.modMail.createModInboxConversation({
274
+ * subject: 'Test conversation',
275
+ * bodyMarkdown: '**Hello there** \n\n _Have a great day!_',
276
+ * subredditId: context.subredditId
277
+ * });
278
+ * ```
279
+ */
280
+ async createModInboxConversation(params) {
281
+ return createModmailConversation({
282
+ subject: params.subject,
283
+ bodyMarkdown: params.bodyMarkdown,
284
+ subredditId: asT5ID(params.subredditId),
285
+ isInternal: false,
286
+ participantType: 'PARTICIPANT_USER',
287
+ conversationType: 'SR_USER',
288
+ });
289
+ }
290
+ /**
291
+ * Creates a notification in the Modmail Inbox.
292
+ * This function is different from {@link ModMailService.createModInboxConversation} in that the conversation also appears in the "Notifications" section of Modmail.
293
+ *
294
+ * @param params.subject - The subject of the message.
295
+ * @param params.bodyMarkdown - The body of the message in Markdown format, e.g. `Hello world \n\n **Have a great day**`.
296
+ * @param params.subredditId - The ID (starting with `t5_`) of the subreddit to which to send the message, e.g. `t5_2qjpg`.
297
+ * @returns A Promise that resolves a string representing the conversationId of the message.
298
+ * @example
299
+ * ```ts
300
+ * const conversationId = await reddit.modMail.createModNotification({
301
+ * subject: 'Test notification',
302
+ * bodyMarkdown: '**Hello there** \n\n _This is a notification!_',
303
+ * subredditId: context.subredditId
304
+ * });
305
+ * ```
306
+ */
307
+ async createModNotification(params) {
308
+ let notificationSubject = params.subject;
309
+ if (!params.subject.startsWith(this.notificationSubjectPrefix)) {
310
+ notificationSubject = `${this.notificationSubjectPrefix} ${params.subject}`;
311
+ }
312
+ return createModmailConversation({
313
+ subject: notificationSubject,
314
+ bodyMarkdown: params.bodyMarkdown,
315
+ subredditId: asT5ID(params.subredditId),
316
+ isInternal: false,
317
+ participantType: 'PARTICIPANT_USER',
318
+ conversationType: 'SR_USER',
319
+ });
320
+ }
321
+ /**
322
+ * Creates a new message for a particular conversation.
323
+ *
324
+ * @param params.conversationId Id of a modmail conversation
325
+ * @param params.body markdown text
326
+ * @param params.isInternal is internal message? (default: false)
327
+ * @param params.isAuthorHidden is author hidden? (default: false)
328
+ *
329
+ * @example
330
+ * ```ts
331
+ * await reddit.modMail.reply({
332
+ * body: 'Lorem ipsum sit amet',
333
+ * conversationId: 'abcdef',
334
+ * });
335
+ * ```
336
+ */
337
+ async reply(params) {
338
+ const client = getRedditApiPlugins().NewModmail;
339
+ const response = await client.CreateConversationMessage({
340
+ body: params.body,
341
+ conversationId: params.conversationId,
342
+ isAuthorHidden: params.isAuthorHidden ?? false,
343
+ isInternal: params.isInternal ?? false,
344
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
345
+ return {
346
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
347
+ protoConversation: response.conversation,
348
+ protoMessages: response.messages,
349
+ protoModActions: {},
350
+ }),
351
+ user: response.user,
352
+ };
353
+ }
354
+ /**
355
+ * Marks a conversation as highlighted.
356
+ *
357
+ * @param conversationId Id of a modmail conversation
358
+ *
359
+ * @example
360
+ * ```ts
361
+ * await reddit.modMail.highlightConversation('abcdef');
362
+ * ```
363
+ */
364
+ async highlightConversation(conversationId) {
365
+ const client = getRedditApiPlugins().NewModmail;
366
+ const response = await client.HighlightConversation({
367
+ conversationId: conversationId,
368
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
369
+ return {
370
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
371
+ protoConversation: response.conversation,
372
+ protoMessages: response.messages,
373
+ protoModActions: response.modActions,
374
+ }),
375
+ };
376
+ }
377
+ /**
378
+ * Removes a highlight from a conversation.
379
+ *
380
+ * @param conversationId Id of a modmail conversation
381
+ *
382
+ * @example
383
+ * ```ts
384
+ * await reddit.modMail.unhighlightConversation('abcdef');
385
+ * ```
386
+ */
387
+ async unhighlightConversation(conversationId) {
388
+ const client = getRedditApiPlugins().NewModmail;
389
+ const response = await client.UnhighlightConversation({
390
+ conversationId: conversationId,
391
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
392
+ return {
393
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
394
+ protoConversation: response.conversation,
395
+ protoMessages: response.messages,
396
+ protoModActions: response.modActions,
397
+ }),
398
+ };
399
+ }
400
+ /**
401
+ * Marks a conversation as archived
402
+ *
403
+ * @param conversationId Id of a modmail conversation
404
+ *
405
+ * @example
406
+ * ```ts
407
+ * await reddit.modMail.archive('abcdef');
408
+ * ```
409
+ */
410
+ async archiveConversation(conversationId) {
411
+ const client = getRedditApiPlugins().NewModmail;
412
+ const response = await client.ArchiveConversation({
413
+ conversationId: conversationId,
414
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
415
+ return {
416
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
417
+ protoConversation: response.conversation,
418
+ protoMessages: response.messages,
419
+ protoModActions: response.modActions,
420
+ }),
421
+ };
422
+ }
423
+ /**
424
+ * Marks conversation as unarchived.
425
+ *
426
+ * @param conversationId Id of a modmail conversation
427
+ *
428
+ * @example
429
+ * ```ts
430
+ * await reddit.modMail.unarchiveConversation('abcdef');
431
+ * ```
432
+ */
433
+ async unarchiveConversation(conversationId) {
434
+ const client = getRedditApiPlugins().NewModmail;
435
+ const response = await client.UnarchiveConversation({
436
+ conversationId: conversationId,
437
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
438
+ return {
439
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
440
+ protoConversation: response.conversation,
441
+ protoMessages: response.messages,
442
+ protoModActions: response.modActions,
443
+ }),
444
+ };
445
+ }
446
+ /**
447
+ * Marks a conversation as read for the user.
448
+ *
449
+ * @param params.conversationId Id of a modmail conversation
450
+ * @param params.numHours For how many hours the conversation needs to be muted. Must be one of 72, 168, or 672 hours
451
+ *
452
+ * @example
453
+ * ```ts
454
+ * await reddit.modMail.muteConversation({ conversationId: 'abcdef', numHours: 72 });
455
+ * ```
456
+ */
457
+ async muteConversation(params) {
458
+ const client = getRedditApiPlugins().NewModmail;
459
+ const response = await client.MuteConversation({
460
+ conversationId: params.conversationId,
461
+ numHours: params.numHours,
462
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
463
+ return {
464
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
465
+ protoConversation: response.conversations,
466
+ protoMessages: response.messages,
467
+ protoModActions: response.modActions,
468
+ }),
469
+ user: response.user,
470
+ };
471
+ }
472
+ /**
473
+ * Unmutes the non mod user associated with a particular conversation.
474
+ *
475
+ * @param conversationId Id of a modmail conversation
476
+ *
477
+ * @example
478
+ * ```ts
479
+ * await reddit.modMail.unmuteConversation('abcdef');
480
+ * ```
481
+ */
482
+ async unmuteConversation(conversationId) {
483
+ const client = getRedditApiPlugins().NewModmail;
484
+ const response = await client.UnmuteConversation({
485
+ conversationId,
486
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
487
+ return {
488
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
489
+ protoConversation: response.conversations,
490
+ protoMessages: response.messages,
491
+ protoModActions: response.modActions,
492
+ }),
493
+ user: response.user,
494
+ };
495
+ }
496
+ /**
497
+ * Marks a conversations as read for the user.
498
+ *
499
+ * @param conversationIds An array of ids
500
+ *
501
+ * @example
502
+ * ```ts
503
+ * await reddit.modMail.readConversations(['abcdef', 'qwerty']);
504
+ * ```
505
+ */
506
+ async readConversations(conversationIds) {
507
+ const client = getRedditApiPlugins().NewModmail;
508
+ await client.Read({
509
+ conversationIds: conversationIds.join(','),
510
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
511
+ }
512
+ /**
513
+ * Marks conversations as unread for the user.
514
+ *
515
+ * @param conversationIds An array of ids
516
+ *
517
+ * @example
518
+ * ```ts
519
+ * await reddit.modMail.unreadConversations(['abcdef', 'qwerty']);
520
+ * ```
521
+ */
522
+ async unreadConversations(conversationIds) {
523
+ const client = getRedditApiPlugins().NewModmail;
524
+ await client.Unread({
525
+ conversationIds: conversationIds.join(','),
526
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
527
+ }
528
+ /**
529
+ * Approve the non mod user associated with a particular conversation.
530
+ *
531
+ * @param conversationId Id of a modmail conversation
532
+ *
533
+ * @example
534
+ * ```ts
535
+ * await reddit.modMail.approveConversation('abcdef');
536
+ * ```
537
+ */
538
+ async approveConversation(conversationId) {
539
+ const client = getRedditApiPlugins().NewModmail;
540
+ const response = await client.ApproveConversation({
541
+ conversationId,
542
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
543
+ return {
544
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
545
+ protoConversation: response.conversations,
546
+ protoMessages: response.messages,
547
+ protoModActions: response.modActions,
548
+ }),
549
+ user: response.user,
550
+ };
551
+ }
552
+ /**
553
+ * Disapprove the non mod user associated with a particular conversation.
554
+ *
555
+ * @param conversationId Id of a modmail conversation
556
+ *
557
+ * @example
558
+ * ```ts
559
+ * await reddit.modMail.disapproveConversation('abcdef');
560
+ * ```
561
+ */
562
+ async disapproveConversation(conversationId) {
563
+ const client = getRedditApiPlugins().NewModmail;
564
+ const response = await client.DisapproveConversation({
565
+ conversationId,
566
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
567
+ return {
568
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
569
+ protoConversation: response.conversations,
570
+ protoMessages: response.messages,
571
+ protoModActions: response.modActions,
572
+ }),
573
+ user: response.user,
574
+ };
575
+ }
576
+ /**
577
+ * Temporary ban (switch from permanent to temporary ban) the non mod user associated with a particular conversation.
578
+ *
579
+ * @param params.conversationId a modmail conversation id
580
+ * @param params.duration duration in days, max 999
581
+ *
582
+ * @example
583
+ * ```ts
584
+ * await reddit.modMail.tempBanConversation({ conversationId: 'abcdef', duration: 42 });
585
+ * ```
586
+ */
587
+ async tempBanConversation(params) {
588
+ const client = getRedditApiPlugins().NewModmail;
589
+ const response = await client.TempBan({
590
+ ...params,
591
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
592
+ return {
593
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
594
+ protoConversation: response.conversations,
595
+ protoMessages: response.messages,
596
+ protoModActions: response.modActions,
597
+ }),
598
+ user: response.user,
599
+ };
600
+ }
601
+ /**
602
+ * Unban the non mod user associated with a particular conversation.
603
+ *
604
+ * @param conversationId a modmail conversation id
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * await reddit.modMail.unbanConversation('abcdef');
609
+ * ```
610
+ */
611
+ async unbanConversation(conversationId) {
612
+ const client = getRedditApiPlugins().NewModmail;
613
+ const response = await client.Unban({
614
+ conversationId,
615
+ }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
616
+ return {
617
+ conversation: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_transformConversationData).call(this, {
618
+ protoConversation: response.conversations,
619
+ protoMessages: response.messages,
620
+ protoModActions: response.modActions,
621
+ }),
622
+ user: response.user,
623
+ };
624
+ }
625
+ /**
626
+ * Endpoint to retrieve the unread conversation count by conversation state.
627
+ *
628
+ * @example
629
+ * ```ts
630
+ * const response = await reddit.modMail.getUnreadCount();
631
+ *
632
+ * console.log(response.highlighted);
633
+ * console.log(response.new);
634
+ * ```
635
+ */
636
+ async getUnreadCount() {
637
+ const client = getRedditApiPlugins().NewModmail;
638
+ return await client.UnreadCount({}, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
639
+ }
640
+ /**
641
+ * Returns recent posts, comments and modmail conversations for a given user.
642
+ *
643
+ * @param conversationId Id of a modmail conversation
644
+ *
645
+ * @example
646
+ * ```ts
647
+ * const data = await reddit.modMail.getUserConversations('abcdef');
648
+ *
649
+ * console.log(data.recentComments);
650
+ * console.log(data.recentPosts);
651
+ * ```
652
+ */
653
+ async getUserConversations(conversationId) {
654
+ const client = getRedditApiPlugins().NewModmail;
655
+ return await client.UserConversations({ conversationId }, __classPrivateFieldGet(this, _ModMailService_instances, "a", _ModMailService_metadata_get));
656
+ }
657
+ }
658
+ _ModMailService_instances = new WeakSet(), _ModMailService_transformConversationData = function _ModMailService_transformConversationData({ protoConversation, protoMessages, protoModActions, }) {
659
+ return {
660
+ ...protoConversation,
661
+ state: R2_TO_MODMAIL_CONVERSATION_STATE[protoConversation.state],
662
+ messages: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_getConversationMessages).call(this, protoConversation, protoMessages),
663
+ modActions: __classPrivateFieldGet(this, _ModMailService_instances, "m", _ModMailService_getConversationModActions).call(this, protoConversation, protoModActions),
664
+ };
665
+ }, _ModMailService_getConversationMessages = function _ModMailService_getConversationMessages(protoConversation, protoMessages) {
666
+ const messages = {};
667
+ const messageIds = protoConversation.objIds
668
+ .filter((o) => o.key === 'messages')
669
+ .map(({ id }) => id);
670
+ for (const messageId of messageIds) {
671
+ const protoMessage = protoMessages[messageId];
672
+ if (protoMessage) {
673
+ messages[messageId] = protoMessage;
674
+ }
675
+ }
676
+ return messages;
677
+ }, _ModMailService_getConversationModActions = function _ModMailService_getConversationModActions(protoConversation, protoModActions) {
678
+ const modActions = {};
679
+ const modActionIds = protoConversation.objIds
680
+ .filter((o) => o.key === 'modActions')
681
+ .map(({ id }) => id);
682
+ for (const modActionId of modActionIds) {
683
+ const protoModAction = protoModActions[modActionId];
684
+ if (protoModAction) {
685
+ modActions[modActionId] = {
686
+ ...protoModAction,
687
+ actionType: R2_TO_MOD_ACTION_TYPE[protoModAction.actionTypeId],
688
+ };
689
+ }
690
+ }
691
+ return modActions;
692
+ }, _ModMailService_metadata_get = function _ModMailService_metadata_get() {
693
+ return getContext().debug.metadata;
694
+ };
695
+ /**
696
+ * Creates a Modmail conversation with the moderators of the given subredditId.
697
+ * @internal
698
+ * @param params.subject - The subject of the message.
699
+ * @param params.bodyMarkdown - The body of the message in Markdown format, e.g. `Hello world \n\n **Have a great day**`.
700
+ * @param params.subredditId - The ID (starting with `t5_`) of the subreddit to which to send the message, e.g. `t5_2qjpg`.
701
+ * @param params.isInternal - Indicates if the conversation should be internal or not.
702
+ * @param params.participantType - The type of participant the author is in the conversation.
703
+ * @param params.conversationType - The type of conversation to create.
704
+ * @returns A Promise that resolves a string representing the conversationId of the message.
705
+ */
706
+ async function createModmailConversation(params) {
707
+ const appUserId = getContext().appAccountId; // TODO: This is deprecated?
708
+ const operationName = 'CreateModmailConversation';
709
+ const persistedQueryHash = '5f9ae20b0c7bdffcafb80241728a72e67cd4239bc09f67284b79d4aa706ee0e5';
710
+ const response = await GraphQL.query(operationName, persistedQueryHash, {
711
+ subject: params.subject,
712
+ bodyMarkdown: params.bodyMarkdown,
713
+ subredditId: params.subredditId,
714
+ authorId: appUserId,
715
+ isInternal: params.isInternal,
716
+ participantType: params.participantType,
717
+ conversationType: params.conversationType,
718
+ });
719
+ if (response.data?.createModmailConversationV2?.ok) {
720
+ return response.data?.createModmailConversationV2?.conversationId;
721
+ }
722
+ throw new Error('modmail conversation creation failed; ${response.data?.createModmailConversationV2?.errors[0].message}');
723
+ }