Class: MeshChat::Message::NodeList
- Defined in:
- lib/meshchat/message/node_list.rb
Instance Attribute Summary
Attributes inherited from Base
#payload, #sender_location, #sender_name, #sender_uid, #time_recieved
Instance Method Summary collapse
- #handle ⇒ Object
- #message ⇒ Object
-
#respond ⇒ Object
only need to respond if this server has node entries that the sender of this message doesn’t have.
Methods inherited from Base
#client, #client_version, #display, #initialize, #render, #type
Constructor Details
This class inherits a constructor from MeshChat::Message::Base
Instance Method Details
#handle ⇒ Object
8 9 10 11 |
# File 'lib/meshchat/message/node_list.rb', line 8 def handle respond return end |
#message ⇒ Object
4 5 6 |
# File 'lib/meshchat/message/node_list.rb', line 4 def ||= Node.as_json end |
#respond ⇒ Object
only need to respond if this server has node entries that the sender of this message doesn’t have
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/meshchat/message/node_list.rb', line 15 def respond received_list = we_only_have, they_only_have = Node.diff(received_list) if they_only_have.present? they_only_have.each do |n| Node.from_json(n).save! end end if we_only_have.present? location = payload['sender']['location'] node = Node.find_by_location(location) # give the sender our list MeshChat::Net::Client.send( node: node, message: NodeListDiff.new(message: we_only_have) ) # give the network their list Node.online.each do |entry| MeshChat::Net::Client.send( node: entry, message: NodeListDiff.new(message: they_only_have) ) end end end |