Class: PrivateMessage

PrivateMessage

A class representing a private message or a modmail.


new PrivateMessage()

Example
// Get a Private Message with a given ID
r.getMessage('51shnw')

Extends

Methods


markAsRead()

Marks this message as read.

Returns:

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

Type
Promise
Example
r.getMessage('51shxv').markAsRead()

markAsUnread()

Marks this message as unread.

Returns:

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

Type
Promise
Example
r.getMessage('51shxv').markAsUnread()

muteAuthor()

Mutes the author of this message for 72 hours. This can only be used on moderator mail.

Returns:

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

Type
Promise
Example
r.getMessage('51shxv').muteAuthor()

unmuteAuthor()

Unmutes the author of this message.

Returns:

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

Type
Promise
Example
r.getMessage('51shxv').unmuteAuthor()

deleteFromInbox()

Deletes this message from the authenticated user's inbox.

This only removes the item from the authenticated user's inbox. It has no effect on how the item looks to the sender.

Returns:

A Promise that fulfills with this message when the request is complete.

Type
Promise
Example
const firstMessage = r.getInbox().get(0);
firstMessage.deleteFromInbox();

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

Inherited From:
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

Inherited From:
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

Inherited From:
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

Inherited From:
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

Inherited From:
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

Inherited From:
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.

Inherited From:
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"}'