Class: ReplyableContent

ReplyableContent

A set of mixin functions that apply to Submissions, Comments, and PrivateMessages


new ReplyableContent()

Extends

Methods


remove(options)

Removes this Comment, Submission or PrivateMessage from public listings.

This requires the authenticated user to be a moderator of the subreddit with the posts permission.

Parameters:
Name Type Description
options object
Properties
Name Type Argument Default Description
spam boolean <optional>
false

Determines whether this should be marked as spam

Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').remove({spam: true})

approve()

Approves this Comment, Submission, or PrivateMessage, re-adding it to public listings if it had been removed

Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').approve()

report( [options])

Reports this content anonymously to subreddit moderators (for Comments and Submissions) or to the reddit admins (for PrivateMessages)

Parameters:
Name Type Argument Description
options object <optional>
Properties
Name Type Argument Description
reason string <optional>

The reason for the report

Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').report({reason: 'Breaking the subreddit rules'})

ignoreReports()

Ignores reports on this Comment, Submission, or PrivateMessage

Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').ignoreReports()

unignoreReports()

Unignores reports on this Comment, Submission, or PrivateMessages

Returns:

A Promise that fulfills with this content when the request is complete

Type
Promise
Example
r.getComment('c08pp5z').unignoreReports()

reply(text)

Submits a new reply to this object. (This takes the form of a new Comment if this object is a Submission/Comment, or a new PrivateMessage if this object is a PrivateMessage.)

Parameters:
Name Type Description
text string

The content of the reply, in raw markdown text

Returns:

A Promise that fulfills with the newly-created reply

Type
Promise
Example
r.getSubmission('4e60m3').reply('This was an interesting post. Thanks.');

blockAuthor()

Blocks the author of this content.

Note: In order for this function to have an effect, this item must be in the authenticated account's inbox or modmail somewhere. The reddit API gives no outward indication of whether this condition is satisfied, so the returned Promise will fulfill even if this is not the case.

Returns:

A Promise that fulfills with this message after the request is complete

Type
Promise
Example
r.getInbox({limit: 1}).then(messages =>
  messages[0].blockAuthor();
);

fetch()

Fetches this content from reddit.

This will not mutate the original content object; all Promise properties will remain as Promises after the content has been fetched. However, the information on this object will be cached, so it may become out-of-date with the content on reddit. To clear the cache and fetch this object from reddit again, use refresh().

If snoowrap is running in an environment that supports ES2015 Proxies (e.g. Chrome 49+), then fetch() will get automatically called when an unknown property is accessed on an unfetched content object.

Inherited From:
Returns:

A version of this object with all of its fetched properties from reddit. This will not mutate the object. Once an object has been fetched once, its properties will be cached, so they might end up out-of-date if this function is called again. To refresh an object, use refresh().

Type
Promise
Example
r.getUser('not_an_aardvark').fetch().then(userInfo => {
  console.log(userInfo.name); // 'not_an_aardvark'
  console.log(userInfo.created_utc); // 1419104352
});

r.getComment('d1xchqn').fetch().then(comment => comment.body).then(console.log)
// => 'This is a little too interesting for my liking'

// In environments that support ES2015 Proxies, the above line is equivalent to:
r.getComment('d1xchqn').body.then(console.log);
// => 'This is a little too interesting for my liking'

refresh()

Refreshes this content.

Inherited From:
Returns:

A newly-fetched version of this content

Type
Promise
Example
var someComment = r.getComment('cmfkyus');
var initialCommentBody = some_comment.fetch().then(comment => comment.body);

setTimeout(() => {
  someComment.refresh().then(refreshedComment => {
    if (initialCommentBody.value() !== refreshedComment.body) {
      console.log('This comment has changed since 10 seconds ago.');
    }
  });
}, 10000);

toJSON()

Returns a stringifyable version of this object.

It is usually not necessary to call this method directly; simply running JSON.stringify(some_object) will strip the private properties anyway.

Inherited From:
Returns:

A version of this object with all the private properties stripped

Type
object
Example
var user = r.getUser('not_an_aardvark');
JSON.stringify(user) // => '{"name":"not_an_aardvark"}'