class Redd::Models::ModMail::Conversation

Represents a conversation in the new modmail. TODO: add modmail-specific user type

Public Class Methods

from_id(client, id) click to toggle source

Get a Conversation from its id. @param id [String] the base36 id (e.g. abc123) @return [Conversation]

# File lib/redd/models/mod_mail.rb, line 17
def self.from_id(client, id)
  new(client, id: id)
end

Public Instance Methods

archive() click to toggle source

Mark this conversation as archived.

# File lib/redd/models/mod_mail.rb, line 41
def archive
  perform_action(:post, 'archive')
end
highlight() click to toggle source

Highlight this conversation.

# File lib/redd/models/mod_mail.rb, line 51
def highlight
  perform_action(:post, 'highlight')
end
mark_as_read() click to toggle source

Mark this conversation as read.

# File lib/redd/models/mod_mail.rb, line 31
def mark_as_read
  @client.post('/api/mod/conversations/read', conversationIds: [get_attribute(:id)])
end
mark_as_unread() click to toggle source

Mark this conversation as unread.

# File lib/redd/models/mod_mail.rb, line 36
def mark_as_unread
  @client.post('/api/mod/conversations/unread', conversationIds: [get_attribute(:id)])
end
mute() click to toggle source

Mute this conversation.

# File lib/redd/models/mod_mail.rb, line 61
def mute
  perform_action(:post, 'mute')
end
reply(body, hidden: false, internal: false) click to toggle source

Add a reply to the ongoing conversation.

# File lib/redd/models/mod_mail.rb, line 22
def reply(body, hidden: false, internal: false)
  # TODO: merge response into the conversation
  @client.post(
    "/api/mod/conversations/#{get_attribute(:id)}",
    body: body, isAuthorHidden: hidden, isInternal: internal
  ).body
end
unarchive() click to toggle source

Removed this conversation from archived.

# File lib/redd/models/mod_mail.rb, line 46
def unarchive
  perform_action(:post, 'unarchive')
end
unhighlight() click to toggle source

Remove the highlight on this conversation.

# File lib/redd/models/mod_mail.rb, line 56
def unhighlight
  perform_action(:delete, 'highlight')
end
unmute() click to toggle source

Unmute this conversation.

# File lib/redd/models/mod_mail.rb, line 66
def unmute
  perform_action(:post, 'unmute')
end

Private Instance Methods

default_loader() click to toggle source
# File lib/redd/models/mod_mail.rb, line 72
def default_loader
  response = @client.get("/api/mod/conversations/#{@attributes[:id]}").body
  response[:conversation].merge(
    messages: response[:messages].values.map { |m| Message.new(@client, m) },
    user: response[:user],
    mod_actions: response[:modActions]
  )
end
perform_action(method, action) click to toggle source

Perform an action on a conversation. @param method [:post, :delete] the method to use @param action [String] the name of the action

# File lib/redd/models/mod_mail.rb, line 84
def perform_action(method, action)
  @client.send(method, "/api/mod/conversations/#{id}/#{action}")
end