class GxG::Networking::XmppAgentConversation
Conversation Channel
Public Class Methods
new(parent=nil, details={})
click to toggle source
# File lib/gxg/net_clients.rb, line 2935 def initialize(parent=nil, details={}) if ::GxG::valid_uuid?(details[:context]) @uuid = details[:context].to_s.to_sym else @uuid = ::GxG::uuid_generate.to_sym end @parent = parent # @details should have a JID for the sender-jid/room-jid # @details should indicate whether a private direct message or MUC ROOM message (:chat? or :groupchat?) @details = details # @received = [] @received_thread_safety = ::Mutex.new # Add call backs # @parent.notify({:event => :new_message, :conversation => @uuid, :message => message.id}) # @parent.notify({:event => :new_private_message, :conversation => @uuid, :message => message.id}) self end
Public Instance Methods
[](the_key=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 2970 def [](the_key=nil) result = nil if the_key.is_a?(::Symbol) result = @details[(the_key)] end result end
add_message(the_message=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 3019 def add_message(the_message=nil) if the_message @received_thread_safety.synchronize { @received << the_message } true else false end end
change_configuration(the_configuration=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 3120 def change_configuration(the_configuration=nil) result = false begin # Review : TODO - alter ROOM configuration if admin/owner # if @handler # if @handler.owner? # unless the_configuration.is_a?(::Hash) # raise ArgumentError, "You MUST provide a configuration Hash." # end # the_configuration = this().default_room_configuration(the_configuration) # @handler.submit_room_configuration(the_configuration) # result = true # else # raise Exception, "You are not the owner of this conversation room." # end # end rescue Exception => the_error log_error({:error => the_error, :parameters => {:configuration => the_configuration}}) end result end
chat_buddies()
click to toggle source
# File lib/gxg/net_clients.rb, line 3049 def chat_buddies() result = [] begin # Review : TODO - like XmppAgent.buddies but for this ROOM only. rescue Exception => the_error log_error({:error => the_error, :parameters => {}}) end result end
closed?()
click to toggle source
# File lib/gxg/net_clients.rb, line 2988 def closed?() # Review : integrate with new system false end
configuration()
click to toggle source
# File lib/gxg/net_clients.rb, line 3086 def configuration() result = nil begin # Review : TODO - get ROOM configuration # if @handler # if @handler.owner? # current_configuration = {} # iq = ::Jabber::Iq.new(:get, @handler.jid.to_s) # iq.to = @handler.jid.to_s # iq.from = @handler.my_jid.to_s # iq.add(::Jabber::MUC::IqQueryMUCOwner.new) # field_keys = this().default_room_configuration.keys # response = @stream.send_with_id(iq) # if response # if (response.query && response.query.x(::Jabber::Dataforms::XData)) # field_keys.each do |the_key| # field = response.query.x(::Jabber::Dataforms::XData).field(the_key.to_s) # if field.is_a?(::Jabber::Dataforms::XDataField) # current_configuration[(the_key.to_s)] = field.value # end # end # end # end # result = current_configuration # else # raise Exception, "You are not the owner of this conversation room." # end # end rescue Exception => the_error log_error({:error => the_error, :parameters => {}}) end result end
default_room_configuration(options={})
click to toggle source
# File lib/gxg/net_clients.rb, line 2903 def default_room_configuration(options={}) unless options.is_a?(::Hash) options = {} end default_config = { 'FORM_TYPE' => 'http://jabber.org/protocol/muc#roomconfig', 'form' => 'config', 'muc#roomconfig_roomname' => nil, 'muc#roomconfig_roomdesc' => nil, 'leave' => 'has left', 'join' => 'has become available', 'rename' => 'is now known as', 'muc#roomconfig_changesubject' => 0, 'muc#roomconfig_maxusers' => 0, 'privacy' => 0, 'muc#roomconfig_publicroom' => 1, 'muc#roomconfig_persistentroom' => 1, 'legacy' => 0, 'muc#roomconfig_moderatedroom' => 0, 'defaulttype' => 0, 'privmsg' => 0, 'muc#roomconfig_membersonly' => 0, 'muc#roomconfig_allowinvites' => 1, 'muc#roomconfig_passwordprotectedroom' => 0, 'muc#roomconfig_roomsecret' => nil, 'muc#roomconfig_whois' => 'moderators', 'muc#roomconfig_enablelogging' => 0, 'logformat' => 'xml' } default_config.merge(options) end
inspect()
click to toggle source
# File lib/gxg/net_clients.rb, line 2984 def inspect() {:jid => this().jid, :title => this().title}.inspect end
jid()
click to toggle source
# File lib/gxg/net_clients.rb, line 2958 def jid() @details[:sender].to_s end
join(the_jid=nil, password=nil, options={})
click to toggle source
# File lib/gxg/net_clients.rb, line 3028 def join(the_jid=nil, password=nil, options={}) result = false begin # Review : TODO - MUC join rescue Exception => the_error log_error({:error => the_error, :parameters => {:the_jid => the_jid, :options => options}}) end result end
leave(exit_string=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 3038 def leave(exit_string=nil) result = false begin # Review : TODO - MUC leave # @parent.refresh_conversations rescue Exception => the_error log_error({:error => the_error, :parameters => {:exit_string => exit_string}}) end result end
my_jid()
click to toggle source
# File lib/gxg/net_clients.rb, line 2962 def my_jid() result = nil if @parent result = @parent.jid().to_s end result end
process_received(&block)
click to toggle source
# File lib/gxg/net_clients.rb, line 2993 def process_received(&block) begin if block.respond_to?(:call) count = 0 @received_thread_safety.synchronize { count = @received.size } record = nil count.times do @received_thread_safety.synchronize { record = @received.shift } if record block.call(record) end end true else false end rescue Exception => the_error log_error({:error => the_error, :parameters => {}}) false end end
say_something(the_message=nil, to_jid=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 3059 def say_something(the_message=nil, to_jid=nil) result = false begin if @details[:type] == :chat recipient = (to_jid || the_message[:to]).to_s @parent.say(::Blather::JID.new(recipient), @parent.gxg_message_to_xmpp(the_message)) else # Review : TODO - send chat message to ROOM end result = true rescue Exception => the_error log_error({:error => the_error, :parameters => {:message => the_message, :to => to_jid}}) end result end
send_invitations(the_recipients=nil, reason=nil)
click to toggle source
# File lib/gxg/net_clients.rb, line 3075 def send_invitations(the_recipients=nil, reason=nil) result = false begin # Review : TODO - ROOM invitation list processing list.each { |i| send i } # "You MUST provide an Array of JID Strings." rescue Exception => the_error log_error({:error => the_error, :parameters => {:recipients => the_recipients, :message => reason}}) end result end
title()
click to toggle source
# File lib/gxg/net_clients.rb, line 2978 def title() result = nil # Review : TODO - return ROOM title result end
uuid()
click to toggle source
# File lib/gxg/net_clients.rb, line 2954 def uuid() @uuid end