Class: Redd::Models::ModMail

Inherits:
BasicModel show all
Defined in:
lib/redd/models/mod_mail.rb

Overview

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

Defined Under Namespace

Classes: Conversation, Message

Instance Attribute Summary

Attributes inherited from BasicModel

#client

Instance Method Summary collapse

Methods inherited from BasicModel

from_id, #initialize, #inspect, #method_missing, #respond_to_missing?, #to_ary, #to_h

Constructor Details

This class inherits a constructor from Redd::Models::BasicModel

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Redd::Models::BasicModel

Instance Method Details

#conversations(subreddits: nil, **params) ⇒ Object

Get the conversations

Options Hash (**params):

  • :after (String)

    base36 modmail conversation id

  • :limit (Integer)

    an integer (default: 25)

  • :sort (:recent, :mod, :user, :unread)

    the sort order

  • :state (:new, :inprogress, :mod, :notifications, :archived, :highlighted, :all)

    the state to limit the conversations by


113
114
115
116
117
118
# 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) ⇒ Conversation

Create a new conversation.


126
127
128
129
130
131
132
# 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

#enrolledArray<Subreddit>


99
100
101
102
103
# 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) ⇒ Conversation

Get a conversation from its base36 id.


137
138
139
# File 'lib/redd/models/mod_mail.rb', line 137

def get(id)
  Conversation.from_id(@client, id)
end

#unread_count#highlighted, ...


94
95
96
# File 'lib/redd/models/mod_mail.rb', line 94

def unread_count
  BasicModel.new(nil, @client.get('/api/mod/conversations/unread/count').body)
end