Class: Jabber::Delay::XDelay

Inherits:
X show all
Defined in:
lib/xmpp4r/delay/x/delay.rb

Overview

Implementation of JEP 0091 for <x xmlns=‘jabber:x:delay’ stamp=‘…’ …/> applied on <message/> and <presence/> stanzas

One may also use XDelay#text for a descriptive reason for the delay.

Please note that you must require ‘xmpp4r/xdelay’ to use this class as it’s not required by a basic XMPP implementation. <x/> elements with the specific namespace will then be converted to XDelay automatically.

Instance Method Summary collapse

Methods inherited from X

add_namespaceclass, import

Methods inherited from REXML::Element

#delete_elements, #first_element, #first_element_text, #import, import, #replace_element_text, #typed_add

Constructor Details

#initialize(insertnow = true) ⇒ XDelay

Initialize a new XDelay element

insertnow
Boolean

Set the stamp to [Time::now]



28
29
30
31
32
33
34
35
# File 'lib/xmpp4r/delay/x/delay.rb', line 28

def initialize(insertnow=true)
  super()
  add_namespace('jabber:x:delay')

  if insertnow
    set_stamp(Time.now)
  end
end

Instance Method Details

#fromObject

Get the timestamp’s origin

result
JID


75
76
77
78
79
80
81
# File 'lib/xmpp4r/delay/x/delay.rb', line 75

def from
  if attributes['from']
    JID::new(attributes['from'])
  else
    nil
  end
end

#from=(jid) ⇒ Object

Set the timestamp’s origin

jid
JID


86
87
88
# File 'lib/xmpp4r/delay/x/delay.rb', line 86

def from=(jid)
  attributes['from'] = jid.nil? ? nil : jid.to_s
end

#set_from(jid) ⇒ Object

Set the timestamp’s origin (chaining-friendly)



92
93
94
95
# File 'lib/xmpp4r/delay/x/delay.rb', line 92

def set_from(jid)
  self.from = jid
  self
end

#set_stamp(t) ⇒ Object

Set the timestamp (chaining-friendly)



67
68
69
70
# File 'lib/xmpp4r/delay/x/delay.rb', line 67

def set_stamp(t)
  self.stamp = t
  self
end

#stampObject

Get the timestamp

result
Time

or nil



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/xmpp4r/delay/x/delay.rb', line 40

def stamp
  if attributes['stamp']
    begin
      # Actually this should be Time.xmlschema,
      # but "unfortunately, the 'jabber:x:delay' namespace predates" JEP 0082
      Time.parse(attributes['stamp'])
    rescue ArgumentError
      nil
    end
  else
    nil
  end
end

#stamp=(t) ⇒ Object

Set the timestamp

t
Time

or nil



57
58
59
60
61
62
63
# File 'lib/xmpp4r/delay/x/delay.rb', line 57

def stamp=(t)
  if t.nil?
    attributes['stamp'] = nil
  else
    attributes['stamp'] = t.strftime("%Y%m%dT%H:%M:%S")
  end
end