class Redd::Models::ModMail

A container for the new modmail. XXX: Instead of making ModMail a dumb container, could it be a lazy wrapper for unread_count?

Public Instance Methods

conversations(subreddits: nil, **params) click to toggle source

Get the conversations @param subreddits [Subreddit, Array<Subreddit>] the subreddits to limit to @param params [Hash] additional request parameters @option params [String] :after base36 modmail conversation id @option params [Integer] :limit an integer (default: 25) @option params [:recent, :mod, :user, :unread] :sort the sort order @option params [:new, :inprogress, :mod, :notifications, :archived, :highlighted, :all]

:state the state to limit the conversations by
# File lib/redd/models/mod_mail.rb, line 113
def conversations(subreddits: nil, **params)
  params[:entity] = Array(subreddits).map(&:display_name).join(',') if subreddits
  @client.get('/api/mod/conversations', **params).body[:conversations].map do |_, conv|
    Conversation.new(@client, conv)
  end
end
create(from:, to:, subject:, body:, hidden: false) click to toggle source

Create a new conversation. @param from [Subreddit] the subreddit to send the conversation from @param to [User] the person to send the message to @param subject [String] the message subject @param body [String] the message body @return [Conversation] the created conversation

# File lib/redd/models/mod_mail.rb, line 126
def create(from:, to:, subject:, body:, hidden: false)
  Conversation.new(@client, @client.post(
    '/api/mod/conversations',
    srName: from.display_name, to: to.name,
    subject: subject, body: body, isAuthorHidden: hidden
  ).body[:conversation])
end
enrolled() click to toggle source

@return [Array<Subreddit>] moderated subreddits that are enrolled in the new modmail

# File lib/redd/models/mod_mail.rb, line 99
def enrolled
  @client.get('/api/mod/conversations/subreddits').body[:subreddits].map do |_, s|
    Subreddit.new(@client, s.merge(last_updated: s.delete(:lastUpdated)))
  end
end
get(id) click to toggle source

Get a conversation from its base36 id. @param id [String] the conversation's id @return [Conversation]

# File lib/redd/models/mod_mail.rb, line 137
def get(id)
  Conversation.from_id(@client, id)
end
unread_count() click to toggle source

@return [#highlighted, notifications, archived, new, inprogress, mod] the number of

unread messages in each category
# File lib/redd/models/mod_mail.rb, line 94
def unread_count
  BasicModel.new(nil, @client.get('/api/mod/conversations/unread/count').body)
end