class Jabber::Delay::XDelay

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.

Public Class Methods

new(insertnow=true) click to toggle source

Initialize a new XDelay element

insertnow
Boolean

Set the stamp to [Time::now]

Calls superclass method
# File lib/xmpp4r/delay/x/delay.rb, line 30
def initialize(insertnow=true)
  super()

  if insertnow
    set_stamp(Time.now)
  end
end

Public Instance Methods

from() click to toggle source

Get the timestamp's origin

result
JID
# File lib/xmpp4r/delay/x/delay.rb, line 76
def from
  if attributes['from']
    JID.new(attributes['from'])
  else
    nil
  end
end
from=(jid) click to toggle source

Set the timestamp's origin

jid
JID
# File lib/xmpp4r/delay/x/delay.rb, line 87
def from=(jid)
  attributes['from'] = jid.nil? ? nil : jid.to_s
end
set_from(jid) click to toggle source

Set the timestamp's origin (chaining-friendly)

# File lib/xmpp4r/delay/x/delay.rb, line 93
def set_from(jid)
  self.from = jid
  self
end
set_stamp(t) click to toggle source

Set the timestamp (chaining-friendly)

# File lib/xmpp4r/delay/x/delay.rb, line 68
def set_stamp(t)
  self.stamp = t
  self
end
stamp() click to toggle source

Get the timestamp

result
Time

or nil

# File lib/xmpp4r/delay/x/delay.rb, line 41
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) click to toggle source

Set the timestamp

t
Time

or nil

# File lib/xmpp4r/delay/x/delay.rb, line 58
def stamp=(t)
  if t.nil?
    attributes['stamp'] = nil
  else
    attributes['stamp'] = t.strftime("%Y%m%dT%H:%M:%S")
  end
end