more fedi tweaks

This commit is contained in:
Administrator 2025-09-01 19:04:18 -07:00
parent 2218358c2f
commit 3f05e092ee
3 changed files with 50 additions and 6 deletions

View file

@ -411,15 +411,25 @@ unless load_error
end end
# #
def new_message(*args) def new_message(*args)
if this.actor?() unless @uuid
::GxG::Events::Message.new({:sender => this().to_uri(), :subject => args[1], :body => args[0]}) @uuid = ::GxG::uuid_generate.to_s.to_sym
else ::GxG::CHANNELS.create_channel(@uuid)
::GxG::Events::Message.new({:sender => this(), :subject => args[1], :body => args[0]})
end end
::GxG::Events::Message.new({:sender => @uuid, :subject => args[1], :body => args[0]})
end end
# #
public public
# #
def defederate()
if @uuid
the_channel = ::GxG::CHANNELS.fetch_channel(@uuid)
if the_channel
::GxG::CHANNELS.destroy_channel(@uuid)
end
end
true
end
#
def millisecond_latency(*args,&block) def millisecond_latency(*args,&block)
if block if block
starting = Time.now.to_f starting = Time.now.to_f

View file

@ -3,6 +3,15 @@ module GxG
# #
GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :available => {}, :connections => {}} GXG_FEDERATION = {:title => "Untitled", :uuid => nil, :available => {}, :connections => {}}
GXG_FEDERATION_SAFETY = Mutex.new GXG_FEDERATION_SAFETY = Mutex.new
def self.federation_servers()
result = {}
::GxG::GXG_FEDERATION_SAFETY.synchronize {
::GxG::GXG_FEDERATION[:available].each_pair do |uuid, server|
result[(uuid.to_s.to_sym)] = server
end
}
result
end
# #
module Messages module Messages
class Channel class Channel
@ -112,9 +121,24 @@ module GxG
channel.write(the_message) channel.write(the_message)
end end
result = true result = true
else
end
else
if ::GxG::valud_uuid?(destination.to_s)
# TODO: search available federated servers for channel. ???
::GxG::federation_servers.each_pair do |the_uuid, the_server|
if the_server.call_event(:federation, {:channel_exist => (destination)})[:result]
the_server.call_event(:federation, {:operation => {:forward_message => (the_message.serialize)}})
result = true
break
end
end
else
#
# email address -- TODO: integrate sendmail functionality in pure ruby. ::GxG::Networking::SmtpClient.new(::URI::parse("smtp://username:password@hostname.org:587"), {:use_ssl => true, :ignore_ssl_errors => true})
#
end end
end end
# email address -- TODO: integrate sendmail functionality in pure ruby. ::GxG::Networking::SmtpClient.new(::URI::parse("smtp://username:password@hostname.org:587"), {:use_ssl => true, :ignore_ssl_errors => true})
# #
end end
result result
@ -997,7 +1021,9 @@ class Object
channel = ::GxG::CHANNELS.fetch_channel(@uuid) channel = ::GxG::CHANNELS.fetch_channel(@uuid)
if channel if channel
channel.write(the_message) channel.write(the_message)
true
else
false
end end
true
end end
end end

View file

@ -3938,6 +3938,14 @@ module GxG
result result
end end
# #
def respond_to_event?(service, operation)
@clients[(service)].respond_to_event?(operation)
end
#
def call_event(service, operation_frame)
@clients[(service)].get(operation_frame)
end
#
def login(username=nil, password=nil) def login(username=nil, password=nil)
# #
@services.keys.each do |service| @services.keys.each do |service|