Class: Blather::Stanza::Presence::Status

Inherits:
Blather::Stanza::Presence show all
Includes:
InstanceMethods, Comparable
Defined in:
lib/blather/stanza/presence/status.rb

Overview

Status Stanza

RFC 3921 Section 2.2.2 - Presence Child Elements

Presence stanzas are used to express an entity's current network availability (offline or online, along with various sub-states of the latter and optional user-defined descriptive text), and to notify other entities of that availability.

"State" Attribute

The state attribute determains the availability of the entity and can be one of the following:

  • :available -- The entity or resource is available

  • :away -- The entity or resource is temporarily away.

  • :chat -- The entity or resource is actively interested in chatting.

  • :dnd -- The entity or resource is busy (dnd = "Do Not Disturb").

  • :xa -- The entity or resource is away for an extended period (xa = "eXtended Away").

Blather provides a helper for each possible state:

Status#available?
Status#away?
Status#chat?
Status#dnd?
Status#xa?

Blather treats the type attribute like a normal ruby object attribute providing a getter and setter. The default type is available.

status = Status.new
status.state              # => :available
status.available?         # => true
status.state = :away
status.away?              # => true
status.available?         # => false
status
status.state = :invalid   # => RuntimeError

"Type" Attribute

The type attribute is inherited from Presence, but limits the value to either nil or :unavailable as these are the only types that relate to Status.

"Priority" Attribute

The priority attribute sets the priority of the status for the entity and must be an integer between -128 and 127.

"Message" Attribute

The optional message element contains XML character data specifying a natural-language description of availability status. It is normally used in conjunction with the show element to provide a detailed description of an availability state (e.g., "In a meeting").

Blather treats the message attribute like a normal ruby object attribute providing a getter and setter. The default message is nil.

status = Status.new
status.message            # => nil
status.message = "gone!"
status.message            # => "gone!"

Direct Known Subclasses

MUC

Defined Under Namespace

Modules: InstanceMethods

Constant Summary collapse

VALID_STATES =

The spec requires only the following 4 states

[:away, :chat, :dnd, :xa].freeze
VALID_TYPES =
[:unavailable].freeze
POSSIBLE_STATES =

...but this is the sorted list of possible states

[:unavailable, :dnd, :xa, :away, :available, :chat].freeze

Constants inherited from XMPPNode

XMPPNode::BASE_NAMES

Instance Attribute Summary

Attributes inherited from Blather::Stanza

#handler_hierarchy

Class Method Summary collapse

Methods included from InstanceMethods

#<=>, #available?, #away?, #chat?, #dnd?, #message, #message=, #priority, #priority=, #state, #state=, #xa?

Methods inherited from Blather::Stanza::Presence

#error?, import, #probe?, #subscribe?, #subscribed?, #type=, #unavailable?, #unsubscribe?, #unsubscribed?

Methods inherited from Blather::Stanza

#as_error, #error?, #from, #from=, handler_list, #id, #id=, #initialize, next_id, register, #reply, #reply!, #to, #to=, #type, #type=

Methods inherited from XMPPNode

class_from_registration, #decorate, decorator_modules, import, parse, register, #to_stanza

Constructor Details

This class inherits a constructor from Blather::Stanza

Class Method Details

.new(state = nil, message = nil) ⇒ Object

Create a new Status stanza

Parameters:

  • state (<:away, :chat, :dnd, :xa>) (defaults to: nil)

    the state of the status

  • message (#to_s) (defaults to: nil)

    a message to send with the status



94
95
96
97
98
99
# File 'lib/blather/stanza/presence/status.rb', line 94

def self.new(state = nil, message = nil)
  node = super()
  node.state = state
  node.message = message
  node
end