Class: Redd::Models::ModMail::Conversation

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

Overview

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

Instance Attribute Summary

Attributes inherited from BasicModel

#client

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from LazyModel

#force_load, #initialize, #method_missing, #respond_to_missing?, #to_h

Methods inherited from BasicModel

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

Constructor Details

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

Dynamic Method Handling

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

Class Method Details

.from_id(client, id) ⇒ Conversation

Get a Conversation from its id.

Parameters:

  • id (String)

    the base36 id (e.g. abc123)

Returns:



17
18
19
# File 'lib/redd/models/mod_mail.rb', line 17

def self.from_id(client, id)
  new(client, id: id)
end

Instance Method Details

#archiveObject

Mark this conversation as archived.



41
42
43
# File 'lib/redd/models/mod_mail.rb', line 41

def archive
  perform_action(:post, 'archive')
end

#highlightObject

Highlight this conversation.



51
52
53
# File 'lib/redd/models/mod_mail.rb', line 51

def highlight
  perform_action(:post, 'highlight')
end

#mark_as_readObject

Mark this conversation as read.



31
32
33
# 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_unreadObject

Mark this conversation as unread.



36
37
38
# File 'lib/redd/models/mod_mail.rb', line 36

def mark_as_unread
  @client.post('/api/mod/conversations/unread', conversationIds: [get_attribute(:id)])
end

#muteObject

Mute this conversation.



61
62
63
# File 'lib/redd/models/mod_mail.rb', line 61

def mute
  perform_action(:post, 'mute')
end

#reply(body, hidden: false, internal: false) ⇒ Object

Add a reply to the ongoing conversation.



22
23
24
25
26
27
28
# 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

#unarchiveObject

Removed this conversation from archived.



46
47
48
# File 'lib/redd/models/mod_mail.rb', line 46

def unarchive
  perform_action(:post, 'unarchive')
end

#unhighlightObject

Remove the highlight on this conversation.



56
57
58
# File 'lib/redd/models/mod_mail.rb', line 56

def unhighlight
  perform_action(:delete, 'highlight')
end

#unmuteObject

Unmute this conversation.



66
67
68
# File 'lib/redd/models/mod_mail.rb', line 66

def unmute
  perform_action(:post, 'unmute')
end