Class: Safubot::XMPP::Message

Inherits:
Object
  • Object
show all
Includes:
MongoMapper::Document
Defined in:
lib/safubot/xmpp.rb

Overview

A Message is a Request source representing a single XMPP chat stanza.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from(raw) ⇒ Object

Creates a new Message.

Parameters:

  • raw

    The Blather stanza from which to source data.



44
45
46
47
48
49
50
51
52
53
# File 'lib/safubot/xmpp.rb', line 44

def from(raw)
  Message.find_by_xmpp_id(raw.id) ||
	Message.create({
	  :xml => raw.to_xml,
	  :xmpp_id => raw.id,
	  :text => raw.body.strip,
	  :to => raw.to.to_s,
	  :from => raw.from.to_s
	})
end

Instance Method Details

#make_requestObject

Retrieves or creates an associated Request.



67
68
69
# File 'lib/safubot/xmpp.rb', line 67

def make_request
		self.request || self.request = Request.create(:user => user, :source => self, :text => self.text)
end

#userObject

Retrieves the KnownUser associated with this Message.



62
63
64
# File 'lib/safubot/xmpp.rb', line 62

def user
		KnownUser.by_xmpp(self.from)
end

#usernameObject

Retrieves the sender’s username from the JID.



57
58
59
# File 'lib/safubot/xmpp.rb', line 57

def username
		self.from.split('@')[0]
end